Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I tell when the StopLoss or ProfitTarget has been executed?

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

    How can I tell when the StopLoss or ProfitTarget has been executed?

    I had initially written my Strategy to execute code to close out the trade when requirements had been met.
    It easier and a bit cleaner to set the StopLoss/ProfitTarget. My issue is that I don't know when the StopLoss/ProfitTarget
    has been executed. I need to know how to determine that as I set a boolean to true when in a current trade and I
    need to reset that boolean to false once the trade closes. Since my code is not executing the close of the trade I
    I don't know when to reset it.

    Is there a signal, or something that I can track when the automatic StoppLoass/ProfitTarget has been executed?

    Any help would be greatly appreciated.

    #2
    Hello ATMtrader0001,

    Thanks for your post and welcome to the NinjaTrader forums!

    There are a couple of ways to check this.

    Perhaps the easiest would be to check to see if you are in a flat position. When you are in a long or short position and your profit target or stop are hit you would go from being long (or being short) to being in a flat position. if (Position.MarketPosition == MarketPosition.Flat) { // do something }
    Reference: https://ninjatrader.com/support/help...etposition.htm

    Note if you are using the strategy builder then you can heck the market position under the strategy folder of the condition builder. See, "How to create market position comparisons" here: https://ninjatrader.com/support/help...on_builder.htm

    If you are using a Ninjascript strategy, you could also check for the signal names in the OnExecutionUpdate() method: https://ninjatrader.com/support/help...tionupdate.htm If you add the example as shown in the link to your strategy you would then see what name prints on a per execution basis for an understanding and the modify to check for those names to trigger your action.

    Finally you can review the sample strategy "SampleMonitorStopProfit" which may give you further ideas: https://ninjatrader.com/support/help..._and_profi.htm

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 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