Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Waxavi, Today, 02:00 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by alifarahani, Today, 09:40 AM
      5 responses
      23 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Kaledus, Today, 01:29 PM
      4 responses
      12 views
      0 likes
      Last Post Kaledus
      by Kaledus
       
      Started by gentlebenthebear, Today, 01:30 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PhillT, Today, 02:16 PM
      2 responses
      7 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Working...
      X