Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Configure State hit twice

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

    Configure State hit twice

    Hi. We are using NT 8.0.18.1 64-bit and while developing our strategy we noticed that the Configure state is being hit twice and running our code twice.

    We've tested this with the sample strategy SampleAtmStrategy.cs and updated OnStateChange code to be this:

    PHP Code:
    protected override void OnStateChange()
    {
        if (State == State.SetDefaults)
        {
            Description    = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleATMStrategy;
            Name        = NinjaTrader.Custom.Resource.NinjaScriptStrategyNameSampleATMStrategy;
            // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
            // See the Help Guide for additional information
            IsInstantiatedOnEachOptimizationIteration = false;
        }
        else if (State == State.Configure)
        {
            Print(DateTime.Now.ToString() + " " + guid + " " + State.ToString());
        }
        else if (State == State.Active)
        {
            Print(DateTime.Now.ToString() + " " + guid + " " + State.ToString());
        }
        else if (State == State.DataLoaded)
        {
            Print(DateTime.Now.ToString() + " " + guid + " " + State.ToString());
        }
    } 
    
    then added SampleAtmStrategy, pressed OK, and the output is this:

    28/06/2019 8:11:54 PM 89ff26c5-0212-4410-8e32-127baafbb9d2 Configure
    28/06/2019 8:11:54 PM 3808acfa-c442-4158-9b07-597ccdfa8871 Configure
    28/06/2019 8:11:54 PM 3808acfa-c442-4158-9b07-597ccdfa8871 DataLoaded
    Enabling NinjaScript strategy 'Sample ATM strategy/150544919' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes


    Is there a way so that Configure will only be run once? Thanks.

    #2
    Hello cmarkb,

    I just wanted to make a quick reply to let you know we are looking into this. Once I have more details I will reply back here.


    I look forward to being of further assistance.

    Comment


      #3
      Hello cmarkb,

      After speaking with QA it appears this is expected although not documented as an expectation. State.Configure seems to also be called multiple times like SetDefaults when used from a chart despite the help guide noting it should only be run once. The note we have about this happening for SetDefaults does not include Configure specifically which creates some confusion. There are cases where it does get executed more than once like SetDefaults, however the other executions are from the menu instances, not the chart instance. For one time actions, I would suggest moving what you can to State.DataLoaded to avoid this.

      Was there a more specific example you can provide which is affected by this being called more than once? Are you seeing a specific NinjaScript property that requires State.Configure failing due to this, or was this for your own logic and uses?



      I look forward to being of further assistance.

      Comment

      Latest Posts

      Collapse

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