Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss in OnOrderUpdate for Reversal

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

    SetStopLoss in OnOrderUpdate for Reversal

    My current handling of a reversal trade:
    - ExitLong/ExitShort in OnBarUpdate (CaclculateOnBarClose is true)
    - save "ActionAfterFlat"
    - in OnPositionUpdate for MarketPosition.Flat with a "ActionAfterFlat" set new Stop Loss & then EnterLong/EnterShort

    Works fine in backtest and market replay. In real-time my feeling is that its quit slow and I get some slippage between Exit and Entry.

    Is there a chance to do this with OnOrderUpdate?
    Idea is to EnterLong/EnterShort without explicit ExitLong/ExitShort and wait e.g. for PendingCancel on (old) Stop Loss Order and then set new Stop Loss before new Stop Order is calculated by NinjaTrader and executed.

    What is the best event to do this (Accepted,Working or Filled of ByToCover / Close Position or PendingCancel of
    BuyToCover / Stop Loss)? Cancelled of BuyToCover / Stop Loss is executed in my test after Filled of Buy Order (in new direction) and is too late? Is it ok to call SetStopLoss before old Stop Order is canceled?

    #2
    Josh will follow up later today.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi michaelbb,

      I'm not sure what you mean by ActionAfterFlat. For reversal orders I think you can just simply do an EnterLong()/Short() in the opposite direction right off the bat. For instance, if you are long just submit an EnterShort(). It will automatically close you out and open you a new position on the short side. Everything is done in one step. There is no fiddle diddle so you should see quick speeds on this one.

      As far as SetStopLoss() goes, you should be able to just submit a new stop loss immediately after your new EnterShort() method since your original stop loss will be cancelled due to the position it was tracking being closed out already.

      If you want to work in OnOrderUpdate() I suggest you not use the Set() methods and opt for ExitLongStop() or ExitLongLimit() methods. It will provide you with the utmost flexibility in control for your stops and targets. You want to check the order state of your entry's IOrder. If it is partial filled or filled you want to immediately fire off your protective stop orders. I don't think you need to worry about the previous stop's order state since it is irrelevant to your current position.
      Last edited by NinjaTrader_JoshP; 05-08-2008, 01:34 AM.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Hi Josh,

        ActionAfterFlat is a self-defined STRUC. In case of reversal I use it to store that there is something what has to be done after position is flat. Roughly description of handling in first post. Only purpose is to make sure that current stop loss is transmitted to NinjaTrader before the next Entry Order is processed. This works fine and is stable in real-time.

        Yesterday I changed this and used method you described in your post (Enterlong/Entershort without explicit close and call SetStopLoss after that). It worked fine in backtest and market-replay. But in real-time the new stop loss was send with old stop loss value and was filled. That is why I asked for best event to do this.

        Decided now to use my old and stable handling of reverse orders again. Currently there is no time for me to investigate on this subject.

        Comment


          #5
          Originally posted by Josh View Post
          For reversal orders I think you can just simply do an EnterLong()/Short() in the opposite direction right off the bat. For instance, if you are long just submit an EnterShort(). It will automatically close you out and open you a new position on the short side. Everything is done in one step.
          Does that still work if you've used different signalname parameters for long and short entries?

          Thanks

          Comment


            #6
            I believe so but you would have to test and verify.
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            672 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            577 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X