Announcement

Collapse
No announcement yet.

SetOnClose Alternative?

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

  • SetOnClose Alternative?

    Hi,

    When the "vComputeOnClose" menu item is set to "true" (which sets up an if statement: if(getBarState()==BARSTATE_NEWBAR){) will the effect be the same as adding a "setComputeOnClose()" statement in the preMain()?

    I would like to have a menu item to equate the "setComputeOnClose".

    Thank you.

    Please see the following example:

    var bInit = false;
    var aFPArray = new Array();
    var vOffset = null;
    function preMain() {

    setPriceStudy(false);
    // setComputeOnClose();
    setStudyTitle("Stoch Menu");
    setShowTitleParameters(false);
    setCursorLabelName("%K",0);
    setDefaultBarFgColor(Color.black, 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);

    var x=0;
    aFPArray[x] = new FunctionParameter( "vComputeOnClose", FunctionParameter.BOOLEAN);
    with( aFPArray[x++] ) {
    setName( "Compute On Close" );
    setDefault( false );
    }
    }
    var myStudy1 = null;
    var myStudy2 = null;
    var myVar1;
    var myVar1_1;

    function main(vComputeOnClose){

    if ( bInit == false ) {
    myStudy1 = stochK( 10, 5, 3 );
    myStudy2 = stochD( 10, 5, 3 );
    bInit = true;
    }
    if(vComputeOnClose){
    if(getBarState()==BARSTATE_NEWBAR){
    myVar1 = myStudy1.getValue(0);
    }
    }else{
    myVar1 = myStudy1.getValue(0);
    }
    return myVar1;
    }

  • #2
    Re: SetOnClose Alternative?

    waynecd
    The effect will be similar however the logic that is required needs to be different.
    When using getBarState()==BARSTATE_NEWBAR you need to retrieve the values at the prior bar (ie the one that just closed) because the efs is still executing on the current bar whereas setComputeOnClose() only allows the execution of the efs when a bar closes
    In order to make your script work correctly you need to change the following section
    PHP Code:
     if(vComputeOnClose){
            if(
    getBarState()==BARSTATE_NEWBAR){
                
    myVar1 myStudy1.getValue(0); 
            }
        }else{
            
    myVar1 myStudy1.getValue(0); 
        } 
    to the following
    PHP Code:
     if(vComputeOnClose){
            if(
    getBarState()==BARSTATE_NEWBAR){
                
    myVar1 myStudy1.getValue(-1); 
            }
        }else{
            
    myVar1 myStudy1.getValue(0); 
        } 
    Hope this helps
    Alex


    Originally posted by waynecd
    Hi,

    When the "vComputeOnClose" menu item is set to "true" (which sets up an if statement: if(getBarState()==BARSTATE_NEWBAR){) will the effect be the same as adding a "setComputeOnClose()" statement in the preMain()?

    I would like to have a menu item to equate the "setComputeOnClose".

    Thank you.

    Please see the following example:

    var bInit = false;
    var aFPArray = new Array();
    var vOffset = null;
    function preMain() {

    setPriceStudy(false);
    // setComputeOnClose();
    setStudyTitle("Stoch Menu");
    setShowTitleParameters(false);
    setCursorLabelName("%K",0);
    setDefaultBarFgColor(Color.black, 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);

    var x=0;
    aFPArray[x] = new FunctionParameter( "vComputeOnClose", FunctionParameter.BOOLEAN);
    with( aFPArray[x++] ) {
    setName( "Compute On Close" );
    setDefault( false );
    }
    }
    var myStudy1 = null;
    var myStudy2 = null;
    var myVar1;
    var myVar1_1;

    function main(vComputeOnClose){

    if ( bInit == false ) {
    myStudy1 = stochK( 10, 5, 3 );
    myStudy2 = stochD( 10, 5, 3 );
    bInit = true;
    }
    if(vComputeOnClose){
    if(getBarState()==BARSTATE_NEWBAR){
    myVar1 = myStudy1.getValue(0);
    }
    }else{
    myVar1 = myStudy1.getValue(0);
    }
    return myVar1;
    }

    Comment


    • #3
      You bet.

      Once again, clear, to the point, and precise.

      Thanks

      Comment


      • #4
        waynecd
        You are most welcome
        Alex


        Originally posted by waynecd
        You bet.

        Once again, clear, to the point, and precise.

        Thanks

        Comment

        Working...
        X