Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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

    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by r68cervera, Today, 05:29 AM
    0 responses
    2 views
    0 likes
    Last Post r68cervera  
    Started by geddyisodin, Today, 05:20 AM
    0 responses
    3 views
    0 likes
    Last Post geddyisodin  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    6 responses
    33 views
    0 likes
    Last Post JonesJoker  
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,239 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    6 views
    0 likes
    Last Post AveryFlynn  
    Working...
    X