• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Strategy donīt work in live trading but in Historical and Strategy analyzer

  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy donīt work in live trading but in Historical and Strategy analyzer


    My strategy donīt work in live trading but do historical trades and work in the strategyanalyzer.

    Also I wonder how the strategy can do trades in the past.

    Thank you very much.

    Hello Uregon,

    Thanks for your post.

    Please make sure the strategy is not waiting for its virtual position to be closed if you are using the WaitUntilFlat Start Behavior. (Check the Strategies tab of the Control Center and see if the strategy is yellow/orange.) I have included some information on Start Behaviors and the difference between strategy and account positions in this post.

    If this is not the case and the strategy is gray, then I would suggest checking for errors in the log tab of the Control Center to see if the strategy has errored out.

    If the strategy is green and is not taking trades, the strategy is running but the logic is not allowing it to place trades. Debugging steps should then be taken at this point.

    To answer your question about the strategy doing trades in the past, the strategy will show you which trades it would have made when it processes historical data when we enable it, or when we run a backtest.

    Information on Start Behaviors

    When a strategy is enabled, it processes historical data to determine trades that the strategy would have made on the data that is already on the PC/chart and to determine what position the strategy is in. (Strategy positions are separate from actual Account positions.) If the strategy calculates that is in a virtual position when it transitions to processing realtime data, the strategy's Start Behavior may waiting until this position becomes flat before orders are allowed to submit with realtime data. (Wait Until Flat.) You can observe the Strategies tab of the Control Center if the strategy is in a virtual position waiting to become flat. The strategy will be orange/yellow when waiting to for the historical position to be closed, and will be green when allowed to trade live.

    Strategy Position vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm
    Start Behaviors - https://ninjatrader.com/support/helpGuides/nt7/syncing_account_positions.htm

    Debugging Tips

    In order to better understand how the code is executing, I recommend adding debugging prints to your strategy. By adding prints for the values used to evaluate your conditions outside of those conditions, you can observe if logic is becoming true and allowing your order submission methods to fire.

    If you are seeing your order submission logic being reached, but it is not executing, there may be an issue where the strategy is already in a virtual position that is not allowing you to re-enter. TraceOrders can be enabled in the strategy's Initialize method so the strategy prints its order feedback, and you may also observe the log tab of the Control Center for additional hints.

    Some items to check when you are taking debugging steps:
    1. Are your conditions allowing your order submission methods to be reached?
    2. Is the strategy currently in a position that is preventing it from submitting another entry order?
    3. Do you see any errors in the log tab of the Control Center or does Trace Orders give you any feedback?
    I've included some tips for debugging below. The Playback Connection can be used to replay data as if it were realtime.

    Debugging Tips - https://ninjatrader.com/support/helpGuides/nt7/debugging_your_ninjascript_cod.htm
    TraceOrders - https://ninjatrader.com/support/helpGuides/nt7/traceorders2.htm
    Market Replay - https://ninjatrader.com/support/help...ket_replay.htm

    Please let us know if there is anything else we can do to help.
    Last edited by NinjaTrader_Jim; 03-05-2020, 10:07 AM.
    JimNinjaTrader Customer Service


    • Latest Posts


      Topics Statistics Last Post
      Started by DaveCro, Today, 09:05 PM
      0 responses
      Last Post DaveCro
      by DaveCro
      Started by magnatauren, Today, 08:26 PM
      0 responses
      Last Post magnatauren  
      Started by SharonSS, Today, 07:21 PM
      1 response
      Last Post NinjaTrader_EricB  
      Started by bmccoard, Today, 06:48 PM
      0 responses
      Last Post bmccoard  
      Started by omololu, Today, 05:10 PM
      0 responses
      Last Post omololu
      by omololu