BarIndex = 0
Forums › ProRealTime English forum › ProBuilder support › BarIndex = 0
- This topic has 4 replies, 3 voices, and was last updated 5 years ago by robertogozzi.
-
-
11/21/2019 at 9:26 AM #113284
Hi,
I’m so confused over the meaning of (BarIndex = 0)?
Can we rewrite the code below without having BarIndex?
Thanks!
BarIndex12345678910IF BarIndex = 0 THENXClose = OpenXOpen = (Open + Close) / 2ELSEXClose = OpenXOpen = (Open + Close + high + low) / 4ENDIF11/21/2019 at 10:25 AM #113293No, 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.
11/21/2019 at 4:03 PM #11332611/21/2019 at 7:34 PM #113353BarIndex 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?
11/21/2019 at 7:38 PM #113356Yes, 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:
1RETURN BarIndexand 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.
-
AuthorPosts