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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      46 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X