BarIndex = 0

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #113284 quote
    csntrader
    Participant
    Average

    Hi,

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

    Can we rewrite the code below without having BarIndex?

    Thanks!

    IF BarIndex = 0 THEN
    XClose = Open
    XOpen = (Open + Close) / 2
    
    ELSE
    
    XClose = Open
    XOpen = (Open + Close + high + low) / 4
    
    ENDIF
    #113293 quote
    robertogozzi
    Moderator
    Master

    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 quote
    csntrader
    Participant
    Average

    Okey, great! 🙂

    Thank you!

    #113353 quote
    GraHal
    Participant
    Master

    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 quote
    robertogozzi
    Moderator
    Master

    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:

    RETURN BarIndex

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

    GraHal thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

BarIndex = 0


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
csntrader @csntrader Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by robertogozzi
6 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/21/2019
Status: Active
Attachments: No files
Logo Logo
Loading...