Announcement

Collapse
No announcement yet.

Need Previous StochD Value

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

  • Need Previous StochD Value

    I have an efs that tracks the StochD values on various futures. I am sure I got this code from the forum, and it works swell.

    But I want to grab also the previous value of StochD and do a comparison, and I do not know how to get that previous value with the code as it is girven below.

    I think it s more complicated than simply using a (-1) somewhere (where?, how?)
    PHP Code:
    /****************************************************************************************************
    7:00 pm    20NNOV06            STochD-US.efs   
    *****************************************************************************************************
    latest fix:
    to do: 

    *****************************************************************************************************/
    var DOWiSymbol null;
    var 
    RUSiSymbol null;
    var 
    iIntervalLO null;
    var 
    bALERTON false;
    var 
    DOWValue null;
    var 
    RUSValue null;
    var 
    bDOWOFF false;
    var 
    bRUSOFF false;
    var 
    vHI 65;
    var 
    vLO 35;

    function 
    preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("DOW SCANNER"); 
    //    setComputeOnClose();


        
    DOWiSymbol = new FunctionParameter("DOWiSymbol"FunctionParameter.STRING);
            
    DOWiSymbol.setDefault"YM #F" );

        
    RUSiSymbol = new FunctionParameter("RUSiSymbol"FunctionParameter.STRING);
            
    RUSiSymbol.setDefault"AB #F" );

        
    iIntervalLO = new FunctionParameter("iIntervalLO"FunctionParameter.NUMBER);
        
    iIntervalLO.setDefault); 



    }
      

    function 
    main(DOWiSymbolRUSiSymboliIntervalLO ){

      if (!
    bDOWOFF) {
        
    DOWValue = ( stochD(5,5,6,sym(DOWiSymbol "," iIntervalLO))  ).toFixed(0);
        if (
    DOWValue >= vHI) {
            
    drawTextAbsolute(5197" DOW = " DOWValue " " "@URL=EFS:DOWOFF"Color.RGB(255,255,0), Color.red
                            
    Text.LEFT |  Text.RELATIVETOLEFT Text.RELATIVETOTOP Text.BOLDnull11"DOW" );
        }

        if (
    DOWValue <= vLO) {
            
    drawTextAbsolute(5197" DOW = " DOWValue " " "@URL=EFS:DOWOFF"Color.RGB(255,255,0), Color.green
                            
    Text.LEFT |  Text.RELATIVETOLEFT Text.RELATIVETOTOP Text.BOLDnull11"DOW" );
        }

        if (
    DOWValue vLO && DOWValue vHI) {
    //        drawTextAbsolute(1, 137, " DOW = " + DOWValue + " " + "@URL=EFS:DOWOFF", Color.RGB(255,255,0), Color.blue, 
    //                        Text.LEFT |  Text.RELATIVETOLEFT | Text.RELATIVETOTOP | Text.BOLD, null, 11, "DOW" );
    //        bDOWOFF = false;
            
    removeText("DOW");
        }
      }



      if (!
    bRUSOFF) {
        
    RUSValue = ( stochD(5,5,6,sym(RUSiSymbol "," iIntervalLO))  ).toFixed(0);
        if (
    RUSValue >= vHI) {
            
    drawTextAbsolute(5217" RUS = " RUSValue " " "@URL=EFS:RUSOFF"Color.RGB(255,255,0), Color.red
                            
    Text.LEFT |  Text.RELATIVETOLEFT Text.RELATIVETOTOP Text.BOLDnull11"RUS" );
        }

        if (
    RUSValue <= vLO) {
            
    drawTextAbsolute(5217" RUS = " RUSValue " " "@URL=EFS:RUSOFF"Color.RGB(255,255,0), Color.green
                            
    Text.LEFT |  Text.RELATIVETOLEFT Text.RELATIVETOTOP Text.BOLDnull11"RUS" );
        }

        if (
    RUSValue vLO && RUSValue vHI) {
    //        drawTextAbsolute(10, 137, " RUS = " + RUSValue + " " + "@URL=EFS:RUSOFF", Color.RGB(255,255,0), Color.blue, 
    //                        Text.LEFT |  Text.RELATIVETOLEFT | Text.RELATIVETOTOP | Text.BOLD, null, 11, "RUS" );
    //        bRUSOFF = false;
            
    removeText("RUS");
        }
      }



    //

    }        // end MAIN 

  • #2
    alexmihh
    Because in these two lines
    PHP Code:
    DOWValue = ( stochD(5,5,6,sym(DOWiSymbol "," iIntervalLO))  ).toFixed(0);
    //and
    RUSValue = ( stochD(5,5,6,sym(RUSiSymbol "," iIntervalLO))  ).toFixed(0); 
    you are using the .toFixed() method when intializing the study the formula engine is retrieving the current value of the study and converting it to a string. Hence DOWValue is no longer a series which means that you cannot retrieve any of its values using the .getValue() method.
    The way to resolve this is to remove the .toFixed() from both those lines then run a null check on the values eg
    if(DOWValue.getValue(0)==null) return;
    and then apply the toFixed() method to the value inside the drawText command (see example enclosed below).
    Once you implement these changes you will then be able to use the .getValue() method to retrieve the values of the series (eg DOWValue.getValue(-1), etc)
    Alex

    PHP Code:
    if (!bDOWOFF) {
        
    DOWValue stochD(5,5,6,sym(DOWiSymbol "," iIntervalLO));
        if(
    DOWValue.getValue(0)==null) return;
        if (
    DOWValue.getValue(0) >= vHI) {
            
    drawTextAbsolute(5197" DOW = " DOWValue.getValue(0).toFixed(0) + " " "@URL=EFS:DOWOFF"Color.RGB(255,255,0), Color.red
                            
    Text.LEFT |  Text.RELATIVETOLEFT Text.RELATIVETOTOP Text.BOLDnull11"DOW" );
        }
        if (
    DOWValue.getValue(0)<= vLO) {
            
    drawTextAbsolute(5197" DOW = " DOWValue.getValue(0).toFixed(0) + " " "@URL=EFS:DOWOFF"Color.RGB(255,255,0), Color.green
                            
    Text.LEFT |  Text.RELATIVETOLEFT Text.RELATIVETOTOP Text.BOLDnull11"DOW" );
        }
        if (
    DOWValue.getValue(0) > vLO && DOWValue.getValue(0) < vHI) {
            
    removeText("DOW");
        }

    Comment


    • #3
      Thank you so kindly.

      I have implementated your changes, made a few enhancements, and now have a great working EFS

      I have a question. What is the purpose of this statement? What does it do? Why is it needed? Etc

      if(DOWValue.getValue(0)==null) return;

      Comment


      • #4
        alexmihh
        You are most welcome.
        That conditional statement is a null check to ensure that the variable contains valid data before we access any of its properties. Otherwise when you use the toFixed() method you will get an error stating the the variable has no properties. This is because in the first n bars the study is returning null while it is priming.
        Alex

        Comment

        Working...
        X