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 bmartz, 03-12-2024, 06:12 AM
          4 responses
          32 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          12 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X