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

keep stop order from before disconnect

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

    keep stop order from before disconnect

    How do I retain the stop order from my strategy when I'm restarting the strategy (due to some disconnect/disablement/etc)?

    All of the syncing options have "Any active orders on the account previously generated by the strategy that does not match an active strategy order will be cancelled". I don't want prior stop orders to be cancelled. But the restarted strategy won't match if it tries to historically calculate, so if I don't have an exact match, it sounds like my order will always be cancelled.

    Any way around this? I guess I could make copies of my strategy everytime there's a restart so it counts as a new strategy and doesn't cancel from the prior copy?

    Thanks

    #2
    Hello krpkevin,

    Thanks for your post.

    ImmediatelySubmit would be the recommended Start Behavior to resume a position and the strategy must not skip processing historical data.

    The strategy will calculate historical data to see what orders would be active and tries to match them with live working orders. If the live orders do not match, they will be replaced with historical orders.

    If, for example, the position is protected with stops and target orders that are offset from the fill price of an entry order, there can be some variance where the stop and target get submitted between historical and realtime, because historical can never be as accurate as realtime with regards to order fill simulations. (Slippage is a factor, and the fact that historical orders are filled with OHLC bar data can result in the fill price of an order being different and thus the price of stop/target orders.)

    If the difference between prices of these orders is minimal, you may wish to simply move forward with ImmediatelySubmit and accept that the orders will change if they don't calculate a match.

    If the difference between prices is of greater concern for you, you could consider adding intrabar granularity to the script to have historical orders filled with single tick data so they are closer to live orders. (Slippage can still be a factor for differences.)

    Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

    As a final item to consider, historical processing is forced to Calculate.OnBarClose, even if using a different Calculate mode like OnPriceChange or OnEachTick. If you need to have historical OnEachTick/OnPriceChange to generate the same signals, you can consider using Tick Replay. It is important to note that Tick Replay does not change how a historical order fill is simulated since the order will still be filled by the data series we submit it to.

    Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

    If you need intrabar logical processing with historical data, Tick Replay is needed.

    If you need intrabar order fill simulations with historical data, an additional data series must be added and orders must be submitted to that data series.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks, but my initial position was based on when I started the strategy. Something like "if(flat && [a generic market condition that's usually true]) then enter long". Essentially, "once the strategy is kicked off, get in long immediately, and manage from there". There's no specific trigger other then enabling the strategy.

      A historical calculation is not going to know when I started the strategy the first time. It's just going to enter at the beginning of the data.

      I'm thinking my copy idea is probably my best bet actually. Is there a way to add a stop to an existing position when it adopts it. So I have:
      Long position from strategy 1
      Stop order from strategy 1
      *Strategy 1 is disabled*
      Strategy 2 doesn't let me enable with existing orders. So delete the stop order
      Strategy 2 adopts strategy 1 position and immediately creates a stop order at price X (input by user)

      I haven't figured out how to do that last step. How do you pair a new stop order with an existing position?

      Thanks

      Comment


        #4
        Hello krpkevin,

        If you enable the strategy with the same data so it starts processing historical data on the same bar, the same signals would be generated to submit orders. If the time in which the strategy enters makes a difference for what position the strategy will be in, ensure that you are starting on the same [historical] bar.

        The re-enabled strategy that is enabled on the same set of data will start on the same historical bar and generate the same first trade signal and subsequent trade signals after that. Once we transition to realtime data, the active historical orders are compared with the live working orders, and these would be relative to the position that was last entered by the strategy. (Keep in mind what is noted in post #2 for how order fills can be different and how NinjaScript logic is forced to follow OnBarClose unless Tick Replay is used.)

        If you are skipping historical processing, this is another story. There would be no way to calculate what position the strategy should be in or what orders it should have active.

        Something else to consider would be to write a strategy that uses AdoptAccountPosition to capture an active position. You would not be able to resume orders this way like you can with ImmediatelySubmit, but you could capture an active position and place new stops and targets when the script gets to State.Realtime. I have attached an example.

        We look forward to assisting.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks, it looks like that SubmitOrderUnmanaged is what I was looking for with my last question. I'm might come back to that because the help text warnings scared me a little bit. In the meantime I'm going with your other suggestion of loading a chart with exactly the number of bars I need before restarting the strategy. I have an indicator, so I actually have to load more bars than I need to calculate the indicator then do something like if(CurrentBar<histBarsForIndicator)return; But that's not so bad. It did resubmit my stop, so I have two stop loss orders when I restart the strategy, but it's easy to cancel the extra one.

          Thanks again for your help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by terofs, Yesterday, 04:18 PM
          1 response
          21 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by CommonWhale, Today, 09:55 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Gerik, Today, 09:40 AM
          2 responses
          7 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Started by RookieTrader, Today, 09:37 AM
          2 responses
          12 views
          0 likes
          Last Post RookieTrader  
          Started by alifarahani, Today, 09:40 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X