Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Move stop

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

    Move stop

    How do I move the stop to 100 profitable if my trade is profitable 300

    if Position.GetUnrealizedProfitLoss(PerformanceUnit.P oints, Close[0]) > ProfitToMoveStop)
    {

    ExitLong ( "Move B/E" ) NumberOfContracts Contracts next bar at OpenPrice + MSP Stop;

    }​

    How do I label my exits? MSP is $100 for NQ 20*5

    #2
    Well, you say you want to MOVE the stop implying you have one initially - how did you place the stop in the first place? It wouldn't be with that sort of ExitLong statement because that looks like some sort of hodge podge of TradeStation EasyLanguage not NinjaTrader NinjaScript. However your strategy placed the initial stop, you would do that again but modify the price or distance.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hi I set the initial stop loss with

      SetStopLoss("", CalculationMode.Currency, 5000, false);

      Then move it later with this

      SetStopLoss(CalculationMode.Currency, 100);

      Does this move the stop loss to $100 profitable?

      Comment


        #4
        No, it moves the stop to $100 loss.

        You could try -100.00 or specify it by price e.g. SetStopLoss("", CalculationMode.Price, Position.AveragePrice - (100.00 / Instrument.MasterInstrument.PointValue / Math.Max(1, Position.Quantity)), false); // long example

        I would encourage you to use the same signature for the SetStopLoss command each time - if you don't you run the risk you might accidentally end up with two different stops going on (one for the whole thing and one for the specific entry you specified, although you sent an empty string here).
        Last edited by QuantKey_Bruce; 05-21-2023, 02:54 PM.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Hello RMin101,

          Thanks for your post.

          QuantKey_Bruce is correct. SetStopLoss(CalculationMode.Currency, 100) would move the stop to a $100 loss. You could specify the stop loss by Price instead of by Currency as Bruce shared.

          You should specify a fromEntrySignal string each time you call SetStopLoss() to ensure the stop loss is tied to the specific entry with that signal name. Otherwise, as Bruce noted you could end up placing two separate stops.

          Note that if you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position. This is noted on the SetStopLoss() help guide page linked below.

          SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm

          We have a reference sample you could view demonstrating modifying the price of a stop loss: https://ninjatrader.com/support/help..._lo.htm​
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            I have a question which is sort of related. Its more about understanding the API for Position.GetUnrealizedProfitLoss() with Points.

            I am trying to understand how PerformanceUnit.Points work as I plan to use it in my strategy and want to make sure I understand the concept correctly.
            I read the page for calculation modes https://ninjatrader.com/support/help..._and_loss_calc ulation_modes.htm and wanted to make sure

            Let's say I am trading ES and here is a hypothetical example where my strategy goes long or short with 1 lot and let's say I want to exit the trade if it goes more than a point against me.
            In this case would the code below be correct given that in the description of calculation modes URL above it says "1 for Long position, or -1 for short position"


            if (Position.MarketPosition == MarketPosition.Long && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Points, Close[0]) < -1))
            ExitLong();
            if (Position.MarketPosition == MarketPosition.Short && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Points, Close[0]) > 1))
            ExitShort();​

            If the code snippet above doesn't look correct what would be the correct approach? Thanks in advance.
            Last edited by vpatanka; 08-30-2023, 11:12 PM.

            Comment


              #7
              Hello vpatanka,

              Thanks for your notes.

              That help guide page details how the Calculation Mode called Points is calculated in NinjaTrader.

              Your understanding and the code you shared is correct. When using GetUnrealizedProfitLoss() with PerformanceUnit.Points, this will return the unrealized PnL in Points.

              This means if you are in a Long position and the strategy goes 1 point against you, the Position.GetUnrealizedProfitLoss(PerformanceUnit.P oints, Close[0]) method would return a value of -1.

              The first section of code would check if you are in a long position and if the Unrealized PnL is less than -1 point against you and calls ExitLong() to exit the position.

              The second section of code would check if you are in a short position and if the Unrealized PnL is greater than 1 point against you and calls ExitShort() to exit the position.





              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment


                #8
                Originally posted by NinjaTrader_BrandonH View Post
                Hello vpatanka,

                Thanks for your notes.

                That help guide page details how the Calculation Mode called Points is calculated in NinjaTrader.

                Your understanding and the code you shared is correct. When using GetUnrealizedProfitLoss() with PerformanceUnit.Points, this will return the unrealized PnL in Points.

                This means if you are in a Long position and the strategy goes 1 point against you, the Position.GetUnrealizedProfitLoss(PerformanceUnit.P oints, Close[0]) method would return a value of -1.

                The first section of code would check if you are in a long position and if the Unrealized PnL is less than -1 point against you and calls ExitLong() to exit the position.

                The second section of code would check if you are in a short position and if the Unrealized PnL is greater than 1 point against you and calls ExitShort() to exit the position.




                Thanks Brandon for the confirmation. Appreciate it. You guys are awesome !

                Comment


                  #9
                  Originally posted by NinjaTrader_BrandonH View Post
                  Hello vpatanka,

                  Thanks for your notes.

                  That help guide page details how the Calculation Mode called Points is calculated in NinjaTrader.

                  Your understanding and the code you shared is correct. When using GetUnrealizedProfitLoss() with PerformanceUnit.Points, this will return the unrealized PnL in Points.

                  This means if you are in a Long position and the strategy goes 1 point against you, the Position.GetUnrealizedProfitLoss(PerformanceUnit.P oints, Close[0]) method would return a value of -1.

                  The first section of code would check if you are in a long position and if the Unrealized PnL is less than -1 point against you and calls ExitLong() to exit the position.

                  The second section of code would check if you are in a short position and if the Unrealized PnL is greater than 1 point against you and calls ExitShort() to exit the position.




                  Hi Brandon,

                  A quick follow up - Does GetUnrealizedProfitLoss() with Points option work with a double meaning say if I am trading ES with 1 lot and if my criteria is half a point (instead of 1 point) or 2 ticks can I still use PerformanceUnit with points or do I have to use ticks

                  e.g. for half a point threshold can I do something like below

                  if (Position.MarketPosition == MarketPosition.Long && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Points, Close[0]) < -0.5))
                  ExitLong();​

                  or do I need to use PerformanceUnit.Ticks with 2?

                  Thanks in advance

                  Comment


                    #10
                    Hello vpatanka,

                    With CalculationMode Ticks or Points, this would be a distance regardless of number of contracts.

                    With CalculationMode.Currency this would be an amount of loss (or profit) with all of the contracts.

                    So you could use .5 points if you wanted, or for the ES you could use 2 ticks. Either would be the same.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello vpatanka,

                      With CalculationMode Ticks or Points, this would be a distance regardless of number of contracts.

                      With CalculationMode.Currency this would be an amount of loss (or profit) with all of the contracts.

                      So you could use .5 points if you wanted, or for the ES you could use 2 ticks. Either would be the same.
                      Thanks. I will try it out.

                      Comment


                        #12
                        Originally posted by vpatanka View Post

                        Thanks. I will try it out.
                        Okay so I just tried out running backtest for today (for ES with 1 lot) for my strategy in strategy analyzer with GetUnrealizedProfitLoss() with Points and Currency and was expecting the same result but I got two different results so I am not sure what I am missing here.

                        Here is the code I ran for 9/1/2023 for ES with 1 lot with 1 point as the threshold. I am using a 4 min chart
                        if (Position.MarketPosition == MarketPosition.Short && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Points, Close[0]) > 1))
                        ExitShort();

                        It showed one trade with a net loss of -$241.68


                        Click image for larger version  Name:	Points.png Views:	0 Size:	96.0 KB ID:	1267183


                        When I changed it to Currency for the exact same thing it showed a net loss of -$166.68
                        if (Position.MarketPosition == MarketPosition.Short && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]) < -50))​​
                        ExitShort();

                        Click image for larger version  Name:	Currency.png Views:	0 Size:	95.6 KB ID:	1267184
                        Here is a screenshot where it shows the entry time being the same but exit time was different between the two causing different P&L
                        Click image for larger version  Name:	CurrencyTrade.png Views:	0 Size:	70.8 KB ID:	1267186Click image for larger version  Name:	PointsTrade.png Views:	0 Size:	67.4 KB ID:	1267187



                        Can you help me understand what I am missing here. Thanks
                        Last edited by vpatanka; 09-01-2023, 02:39 PM.

                        Comment


                          #13
                          Originally posted by vpatanka View Post

                          Okay so I just tried out running backtest for today (for ES with 1 lot) for my strategy in strategy analyzer with GetUnrealizedProfitLoss() with Points and Currency and was expecting the same result but I got two different results so I am not sure what I am missing here.

                          Here is the code I ran for 9/1/2023 for ES with 1 lot with 1 point as the threshold. I am using a 4 min chart
                          if (Position.MarketPosition == MarketPosition.Short && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Points, Close[0]) > 1))
                          ExitShort();

                          It showed one trade with a net loss of -$241.68


                          Click image for larger version Name:	Points.png Views:	0 Size:	96.0 KB ID:	1267183


                          When I changed it to Currency for the exact same thing it showed a net loss of -$166.68
                          if (Position.MarketPosition == MarketPosition.Short && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]) < -50))​​
                          ExitShort();

                          Click image for larger version Name:	Currency.png Views:	0 Size:	95.6 KB ID:	1267184
                          Here is a screenshot where it shows the entry time being the same but exit time was different between the two causing different P&L
                          Click image for larger version Name:	CurrencyTrade.png Views:	0 Size:	70.8 KB ID:	1267186Click image for larger version Name:	PointsTrade.png Views:	0 Size:	67.4 KB ID:	1267187



                          Can you help me understand what I am missing here. Thanks

                          I ran the strategy in market replay with some Print() statements and figured out what the issue was regarding what I was trying to do.

                          It turns out Position.GetUnrealizedProfitLoss(PerformanceUnit.P oints, Close[0]) returns a -ve if the trade goes against the direction of the trade so it's agnostic to MarketPosition.<> which was not my understanding. I thought if I am long and if it goes against me by a point the function would return -1 and if I am short the function would return 1 if the position goes against me by a point but when I ran it in market replay it returned -1 when the position goes against me for both long and short.

                          Anyway good learning. Thanks

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Yesterday, 05:17 AM
                          0 responses
                          55 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          132 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          73 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          45 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          49 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X