• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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

    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Johnny Santiago, Today, 12:30 PM
    6 responses
    17 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by ttodua, Today, 12:26 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by dastaan, 06-26-2020, 04:33 AM
    6 responses
    108 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by RumHam, Today, 12:14 PM
    0 responses
    8 views
    0 likes
    Last Post RumHam
    by RumHam
     
    Started by Lancer, Today, 12:12 PM
    2 responses
    13 views
    0 likes
    Last Post Lancer
    by Lancer
     
    Working...
    X