Announcement

Collapse
No announcement yet.

getCurrentBarIndex() does not update with each new bar even when in return statement

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

  • getCurrentBarIndex() does not update with each new bar even when in return statement

    Using :
    PHP Code:
    function preMain(){
     
    setPriceStudy(true);
     
    setCursorLabelName("getCurrentBarIndex",0);
    }
    function 
    main(){
     return 
    getCurrentBarIndex()+"";

    As I understand it the returned value should update with every new bar but it doesn't. It is accurate when loaded but returns 0 for every new bar keeping the -1 etc. on the same bar as when the study was loaded. All new drawn bars after the study is loaded return 0.

    The attached image has a red arrow where the study was loaded and the returned value is -1 instead of the actual bar index of -4. All bars after the bar under the arrow return 0.

    Is this how getCurrentBarIndex() should work?

    Wayne
    Attached Files

  • #2
    Wayne, I remember it counts down to zero (starting as a negative value to getCurrentBarIndex()=0) from the most recent bar (getCurrentBar()=0). Please try comparing with a debugPrint Statement before the return statement with both getCurrentBarIndex() and getCurrentBar().

    Comment


    • #3
      Steve, always good to hear from you.

      Your suggested test seem to confirm my original post. As new bars are formed and barcount increases after the original load, getCurrentBarIndex() then stays on 0. So I think it will only give an accurate index at the time it is first loaded.

      I used a 10T interval ES #F chart & the following script:
      PHP Code:
      function preMain(){
       
      setPriceStudy(true);
       
      setCursorLabelName("getCurrentBarIndex",0);
      }
      function 
      main(){
          
      debugPrintln("BarIdx: "+getCurrentBarIndex()+" BarCnt: "+getCurrentBarCount());
       return [
      getCurrentBarIndex()+"",getCurrentBarCount()+""];

      I returned the following (I cropped out barcounts 0 through 284):
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 303
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 302
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 301
      BarIdx: 0 BarCnt: 300
      BarIdx: -1 BarCnt: 299
      BarIdx: -2 BarCnt: 298
      BarIdx: -3 BarCnt: 297
      BarIdx: -4 BarCnt: 296
      BarIdx: -5 BarCnt: 295
      BarIdx: -6 BarCnt: 294
      BarIdx: -7 BarCnt: 293
      BarIdx: -8 BarCnt: 292
      BarIdx: -9 BarCnt: 291
      BarIdx: -10 BarCnt: 290
      BarIdx: -11 BarCnt: 289
      BarIdx: -12 BarCnt: 288
      BarIdx: -13 BarCnt: 287
      BarIdx: -14 BarCnt: 286
      BarIdx: -15 BarCnt: 285
      Wayne

      Comment

      Working...
      X