Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetProfitTarget() and SetStopLoss() are executed without being called

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

    SetProfitTarget() and SetStopLoss() are executed without being called

    Hello NT Team,

    I use both SetProfitTarget() and SetStopLoss() to set my TP and SL levels, and each time one of them is reached, I IMMEDIATELY enter a new position based on what order was filled, BUT, for the NEW ENTRY, I need new TP and new SL levels to be re-calculated based on new market conditions, volatility ... but I see that the SetProfitTarget() and SetStopLoss() both keep the same initial values that were used at the beginning and they keep getting executed each time I have a new entry without updating the values according to my strategy.

    I try to force them to re-calculate by using both Set methods ONLY when certain conditions are met, but like my conditions are ignored, and they keep getting executed using the old initial values they got at the very beginning upon first strategy run.

    how to force them to re-calculate new values each time one of them is filled ?

    Thank you

    #2
    Hello MohammedAmine,

    Thanks for your post.

    As stated in the Notes section of the SetStopLoss() and SetProfitTarget() help guide documentation, Should you call this method to dynamically change the target price in the strategy OnBarUpdate() method, you should always reset the target price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your profit target order on your next open position

    Please see the attached example script demonstrating modifying the price of stop loss and profit target orders.

    Also, see the help guide documentation below for more information.
    SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
    SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm

    Let us know if we may assist further.
    Attached Files
    <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


      #3
      I'm using a button to disable the loop from running the stop and target calculation but it still resets them just like Mohammed indicated. My goal is to disable the loop so I can manually move the profit target.

      I suppose my loop is working however the stored values cause the reset. The price modification script wouldn't work since I want to manually adjust the profit target using chart trader to an zone that makes sense. That is difficult for me to program. Any suggestions other than disabling the Strategy itself?

      Comment


        #4
        Hello tak145,

        Thanks for your note.

        Something you could do if you want to be able to adjust your profit target manually would be to submit your entry orders with an Atm Strategy template attached.

        You could see an example of using ATM strategy methods by viewing the SampleAtmStrategy script that comes default with NinjaTrader. To view the script, open a New > NinjaScript Editor window, open the Strategies folder, and select the SampleAtmStrategy script.

        See the help guide documentation below for more information.

        Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm

        Let us know if we may assist further.
        <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


          #5
          I let my script control everything so I can set the initial stop just beyond a recent candle high or low while calculating how many contracts to trade. I'm happy with that since I can now risk a constant dollar amount no matter how far the entry is from my stop. I don't think that is possible with an ATM. Disabling the strategy is a sufficient solution but I can sometimes be too slow for a fast moving market.

          Comment


            #6
            Hello tak45,

            Thanks for your note.

            That is correct, you would not be able to set the initial stop just beyond the recent candle high or low while calculating how many contracts to trade when using ATM strategy methods.

            If you are dynamically calling Set methods such as SetStopLoss()/SetProfitTarget() in the OnBarUpdate() section of your script, you would need to make sure the reset the target price/offset value when your strategy is in a flat position (Position.MarketPosition == MarketPosition.Flat). Otherwise, the last price/offset value set will be used to generate your profit target order on your next open position. This is noted in the Notes section of the help guide documentation below.

            SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
            SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm
            Position.MarketPosition(): https://ninjatrader.com/support/help...etposition.htm

            Ultimately, To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

            In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in a NinjaScript Output window (New > NinjaScript Output).

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.
            https://ninjatrader.com/support/foru...121#post791121

            Please let me know if I may further assist
            <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

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            68 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X