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

Cycling Strategy On/Off and Order Cancelling/Submission

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

    Cycling Strategy On/Off and Order Cancelling/Submission

    If I disable a strategy with a pending order, the order remains pending. When I re-enable the strategy, the pending order is cancelled. All the conditions for order submission are still met, so I wait for the next bar close, but the order is not submitted. I have to disable and re-enable the strategy again in order to get the order submitted (which it does as soon as the strategy is re-enabled).

    Is there a common reason for this behaviour? The strategy is in operation because I print the entry order condition on each bar close and they print fine, but the order just doesn't go through unless I do a second cycle of disabling/enabling the strategy.

    #2
    Hello pmn100,

    Thanks for opening the thread.

    The NinjaScript options in the options menu will tell the strategy if it should cancel any entry or exit orders upon disable. Upon re-enabling, the Start Behavior determines how the strategy should use the historical data it processes to resume a position it had made in a previous run.
    • Immediately Submit will try to match any active orders that were made by the strategy, while Wait Until Flat will cancel any active orders that were previously made.
    • Wait Until Flat will wait until the strategy is in a flat position before it starts submitting orders live. The yellow indicator means the strategy is in a virtual/historical position. When the strategy starts, historical data is parsed through OnBarUpdate() to create these simulated fills. Once the historical data gets finished processing, Realtime data begins iterating through OnBarUpdate(). The real data would have to close the virtual position before real trades can take place.
    • Synchronize Account is an additional Start Behavior that can be used in combination with Immediately Submit and Wait Until Flat to Synchronize the Account position to the Strategy's position. This would involve the strategy placing an additional reconciliary order to synchronize the account to the strategy.


    If you would like to have your strategy resume if data has been reloaded or if the strategy has briefly been disabled, I would suggest to look into using Immediately Submit instead of the default Wait Until Flat start behavior.

    I would suggest to review the documentation on syncing account positions for complete information on how these start behaviors work exactly. It's important to understand how these behaviors work when you decide to go live with your strategy. After reviewing the documentation, I would suggest to test the behaviors when disabling and re-enabling a simple strategy that can enter a position quickly. The reading can be a little dense, so testing the behaviors can provide a good visual.

    The SampleOnOrderUpdate strategy is a good example that can be used to test start behaviors quickly. You could to set the BarsRequired to 0 and apply it to a 5 second data series on the simulated data feed to get some quick entries. You can then disable and enable the strategy from the Control Center to trigger the Start Behavior as well as the cancel-on-disable behaviors.

    Keep in mind, Immediately Submit will need to transition Order objects from Historical to Realtime in order for the strategy to resume properly.

    It is also important to understand the difference between Strategy and Account positions to conceptualize NinjaTrader's Start Behaviors. Please see the Strategy Position vs. Account Position documentation for details.

    Here are some publicly available resources to the items discussed.

    Strategy Position vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

    Syncing Account Positions - https://ninjatrader.com/support/help..._positions.htm

    SampleOnOrderUpdate strategy - http://ninjatrader.com/support/forum...ead.php?t=7499

    Transitioning order references from Historical to Realtime - https://ninjatrader.com/support/help...storicaltolive -

    Here is a video I made demonstrating this behavior with the SampleOnOrderUpdate strategy as well. Keep in mind the Short Entry order gets filled in the beginning of the test, however the Start Behavior for Immediately Submit is then observed when the strategy is disabled/re-enabled and the orders are resumed.

    Demo - https://www.screencast.com/t/FUCm2zymF8Cd

    Please let me know if you have any questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Are there any lists of strategies for automated trading?

      I have created a bot for automated stock trading on Forex. Now, I'd like to use some strategy\ies to install into the trader software. Are there any complete lists of strategies for NinjaTrader? Have such lists been ever created?

      Thanx!

      Comment


        #4
        Thanks for the info. I do have another question, and its the reason I came across this issue.

        I'm live testing a strategy on the ger30 cfd from FXCM. I loaded the chart and strategy last night. On checking the chart this morning, there was no pending orders and there is a gap from the historical data loaded last night and the realtime data that started at 7am UK time.

        On selecting reload all historical data, the data from 7am shifted downwards to correspond with the historical data load, and an order was submitted as entry conditons were meet.

        So I've got to reload all historical chart data from within my strategy every morning in order to get the fresh price data lined up in the same way as my backtesting obviously is. I'm pretty sure I can do this with the ReloadAllHistoricalData() function from within OnBarUpdate with the use of a time filter and boolean to prevent it going into a loop of reloading. However, I notice on reloading historical data whilst a strategy is running on the chart causes a warning box to pop up, which I have to be around to click 'Yes' for.

        So my question is, is there a way to disable this warning box so I can reload historical data at the start of each day without having to be at the computer?

        Comment


          #5
          Hello everyone,

          @Dimitry_Pi, welcome to the forums! There are publicly released strategies in the Strategies section of the NinjaScript File Sharing forum. I'll provide a link below. If you have any additional questions on this matter, please open a new thread so we can keep this thread on the topic of resuming strategies.

          NinjaScript Strategies NT7 - https://ninjatrader.com/support/foru...ks.php?catid=5

          NinjaScript Strategies NT8 - https://ninjatrader.com/support/foru...ks.php?catid=8

          @pmn100, we only advise to use ReloadAllHistoricalData() in OnConnectionStatusUpdate(). Calling this within OnBarUpdate() may give you undesired results. You are welcome to use it if you can find a use for your needs, however. If the gap in data was received after a connection loss, you could catch the instance in OnConnectionStatusUpdate() if your ConnectionLossHandling is set to KeepRunning.

          Which warning message are you referring to? Order confirmation windows can be disabled in the Options menu under Trading. (Control Center > Tools > Options > Trading > Confirm Order Placement)

          Here are some documentation links for ReloadAllHistoricalData() and OnConnectionStatusUpdate().

          ReloadAllHistoricalData() - https://ninjatrader.com/support/help...oricaldata.htm

          OnConnectionStatusUpdate() - https://ninjatrader.com/support/help...atusupdate.htm

          Please let me know if I may be of further assistance.
          JimNinjaTrader Customer Service

          Comment


            #6
            Thanks for the reply.

            The warning message occurs when you reload historical data on a chart with an active strategy running on it.

            "You have an active strategy(s) running on the Instrument selected for historical data reload. Reloading data will terminate and restart these active strategy(s). Do you wish to continue?" Yes/No

            Will this message display if I try to reload historical data from within a strategy?


            As for the price discrepancy, it wasn't a connection loss that caused it, I think the historical data is adjusted to suit the level of the new price data. I will try to get a screen shot before and after a historical data reload on a live chart of Dax.

            Comment


              #7
              When I place ReloadAllHistoricalData() in a strategy, I do not see this warning.

              I will be happy to take a look at some screenshots depicting the price discrepancy with you and provide further input. Could you also provide a screenshot of the Market Data page of the Options Menu so we can observe the Merge policy and Record Live Data as historical setting?

              I look forward to being of further help.
              JimNinjaTrader Customer Service

              Comment


                #8
                Okay, I'll see if it happens tomorrow and get back to you. Hopefully there is a setting I can adjust so I don't have to bother programming the chart reload. My settings are currently set to 'Merge back adjusted' and Record live data as historical is unchecked, but I'll include the windows in the screenshot

                Thanks for the help.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                20 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                45 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                21 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                181 views
                0 likes
                Last Post jeronymite  
                Working...
                X