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 zstheorist, Today, 07:52 PM
          0 responses
          6 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X