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

Continuous Strategy

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

    Continuous Strategy

    Hi, I am interested to test a couple of strategies in continuous mode, i.e running 5 days per week, for all allowed 22:30 trading hours with a mandatory break in between sessions, of cause. In view of this there are a couple of issues which would be usefull to clarify

    1. Do I need to be constantly logged in NT on, or it is possible to activate the strategy, log off and strategy will continue to perform, which will be most optimal outcome as sometimes Internet can drop off , or some other PC related issues can occur.

    2. What happens if there are some connectivity or PC related issues on user part , would strategy still continue to run ?

    3. Are there some server solutions where strategy can be uploaded and kept running regardless of state of local NT installation ?

    Or may be there are some other solutions that were already developed to deal with such tasks that I will be quite interested to hear about.

    Cheers
    ​​​​​​​
    Victor

    #2
    Hi Victor, thanks for posting.

    1. The Computer and NinjaTrader need to be on to run the strategy logic. There are disconnection handling settings under Tools>Options>Strategies that tell the strategy what to do if the internet connection drops. Also, if a strategy opens a position and you need to re-enable it for any reason, there are multiple Startup behaviors you can appy to the strategy depeneding on its startup state:


    2. See #1

    3. You may use a VPS to run NinjaTrader on a virtual machine that runs in a data center. The NinjaTrader Ecosystem has companies that provide VPS services. If you would like more information on that, I will have a member of the Vendor Support team follow up.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for explanations, Chris.
      I think I will start testing from Demo account and see how disconnection issues are handled. But still would be interesting to hear about VPS offers and put things on really solid footing.

      One thing I was not able to figure out yet whether it is possible to open position at the start of new session taking into state of the position at the previous session close. Was it " immediately submit " ? I am in a bit of a bind here, as at the very very beginning ( first order) position is flat and then at the end session position is rarely flat: it either short or long so somehow those two seemingly contradictory things at the strategy beginning need to come together. Though forcing it to flat from the beginning of new session seems to work fairly well as well. But if there is way to synchronize new open with previous close that would be pretty neat as it would continue previous trend. Whether it is profitable need to be tested.
      Cheers

      Comment


        #4
        Hi Victor, If you need to save some data between enabling the strategy, like if you had a position, the position closed at the end of the session, you disabled and re-enable the strategy at the beginning of the next session and you want the strategy to know information about this previous position you would need to save the custom data in a .txt file. We have an example here:


        Best regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chris,
          Was my understanding correct that none of the 4 available options of start strategy behaviour allow to start new position at the opening of a new session while taking account state of the position ( Long or SHort) at the closure of the previous session without saving custom data ? That is the essence of the question. If current position at the closure of the previous session was Short I would like to start new session as Short and not flat. Just want to make sure that I understand response correctly. I dont want to complicate things too much so if some sort of additional script is needed to synchronize between close and open I'd rather do it without it. Cheers

          Comment


            #6
            Hi, thanks for your reply.

            No startup behavior will take into account a position that is already closed. It either sees a working order or an open position that the strategy generated in the past and it keeps managing those positions/orders.

            Best regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,
              I transferred my strategy development and evaluation to SIM account and yesterday started ( enabled) 2 strategies before session closure in the hope that they will restart automatically upon session reopening at 5PM CT. Though today in the morning I found that both strategies were disabled. Could you please clarify whether it is possible to run uninterrupted strategy from session to session upon enabling it or they need to be manually restarted at the beginning of each session even if strategy is already loaded. THanks

              Comment


                #8
                Hi kazbek966, thanks for the follow-up. The platform must stay open to keep the strategy enabled. If the platform was shut down or if you reset the PC then the strategy would need to be re-enabled. It's also possible for the connection to reset over the weekend for server maintenance. There are settings under Tools>Options>Strategies called "OnConnectionLoss" (documentation) These settings let you define the strategy behavior when a connection loss occurs. Set it to keep running and increace the wait time to keep the strategy running over the weekend.

                Kind regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for following up, Chris. Could we please spend a bit more time troubleshooting this issue as my strategy keeps being disabled after implementing currently obvious to me mitigating measures. I am in CET time zone and did not manage to monitor what is happening at the end of the session that falls into local 1AM. Here is a description of my original set-up and things I tried to enable continuous strategy.

                  ORIGINAL SET-UP

                  1. ON CONNECTION LOSS ( KEEP RUNNING, DELAY :10,# Restart Attempts : 4, Restart within X minutes : 5)
                  2. Ninja Script :. Cancel entry orders when strategy is disabled : CHECK
                  3. Autoclose position: SET @ 3:40 PM CT
                  4. Exit on Session Close : Checked and Set. on 900 seconds
                  5. Start behaviour: Wait Until flat
                  6. Time in Force; GTC
                  7. My connection is Ninja Continuum ( so no obvious third party issues )

                  FIXES

                  - First obvious thing : Unchecked Exit on Session close, while having Autoclose position checked. No effect whatsoever.
                  - Tried different Long and Short strategies : No effect.
                  - May try removing Autoclose and Hard coding trading hours and Exit time in the strategy itself.

                  Anything else to try ?

                  Indeed the platform is being kept open, I am keeping an eye on it during the day and everything runs quite smooth. PC was not restarted so I am pretty sure no connection loss has occurred as strategy being consistently disconnected for 4 days in row. So there is systemic issue. But if there is a log somewhere it will be pretty interesting to take a look.

                  Comment


                    #10
                    P.S: Found LOG Folder and enclosing sequence of events

                    2022-02-17 11:00:00:315|1|64|Instrument='MNQ 03-22' Account='Sim101' Average price=14359 Quantity=1 Market position=Short Operation=Operation_Add
                    2022-02-17 11:00:00:345|1|32|Order='79a07bcd3b6b4717bcb8c076b 8956fb4/Sim101' Name='Sell short' New state='Filled' Instrument='MNQ 03-22' Action='Sell short' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=14359 Error='No error' Native error=''
                    2022-02-17 11:00:00:345|1|8|Execution='2f4c267d668448e2977de7 211206c59d' Instrument='MNQ 03-22' Account='Sim101' Exchange=Default Price=14359 Quantity=1 Market position=Short Operation=Operation_Add Order='79a07bcd3b6b4717bcb8c076b8956fb4' Time='2/17/2022 11:00 AM'
                    2022-02-17 11:00:00:345|1|64|Instrument='MNQ 03-22' Account='Sim101' Average price=14359 Quantity=2 Market position=Short Operation=Update
                    2022-02-17 15:40:00:176|1|64|Auto close on account '210700' triggered at '2/17/2022 3:40:00 PM' on instruments 'MNQ 03-22 Globex'
                    2022-02-17 15:40:00:177|1|64|Flatten account='210700'
                    2022-02-17 15:40:00:177|1|64|Auto close on account 'Sim101' triggered at '2/17/2022 3:40:00 PM' on instruments 'MNQ 03-22 Globex'
                    2022-02-17 15:40:00:177|1|64|Flatten account='Sim101'
                    2022-02-17 15:40:00:177|1|4|Disabling NinjaScript strategy 'AuLLMAMedLong/256400622'
                    2022-02-17 15:40:00:177|1|4|Disabling NinjaScript strategy 'AuLLMAMedShort/256400623'
                    2022-02-17 15:40:00:178|1|4|Disabling NinjaScript strategy 'MAMAonRSILong/256400628'
                    2022-02-17 15:40:00:178|1|4|Disabling NinjaScript strategy 'MAMAonRShort/256400629'
                    2022-02-17 15:40:00:232|1|32|Order='c96fe92386cf413c88c534b28 55a2792/Sim101' Name='Close' New state='Submitted' Instrument='MNQ 03-22' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                    2022-02-17 15:40:00:333|1|32|Order='c96fe92386cf413c88c534b28 55a2792/Sim101' Name='Close' New state='Accepted' Instrument='MNQ 03-22' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                    2022-02-17 15:40:00:333|1|32|Order='c96fe92386cf413c88c534b28 55a2792/Sim101' Name='Close' New state='Working' Instrument='MNQ 03-22' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
                    2022-02-17 15:40:00:373|1|32|Order='c96fe92386cf413c88c534b28 55a2792/Sim101' Name='Close' New state='Filled' Instrument='MNQ 03-22' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=2 Type='Market' Time in force=DAY Oco='' Filled=2 Fill price=14164 Error='No error' Native error=''
                    2022-02-17 15:40:00:374|1|8|Execution='34ce6ed5143942748986f7 cc0301a5d7' Instrument='MNQ 03-22' Account='Sim101' Exchange=Default Price=14164 Quantity=2 Market position=Long Operation=Operation_Add Order='c96fe92386cf413c88c534b2855a2792' Time='2/17/2022 3:40 PM'
                    2022-02-17 15:40:00:374|1|64|Instrument='MNQ 03-22' Account='Sim101' Average price=0 Quantity=0 Market position=Flat Operation=Remove
                    2022-02-17 17:53:56:812|1|2|NinjaTrader Continuum: Primary connection=Connected, Price feed=Connection lost
                    2022-02-17 17:53:57:532|1|2|NinjaTrader Continuum: Primary connection=Connected, Price feed=Connected

                    2022-02-18 00:11:10:083|1|4|Enabling NinjaScript strategy 'MAMAonRShort/256400629' : On starting a real-time strategy - StartBehavior=WaitUntilFlat Position=MNQ 03-22 1S EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Ignore all errors ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
                    2022-02-18 00:11:13:608|1|4|Enabling NinjaScript strategy 'AuLLMAMedShort/256400623' : On starting a real-time strategy - StartBehavior=ImmediatelySubmit EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 900 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
                    2022-02-18 00:11:44:261|1|4|Enabling NinjaScript strategy 'MAMAonRSILong/256400628' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Ignore all errors ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
                    2022-02-18 00:11:46:667|1|4|Enabling NinjaScript strategy 'AuLLMAMedLong/256400622' : On starting a real-time strategy - StartBehavior=ImmediatelySubmit Position=MNQ 03-22 1L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 900 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes

                    Comment


                      #11
                      Hi kazbek966, thanks for the follow up.

                      If you have auto close positions set it will disable your strategy. You need to turn that off and implement the auto close within the strategy instead. You can get the timestamp of each bar using the Time[] array:


                      Kind regards,
                      -ChrisL
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Chris, that was one of the questions I had in mind : difference between Autoclose and Exit on Session Close. I guesstimated that based on its name Autoclose will close without disabling strategy. So once this thing was clarified would it be correct to assume that Exit on Session Close, would close position and NOT disable strategy ? Or both of them will disable ? I explored TimeSeries and other Time Related topics and there are great examples presented both as scripts and strategies so I think I will manage this part, or at least will give it an honest try, test sometime next week before contacting again if some additional issues will arise. Thanks

                        Comment


                          #13
                          Hi kazbek966, Exit On Session Close will not disable the strategy. Use this to close open positions at the end of the session.

                          Kind regards,
                          -ChrisL
                          Chris L.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by giulyko00, Today, 12:03 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post giulyko00  
                          Started by AttiM, 02-14-2024, 05:20 PM
                          12 responses
                          213 views
                          0 likes
                          Last Post DrakeiJosh  
                          Started by cre8able, 02-11-2023, 05:43 PM
                          3 responses
                          238 views
                          0 likes
                          Last Post rhubear
                          by rhubear
                           
                          Started by frslvr, 04-11-2024, 07:26 AM
                          8 responses
                          117 views
                          1 like
                          Last Post NinjaTrader_BrandonH  
                          Started by stafe, 04-15-2024, 08:34 PM
                          10 responses
                          47 views
                          0 likes
                          Last Post stafe
                          by stafe
                           
                          Working...
                          X