Announcement

Collapse
No announcement yet.

stoch mom index

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • stoch mom index

    I have managed to modify you code, to accommodate the Buy/sell signal on the price chart.
    This is a second script executed independently. this works fine.

    What I want to do is display the value of the price underneath the buy/sell signal when this cross over happens.
    Is it also possible to write the time and price value when this happened, to a file ?

    ************************************************** ********************/


    //Global Variables
    var grID = 0;
    var nVal1 = 0;
    var nSMI = 0;
    var nResult = 0;

    var nHH = 0;
    var nLL = 0;

    var nMA1 = 0.0;
    var nMA2 = 0.0;
    var nMA3 = 0.0;
    var nMA4 = 0.0;

    var aResult = new Array();
    var aMA1 = new Array();
    var aMA2 = new Array();
    var aMA3 = new Array();
    var aMA4 = new Array();

    var aSMI = new Array();

    //== PreMain function required by eSignal to set things up
    function preMain() {
    var x;

    setPriceStudy(true);
    setStudyTitle("Stoch Mom Index3");
    //setComputeOnClose();
    grID = 0;

    //initialize arrays
    for (x=0; x<10; x++) {
    aMA1[x] = 0.0;
    aMA2[x] = 0.0;
    aMA3[x] = 0.0;
    aMA4[x] = 0.0;
    aSMI[x] = 0.0;
    aResult[x] = 0.0;
    }

    }

    //== Main processing function
    function main( frPer1, frPer2, frPer3, frSMIPer ) {
    var x;
    var nEMA1;
    var nEMA2;
    var nEMA3;
    var space = 1;


    if (frPer1 == null) {
    frPer1 = 5;
    }

    if (frPer2 == null) {
    frPer2 = 3;
    }

    if (frPer3 == null) {
    frPer3 = 3;
    }

    if (frSMIPer == null) {
    frSMIPer = 3;
    }

    //script is initializing
    if (getBarState() == BARSTATE_ALLBARS) {
    return null;
    }

    if (getBarState() == BARSTATE_NEWBAR) {
    //calculate the appropriate highest-high/lowest-low values
    nHH = highestHigh( frPer1 );
    nLL = lowestLow( frPer1 );

    //cycle our arrays
    aMA1.pop();
    aMA1.unshift( nMA1 );
    aMA2.pop();
    aMA2.unshift( nMA2 );
    aMA3.pop();
    aMA3.unshift( nMA3 );
    aMA4.pop();
    aMA4.unshift( nMA4 );
    aSMI.pop();
    aSMI.unshift( nSMI );
    aResult.pop();
    aResult.unshift( nResult );

    space = high() - low();

    if ( aResult[0] > aSMI[0] && aResult[1] <= aSMI[1] ) {
    //display long
    drawShapeRelative( -1, low()-3, Shape.UPARROW, null, Color.RGB(38,176,49), Shape.ONTOP | Shape.TOP, gID() );

    //drawTextRelative(0, low()-10.0, "Buy", Color.RGB(10,176,49), null, Text.ONTOP | Text.CENTER, "Courier", low()-10, 0 );

    Alert.playSound("Buysignal.wav");
    }
    else if ( aResult[0] < aSMI[0] && aResult[1] >= aSMI[1] ) {
    //display short
    drawShapeRelative( -1, high()+5, Shape.DOWNARROW, null, Color.red, Shape.ONTOP | Shape.TOP, gID() );
    //play sound
    Alert.playSound("Sellsignal.wav");
    }

    }
    nHH = Math.max( nHH, high() );
    nLL = Math.min( nLL, low() );

    //detremine exponential moving average coefficients
    nEMA1 = 2 / (frPer2+1);
    nEMA2 = 2 / (frPer3+1);
    nEMA3 = 2 / (frSMIPer+1);

    //perform the value and average calculations
    nVal1 = close() - (0.5 * (nHH + nLL));

    nMA1 = (nVal1*nEMA1) + (aMA1[0] * (1.0-nEMA1));
    nMA2 = (nMA1*nEMA2) + (aMA2[0] * (1.0-nEMA2));

    nVal2 = nHH-nLL;

    nMA3 = (nVal2*nEMA1) + (aMA3[0] * (1.0-nEMA1));
    nMA4 = (nMA3*nEMA2) + (aMA4[0] * (1.0-nEMA2));

    //compute SMI
    nResult = 100 * ( nMA2 / (0.5 * nMA4) );

    //compute exp average of SMI
    nSMI = (nResult*nEMA3) + (aSMI[0] * (1.0-nEMA3));



    //return the value to be plotted
    if (!isNaN( nResult ) && !isNaN( nSMI )) {
    return;
    }


    }


    /*************************************************
    SUPPORT FUNCTIONS
    **************************************************/


    //================================================== =======
    //== returns the highest high of the last x bars
    //================================================== =======
    function highestHigh( nBarsBack ) {
    var x = 1;
    var nTmp = -9999999.0;

    while( x<nBarsBack ) {
    nTmp = Math.max( nTmp, high(-x) );
    x++;
    }

    return( nTmp );

    }

    //================================================== =======
    //== returns the lowest low of the last x bars
    //================================================== =======
    function lowestLow( nBarsBack ) {
    var x = 1;
    var nTmp = 9999999.0;

    while( x<nBarsBack ) {
    nTmp = Math.min( nTmp, low(-x) );
    x++;
    }

    return( nTmp );

    }


    //== gID function assigns unique identifier to graphic/text routines
    function gID() {
    grID ++;
    return( grID );
    }


    //== displayError function displays an error to the user
    function displayError( ErrStr ) {

    drawTextRelative(20, 50, ErrStr, Color.maroon, Color.lightgrey, Text.FRAME | Text.ONTOP | Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM, null, 16, gID());

    }


    have a great day,

    thanks again for your help once again.
    regards

    Harish maru

  • #2
    Hello Harish,

    You can use drawTextRelative() to display the price next to your signals. Here's a link that explains how to write info to a file using the File Object.

    These resources can be found in our EFS Help Center & Library at the link below.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X