Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy State

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

    #16
    Hey Jessica,

    Can't get this code to run properly:

    ExampleStateStrategy Snippet:
    Code:
    ......
        else if (State == State.Configure)
        {
    	AddChartIndicator(ExampleStateIndicator());
        }
    }
    
    protected override void OnBarUpdate()
    {
    	double  data = ExampleStateIndicator()[0];
    	Print("STRATEGY - " + State);
    }
    ExampleStateIndicator Snippet:
    Code:
    protected override void OnBarUpdate()
    {
    	Value[0] = 0;
    	Print("INDICATOR - " + State);
    }
    The output in the window gives the following error:

    Code:
    Strategy 'ExampleStateStrategy': Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array.
    This tells me the indicator has not yet run so if we add the following line to the strategy code:

    Code:
    if(State < State.Realtime)
    	return;
    We then get this error once the first realtime bar closes:

    Code:
    Strategy 'ExampleStateStrategy': Error on calling 'OnBarUpdate' method on bar 6997: Index was outside the bounds of the array.
    I have tried several variations and have gotten none of them to work.

    Do you have a working example of this scenario working correctly?

    Comment


      #17
      I do in fact have a pair which will process realtime correctly. I am attaching it to this reply. Please let us know if there are any other ways we can help.
      Attached Files
      Jessica P.NinjaTrader Customer Service

      Comment


        #18
        Thanks Jessica, I'll take a look at this. I really appreciate your help.

        Just a side note, this could be explained better in the documentation or handled in a better way without having to keep a reference in the scope of the function only when the state is less than Realtime.

        Just a thought, have a great weekend!

        Comment


          #19
          Thank you fxRichard. I have drawn the attention of the teams responsible for documentation to this thread. Any information we add will be made automatically available to them.
          Jessica P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          117 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          166 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          85 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          130 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          88 views
          0 likes
          Last Post PaulMohn  
          Working...
          X