Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not executing OnStartUp() in strategy

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

    Not executing OnStartUp() in strategy

    Hi,

    First off, I think this may be hard to reproduce, so I'm also interested in whether other people have seen this, and whether NT dev/support may have some idea why it occurs.

    I've seen a similar situation before where it looks like if there's a problem with a strategy in the strategies tab, the strategy is clickable enabled/disabled but without anything running, or at least without initialize.

    Now today I am having serious problems in the strategies tab.

    Not all strategies, and not all instruments, but quite often I can set up a strategy in the tab, I see the initialize run, I then enable it, and I see OnBarUpdate, but no OnStartUp. I have a print in there. I've tried with a simple 'MyCustomStrategy' and it sometimes happens there too, but it definitely happens.

    Any thoughts?

    #2
    Not sure if it helps but I had a similar thing today. Try disbaling it and removing it from the Stratgeies tab, then add it back and enable it.

    I was running the four instances of a Strategy today (on four instruments) and one of them did not Print() in OnStartUp(). The above steps made it good. NT7b12. Nothing in the log or trace.

    Comment


      #3
      Good, then it's not just me.

      I should have mentioned, I'm also NT7B12, and I tried removing and putting them back, and also restarting, and also reinstalling NT (from 11->12 anyway)

      It's with my Zen-Fire connection.

      It would be good if dev could have a good think of a scenario in which it could, because it's pretty serious, and clearing dbs etc won't be a decent solution.

      Comment


        #4
        Whats your OnStartUp() code look like? I've been putting something like this in all my 'strats:

        PHP Code:
        protected override void OnStartUp()//////////////////////////////////////////////////////////////
        {
        Print(DateTime.Now+" STRATEGY NinjaSpreader "+ Instrument.FullName +"/" + hedgeInstrument + " ENABLED");
         
        } 
        
        I've also been adding an OnTermination()

        PHP Code:
        protected override void OnTermination()
        {
        Print(DateTime.Now+" STRATEGY NinjaSpreader "+ Instrument.FullName +"/" +hedgeInstrument + " DISABLED. Inventory is "+ inventory+" Spread(s).");
        } 
        
        I'm a big fan of the Output window

        Comment


          #5
          Yes, I have the same, except I have a flag that stops it printing during backtesting ;-)

          Comment


            #6
            I have to ask and I hope you can share... the only way I've been able to pull that off is by disabling backtesting the whole strat as an option as follows:

            PHP Code:
            protected override void OnBarUpdate()///////////////////////////////////////////////////////////
            {
            if (backtest == false)
            {
            if (Historical)
            return;
            }
            // do something 
            
            Where "backest" is a bool set in the Strategy Editor.

            Do you have a way to exclude individual print statements from executing on historical data?

            I've tried something like if (!Historical) Print("This is not Historical");
            but have had no joy.

            What's working for you if you don't mind sharing?

            Comment


              #7
              Hi dave1992 and MXASJ,

              This is the first report of this and would like additional information to reproduce. Is it only when you have multiple strategies? Are there any errors in the Control Center logs? What was the nature of the strategy causing issues? As in, was it the first time you added it to the Strategies tab? Was it a persisted strategy from earlier? Was it running beforehand and now it is recovering its position and things like that? Sync settings? Do you get any print like "Enabling NinjaScript strategy..."? Thank you.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                From my Output window:

                PHP Code:
                **NT** Enabling NinjaScript strategy 'CUR_001/5459f780de014d34b4a38e59b00e2888' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                **NT** Enabling NinjaScript strategy 'CUR_001/a9f7692cd47d4e05baf7cde4880b0eb4' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                2010-03-29 16:45:43 STRATEGY CUR_001/INSTRUMENT: 6J 06-10 ENABLED. MarketPosition: Flat
                **NT** Enabling NinjaScript strategy 'CUR_001/d3e9e7c8829646c390b07ff425247e62' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                **NT** Enabling NinjaScript strategy 'CUR_001/53f1d96d0f6d4b789f489a3fb6172cb7' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                2010-03-29 16:45:46 STRATEGY CUR_001/INSTRUMENT: 6B 06-10 ENABLED. MarketPosition: Flat
                2010-03-29 16:45:46 STRATEGY CUR_001/INSTRUMENT: 6C 06-10 ENABLED. MarketPosition: Flat
                **NT** Enabling NinjaScript strategy 'CUR_001/f66a2487b1c24a6b8a38f9ce94ffabd9' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                2010-03-29 16:45:49 STRATEGY CUR_001/INSTRUMENT: 6A 06-10 ENABLED. MarketPosition: Flat 
                
                There were five instruments, but only 9 statements above (should be 10). Instrument 6E was Enabled in the check box but did did not turn green nor print the OnStartUp print statement. I toggled the "Enable" checkbox on and off, saw nothing in the Output window, and then removed it from the Strategies tab and added and enabled it again.

                Upon doing that, I got:

                PHP Code:
                **NT** Enabling NinjaScript strategy 'CUR_001/bb8f7b5cd81b40d3b7d35673ca324af7' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                2010-03-29 16:54:13 STRATEGY CUR_001/INSTRUMENT: 6E 06-10 ENABLED. MarketPosition: Flat 
                
                Which is the expected behavior.

                It was persistant strategies, after reconnecting after a hard crash (Windows needs to shut this down), which was triggered by trying to open a chart of 6E. No other charts were open. All other strats restarted fine. I saw nothing in the tarce or logs about exceptions that would have led to that crash

                As Dave mentioned it looks like a hard one to reproduce but I'll look out for it.

                Comment


                  #9
                  MXASJ,

                  Thanks. When you say it did not turn green, what did it do instead? Just no color? Maybe yellow?
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I had it in various scenarios. I had the same strategy, 5 different instruments. Some where OK, some not. I always got the 'starting ninjascript' message, except for one time when you could click it on and off with no message at all. One time I got the starting ninjascript message and no output (i.e. nothing executed at all - init, on startup, on bar)

                    All this time, all 5 instruments were receiving data.

                    Sometimes you have to click twice in the enable box to get a tick.

                    To be honest, the whole strategy tab feels kind of flakey and unreliable. It took me six hours today to get 5 strats running properly at the same time.

                    All strategies were persisted, and removed/etc multiple times. I'll try and think of more.

                    Comment


                      #11
                      dave1992,

                      The first click you press in the Strategies tab selects the strategy row. Then you need to click it again to actually enable it. This is a grid component limitation.

                      As far as taking 6 hours to start strategies, I am not sure what exactly you were trying. I just tried on my end with 5 instruments on SampleMACrossOver. All started up okay in a matter of seconds. Please try the attached strategy to ensure it is not the strategy programming causing issues. Can you please describe what exactly was wrong for your startups each time? Was it the same problem over and over? Or different? Thanks.

                      Code:
                      **NT** Enabling NinjaScript strategy 'SampleMACrossOverStartup/1e4de77d80c7417ebdf01ee93d4cf59a' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                      ES 06-10 Minute 1
                      **NT** Enabling NinjaScript strategy 'SampleMACrossOverStartup/c02d131508e242c5943ba6de05d6b7e9' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                      FDAX 06-10 Minute 1
                      **NT** Enabling NinjaScript strategy 'SampleMACrossOverStartup/9e1bbd5e3a2744f1846e96cb160741c5' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                      NQ 06-10 Minute 1
                      **NT** Enabling NinjaScript strategy 'SampleMACrossOverStartup/13a56eb8f1f34c3ebc7f48ae70f8f4af' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                      TF 06-10 Minute 1
                      **NT** Enabling NinjaScript strategy 'SampleMACrossOverStartup/a882ec3cc46d47f0ad7386ab67b70cb5' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                      YM 06-10 Minute 1
                      **NT** Enabling NinjaScript strategy 'SampleMACrossOverStartup/bc433e350aaf40dbb3bcb1476f050665' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                      ZB 06-10 Minute 1
                      Attached Files
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Josh,

                        In my case it stayed white, with behavior similar to what Dave mentioned as having happened once ("one time when you could click it on and off with no message at all"). It was recovering its position after a crash. Hard to reproduce, but I'll keep an eye out for it.

                        FWIW If I enable the use of historical data by the code I show below on OnBarUpdate(), some newly enabled Strategies will stay yellow until (I presume) a new reverse or flatten signal is generated. I believe that is expected behavior (StratgeyPosition?) but it is something I'm in the process of checking against entry and exit signals and acutal executions.

                        Comment


                          #13
                          Originally posted by NinjaTrader_Josh View Post
                          dave1992,

                          The first click you press in the Strategies tab selects the strategy row. Then you need to click it again to actually enable it. This is a grid component limitation.
                          Really? Which grid component does Ninja use?

                          As far as taking 6 hours to start strategies, I am not sure what exactly you were trying.
                          I didn't say it took me 6 hours to start strategies - I said it took me 6 hours to get them all working properly ;-)

                          I have 5 running strategies, and I estimate that 95% of the times I started a strategy yesterday it didn't start properly, so it took me hours to get them all going properly at the same time.

                          Comment


                            #14
                            MXASJ,

                            Yellow means it is holding a strategy position and waiting for that to close to match a flat account position before going live. That is expected behavior when you are using WaitUntilFlat. If you are using ImmediatelySubmit it should go green right away.

                            dave1992,

                            Please describe what you mean by not working properly? What went wrong? If it is simply OnStartUp() please try my attached strategy earlier and see if you can get it to start all at the same time with ease or not. Thank you.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Josh View Post
                              MXASJ,

                              Please describe what you mean by not working properly? What went wrong? If it is simply OnStartUp() please try my attached strategy earlier and see if you can get it to start all at the same time with ease or not. Thank you.
                              What I mean is not executing OnStartUp every time. Sorry I didn't try your strat - I'd mentioned in the first post that it happens also with a simple strat. OK, so I tried yours, and first six times I stopped and started it, and no print message from OnStartUp. Just this:

                              Code:
                               Enabling NinjaScript strategy 'SampleMACrossOverStartup/0a7d8bc108304ea3b27bac973fed4acb' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes                                                             Disabling NinjaScript strategy 'SampleMACrossOverStartup/0a7d8bc108304ea3b27bac973fed4acb'
                              So, I edited the strat to put a print line in OnBarUpdate() and when I compiled I got this

                              Failed to execute DB job 'StrategyUpdateJob': There was an error generating the XML document.: AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only.

                              and on trying to run the strategy I got this

                              Failed to execute DB job 'StrategyUpdateJob': There was an error generating the XML document.: AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only.
                              So I had to restart Ninja, and now I tried it on and off a few times and it works, and gives me

                              Code:
                              Enabling NinjaScript strategy 'SampleMACrossOverStartup/b470b58f9aca476db5970e72a4adc261' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes               
                               6A 06-10 Minute 1
                              So, the answer is, yes it happens with your strategy, and as I implied, it's difficult to say exactly what the circumstances are. There is a reasonable chance that a developer might see quickly what the scenario is in which it doesn't get executed, if you can spare a resource for that ;-)

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              606 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              351 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              561 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X