• 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 buick, Today, 09:37 PM
    0 responses
    4 views
    0 likes
    Last Post buick
    by buick
     
    Started by Hagar, Today, 07:12 PM
    0 responses
    6 views
    0 likes
    Last Post Hagar
    by Hagar
     
    Started by jtrading82, Today, 01:55 PM
    4 responses
    28 views
    0 likes
    Last Post bppayne
    by bppayne
     
    Started by Hagar, Today, 06:52 PM
    0 responses
    4 views
    0 likes
    Last Post Hagar
    by Hagar
     
    Started by vivekniwas, Today, 04:56 PM
    0 responses
    7 views
    0 likes
    Last Post vivekniwas  
    Working...
    X