Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a SL, and 2 target profits.

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

    #31
    Referring to the TIp in SetStopLoss() "Should 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"

    What exactly mean to reset it, To which value? With Which Label? What I currently understand is that I always call it before submitting a new opening order.

    Also above is being suggested to consider Exit Methods instead, like "ExitLongStopMarket".
    Can I alter the stop level of the bracket created via SetStopLoss() later using ExitLongStopMarket() with the same fromEntrySignal of the SetStopLoss ?

    Thank you,
    Gio

    Comment


      #32
      Hello,


      What exactly mean to reset it, To which value? With Which Label?​
      It needs to be reset to the original value. The reference sample script SamplePriceModification demonstrates how to change the price of stop loss and profit target orders, including when to reset them:

      https://ninjatrader.com/support/helpGuides/nt8/modifying\_the\_price\_of\_stop\_lo.htm


      Can I alter the stop level of the bracket created via SetStopLoss() later using ExitLongStopMarket() with the same fromEntrySignal of the SetStopLoss ?
      ​​
      No, you cannot modify SetStopLoss() using ExitLongStopMarket(). These would be considered two separate orders.

      Comment


        #33
        Hi Gaby,

        I'm not sure if this question is relevant to to my thread so if not please let me know where to post it.

        I’m currently running into an issue with my strategy that works well in real-time but causes problems during backtesting in the Strategy Analyzer. Here’s the situation: Problem Overview:
        • My strategy involves placing trades with two profit targets, stop-loss adjustments, and breakeven logic. In live trading, I manage these using OnExecutionUpdate to dynamically handle stop-loss adjustments, partial exits, and moving stops to breakeven + pips.
        • I’ve used the State.Realtime condition in parts of my code to handle execution and position management for live trades.
        Issue During Backtesting:


        When I remove the State.Realtime condition to enable backtesting, the Strategy Analyzer runs into issues where:
        1. Partial trades or incorrect position sizes appear in historical data.
        2. Breakeven adjustments, stop-loss movements, and profit target hits are not simulated properly since these are handled in real-time with dynamic logic.
        What I Want to Achieve:
        1. Accurate Backtesting: I need my backtests to simulate the behavior of live trading as closely as possible, including proper handling of stop-loss, profit targets, and breakeven logic without relying on real-time execution conditions.
        2. Keep Real-Time Logic: I want to retain the real-time execution logic for live trading, but I’m not sure how to properly isolate it without affecting backtesting results.
        Key Questions:
        • How can I simulate my real-time order management logic (breakeven, stop-loss adjustments, etc.) accurately during backtesting, given that I rely on OnExecutionUpdate and dynamic position management in live trading?

        Any advice on structuring the strategy to accommodate both backtesting and live trading modes without losing accuracy would be greatly appreciated!

        Thank you for your help!

        Comment


          #34
          Thank you Gaby,
          looking at the example it is clear that the resetting stop when flat means to reset it to the desired default initial stop value.
          Gio

          Comment


            #35
            Hello Gio,

            Because a Set method cannot be unset, it will continue working with the previous value for all new orders. If the CalculationMode is set to Price, the stop loss price for the previous order may be an invalid price for the new order.

            Resetting this to a number of ticks, will ensure that the stop for the new order is submitted with a valid price.
            The number of ticks should be greater than 0. A stop placed with a distance of 0 ticks would be attempted to be submitted at the entry fill price the moment the entry fills, which if accepted the stop would immediately fill or it will be rejected due to not being below the bid for a sell or above the ask for a buytocover.

            In backtest, to have intra-bar actions, such as trailing when the price changes, 1-tick intra-bar granularity will need to be implemented and TickReplay enabled.


            Last, orders should not be assigned to order variables from the order method return object. These should be assigned to variables from OnOrderUpdate() only.

            Below is a link to an example named ProfitCasestopTrailExitOrdersExample that demonstrates and can be backtested.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            612 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            355 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
            561 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            564 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X