BarIndex = 0

Viewing 5 posts - 1 through 5 (of 5 total)
  • #113284

    Hi,

    I’m so confused over the meaning of (BarIndex = 0)?

    Can we rewrite the code below without having BarIndex?

    Thanks!

     

    #113293

    No, BarIndex is needed.

    BarIndex is the very first bar when you load an indicator or a strategy. In your case you need it to start the HA sequence.

    If you have instructions to be executed only when your code is loaded and not the next candles, well… BarIndex is what you need.

    IntraDayBarIndex is another constant that returns 0 when it’s the first intraday bar of the day.

    IntraDayBarIndex restarts from zero each new day, while BarIndex starts from 0 when you first execute your code and ALWAYS increases.

    #113326

    Okey, great! 🙂

    Thank you!

    #113353

    BarIndex starts from 0 when you first execute your code

    Is above true even allowing for preload bars (default preload bars = 2000 in a strategy?) or would we need to use defparam preloadbars = 0 in a strategy?

    #113356

    Yes, it’s true no matter how many PRELOADBARS. If PreLOadBars > 0 then BARINDEX 0 will be that very first preloaded bar.

    If you create a simple indicator:

    and go back to the very first displayed bar on the chart, you’ll see what’s its BARINDEX value.

     

    1 user thanked author for this post.
Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login