BarIndex = 0

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #113284 quote
    csntradercsntrader
    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
    robertogozzirobertogozzi
    Moderator
    Legend

    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
    csntradercsntrader
    Participant
    Average

    Okey, great! 🙂

    Thank you!

    #113353 quote
    GraHalGraHal
    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
    robertogozzirobertogozzi
    Moderator
    Legend

    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 robertogozzirobertogozzi
6 years, 10 months ago.

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