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 JTizz, Today, 03:32 PM
    1 response
    35 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by ebaydan777, Today, 02:41 PM
    1 response
    28 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by aligator, Today, 02:28 PM
    1 response
    27 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by daniel_weber8, Today, 01:21 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChristopherS  
    Started by jungsoohuh, Today, 12:07 PM
    1 response
    35 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Working...
    X