Announcement

Collapse
No announcement yet.

End of bar Data with SETCOMPUTEONCLOSE=FALSE

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

  • End of bar Data with SETCOMPUTEONCLOSE=FALSE

    I know how to get the value at the beginning of a bar using the sample code

    if (getBarState() == BARSTATE_NEWBAR) {
    vFlag = false;
    var vData1 = 5;
    var vData2 = 1;
    if (vData1 > vData2 && vFlag == false) {
    vHistoryFile = (vChartTitle + getInterval() + "--Loaded on " + getMonth(0) + "-" + getDay(0) + " at " + getHour(0) + "." + getMinute(0) + "");
    vHistoryFileTitle = ("Loaded on: " + getMonth(0) + "-" + getDay(0) + " at " + getHour(0) + "." + getMinute(0));
    vFlag = true;
    }
    }

    But how can you grab the last value of the last bar instead

    What I am trying to do is have SETCOMPUTEONCLOSE to false, and check the value of an StochD (which is updating on every tick), against the closing value of the last bar. Using a "-1" parameter, study(-1), will not work because that gives me the value of the last tick, not the last closed bar

  • #2
    alexmihh
    First of all please consider that setComputeOnClose() does not have any parameters so even if you set it to setComputeOnClose(false) the formula will still compute on the close of a bar only. You need to comment out (or remove altogether) the setComputeOnClose() statement.
    Having said that you should be able to retrieve the value of a study at the prior bar by using study.getValue(-1) The script enclosed below for example will return to the current bar the value of the Stochastic %D at the prior bar. By using the getValue(-1) you are essentially displacing forward by one bar the study's return which should remain constant on every tick
    Please let me know if I have misunderstood your question.
    Alex

    PHP Code:
    var xStochD null;
     
    function 
    main(){
     
        if(
    xStochD==nullxStochD stochD(14,1,3);
     
        var 
    nStochD xStochD.getValue(-1);//nStochD is the value of Stochastic %D at prior bar
        
    if(nStochD==null) return;
     
        return 
    nStochD;

    Comment


    • #3
      [QUOTE]Originally posted by Alexis C. Montenegro
      [B]alexmihh
      Having said that you should be able to retrieve the value of a study at the prior bar by using study.getValue(-1)

      OK, I somehow thought that this would retreive the last tick value of the study if SETCOMPUTEONCLOSE was not in effect, but I see this is not the case. It returns the study value at the close of last bar regardless of SETCOMPUTEONCLOSE

      Comment


      • #4
        alexmihh

        It returns the study value at the close of last bar regardless of SETCOMPUTEONCLOSE
        That is correct
        Alex

        Comment


        • #5
          What you want is to get that last value, only when NEWBAR is true. By definition this will be the last closing value.


          if (getBarState() != BARSTATE_NEWBAR) {
          return;
          }

          MostRecentClose = Close();


          Garth
          Garth

          Comment

          Working...
          X