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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      49 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      69 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      36 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      95 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      59 views
      0 likes
      Last Post PaulMohn  
      Working...
      X