Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical vs Live and IsFirstTickOfBar logic

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

    Historical vs Live and IsFirstTickOfBar logic

    Hello,

    I understand how the IsFirstTickOfBar works on live data...

    My plan is to use "Calculate on each tick" in every indicator, but really calculate only on the first tick of the bar in order to get previous close...

    Like "Close[1]"...

    However, how will historical bars be treated when I have condition "IsFirstTickOfBar" but current state is historical?

    Do I need to write a new logic in order to treat historical bars correctly?

    All I really want is to calculate on BarClose, but being able to run indicator "OnEachTick" in live data (and OnBarClose when historical state or running through strategy analyzer which is same).

    Thanks

    #2
    I think I found answer to my question based on testing and following article:



    Seems that the best way to separate both real-time and historical logic is by putting two if statements - one for real time (then I need to use "Close[1]"), and one for historical (then I will need to use "Close[0]"), and so IsFirstTickOfBar will always be "TRUE" when state is historical...

    Please confirm if I am correct, and if that is the best practice to separate both logics... Disadvantage - is I need to pretty much "Duplicate" code... unless maybe I use some offset of "1" and will set based on the current state, and so if state is "RealTime" - then I will need to add "1" offset, if state is "HIstorical" - then add a zero offset...

    protected override void OnBarUpdate()
    {
    //if (State != State.Realtime)
    // return;

    ++counter;

    if (State == State.Realtime && IsFirstTickOfBar)
    {
    Draw.Dot(this, "dot" + CurrentBar.ToString() + counter.ToString(), true, 0,
    High[0] + counter * TickSize, Brushes.Orange);
    Print(string.Format("Time:{0}, High:{1}, Low:{2}", Time[1], High[1], Low[1]));
    }

    if (State == State.Historical && IsFirstTickOfBar)
    {
    Draw.Dot(this, "dot" + CurrentBar.ToString() + counter.ToString(), true, 0,
    High[0] + counter * TickSize, Brushes.Orange);
    Print(string.Format("Time:{0}, High:{1}, Low:{2}", Time[0], High[0], Low[0]));
    }

    if (IsFirstTickOfBar)
    counter = 0;

    }

    Thanks

    Comment


      #3
      Hello music_p13,

      In historical data TickReplay must be enabled for Calculate to work with .OnPriceChange or .OnEachTick.

      With TickReplay disabled, IsFirstTickOfBar will always be true in historical data.

      With TickReplay enabled and Calculate set to .OnPriceChange or .OnEachTick, IsFirstTickOfBar will only be true on the first tick of a bar.

      Below is a link to a forum post with details and links to the help guide.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hello music_p13,

        Unfortunately, Renko bars do not work with TickReplay.

        From the help guide:
        "Note: The system bar types "Line Break" and "Renko" cannot be used with Tick Replay and as a result, the Tick Replay option will be disabled when configured with those bar types. There may be other 3rd party bar types which may also disable Tick Replay by design. If you are a developer, please see the property IsRemoveLastBarSupported for more information"


        This is because RemoveLastBar() is used with this script.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        600 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        346 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X