Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New session Integer reset issue

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

    New session Integer reset issue

    Interesting little problem, first assumption is my initialization is faulty... I have a variable "i"intially declared up top as

    private int i = 0;

    Then in update I have as follows:

    protected override void OnBarUpdate()
    {


    if (BarsInProgress != 0)
    return;

    if (CurrentBars[1] < 2)
    return;

    if (Bars.IsFirstBarOfSession == true) // reset indicator at start of session
    i = 0;


    This is what I want, reset i to zero at start of session.

    What's odd, is that this works just fine in playback but with a live data feed it sets to -1. During the day therefore it rests at -1 instead of zero.

    Thoughts?

    #2
    Hello johnMoss,

    While I don't see a problem with the suggested code, I do recommend initializing variables in State.DataLoaded.

    I see you are using CurrentBars[1]. To confirm, you are adding a series with AddDataSeries() in State.Configure?
    Are you also checking CurrentBars[0] is not less than 1?

    I'm testing this on a 60 minute chart and not seeing an issue.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea... Answers to your questions are Yes, and "I am now" ...

      That and moving the initialization to State.DatalLoaded have apparently resolved the issue. Thanx Again

      Comment

      Latest Posts

      Collapse

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