Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop and Reverse Strategy

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

    Stop and Reverse Strategy

    Hi NT Team

    I was wondering if there is a StopAndReverse kind of order. What I am trying to achieve is quite simple, however I am not sure how to program this in Ninjascript. Imagine I am using a simple moving average cross over strategy with a 1% stoploss. what I would like the strategy to do is stop and reverse my position once the stoploss is triggered. e.i. assume fast ma has crossed above slow ma, my strategy would enter a long position. Now assume price drops to my stoploss level, what I would like is to stop my long position and enter a short position. Is this currently possible with NinjaTrader?

    Thanks,

    #2
    Hello sburtt,

    While, we do have a specific method that will do a Stop and Reversal using the Managed Approach if you call an EnterShort() method while in a Long Position NinjaTrader will automatically reverse your position for your by send an order to make you flat and then sending an order for your short position.

    If you would like to keep your Stop Loss set then you can monitor it and when it is filled you may call the EnterShort method to achieve this as well. Here is a reference that goes over monitoring Stop loss and Profit target orders that you may use as reference.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello sburtt,

      While, we do have a specific method that will do a Stop and Reversal using the Managed Approach if you call an EnterShort() method while in a Long Position NinjaTrader will automatically reverse your position for your by send an order to make you flat and then sending an order for your short position.

      If you would like to keep your Stop Loss set then you can monitor it and when it is filled you may call the EnterShort method to achieve this as well. Here is a reference that goes over monitoring Stop loss and Profit target orders that you may use as reference.
      http://www.ninjatrader.com/support/f...ead.php?t=5790
      Hi JC, thanks for your reply. I would like to stay in the Managed Approach, as I have little understanding of the Unmanaged Approach. Do you think this would work? Obviously it's not a hard stop, do you think it would be possible to code something like my request in the Managed Approach?

      Code:
       if(Position.MarketPosition != MarketPosition.Long                &&  Position.GetProfitLoss(Close[0], PerformanceUnit.Percent) <= -0.01)                    {                 ExitLong();                  EnterShort();             }

      Comment


        #4
        Hello sburtt,

        Yes, that will work. Note that if you just call EnterShort() it will do the same thing as NinjaTrader will submit a close order and then go short as well.
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JC View Post
          Hello sburtt,

          Yes, that will work. Note that if you just call EnterShort() it will do the same thing as NinjaTrader will submit a close order and then go short as well.
          JC I have a query. This technique is clearly not a stop & reverse, as it only takes place OnBarUpdate, and I am using 60min bars. However, if I use MultiTimeFrame and I add a 1min bar and adapt the code to the 1min bar this should act very similar to a stop loss, is this correct?

          code should be something like this right?

          Code:
           [B][FONT=&quot]protected override void Initialize() 
          {
              Add(PeriodType.Minute, 1);[/FONT][/B]
            [B][FONT=&quot][…][/FONT][/B]
            [B][FONT=&quot]protected override void OnBarUpdate()
           
           [/FONT][/B][B][COLOR=blue][FONT=&quot][/FONT][/COLOR][/B]
            [B][FONT=&quot][…][/FONT][/B]
            [B][COLOR=blue][FONT=&quot] [/FONT][/COLOR][/B]
            [B][COLOR=blue][FONT=&quot]else[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot][/FONT][/COLOR][/B]
            [B][COLOR=blue][FONT=&quot]if[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot](Position.MarketPosition == MarketPosition.Long                [/FONT][/COLOR][/B]
            [B][COLOR=black][FONT=&quot]&&  Position.GetProfitLoss(Close[[/FONT][/COLOR][/B][B][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot]], PerformanceUnit.Percent) <= -[/FONT][/COLOR][/B][B][COLOR=purple][FONT=&quot]0.01[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot])[/FONT][/COLOR][/B]
            [B][COLOR=black][FONT=&quot]{                                [/FONT][/COLOR][/B]
            [B][COLOR=black][FONT=&quot]EnterShort([/FONT][/COLOR][/B][B][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot],[/FONT][/COLOR][/B][B][COLOR=purple][FONT=&quot]1[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot],[/FONT][/COLOR][/B][B][COLOR=maroon][FONT=&quot]""[/FONT][/COLOR][/B][B][COLOR=black][FONT=&quot]);[/FONT][/COLOR][/B]
            [B][COLOR=black][FONT=&quot]}[/FONT][/COLOR][/B][B][FONT=&quot][/FONT][/B]

          Comment


            #6
            Hello sburtt,

            Thank you for your response.

            This would work in backtesting and real-time, but is unnecessary in real-time if you use CalculateOnBarClose = False.

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X