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

Breakeven for trade 1 after profit target is hit for trade 2 is hit

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

    Breakeven for trade 1 after profit target is hit for trade 2 is hit

    Hello,

    I have looked at all the code examples found through others post but what i am looking to code is slightly different, so I am hoping it is not too difficult for me to do myself.

    If I have two trades going. I have set ticks I would like to exit for profit target and stop loss. My goal is to test and see how it would impact my strategy by adding this piece of breakeven in to see if has any true value.
    Both: Enter off the same entry
    Trade 1: Exits 160 ticks profit or 65 ticks stop loss
    Trade 2: Exits 40 ticks profit or 65 ticks stop loss

    This is the logic I am thinking: If Trade 1 is in trade and trade 2 has exited trade only through its profit target, move the stop loss of trade 1 to average position price + 2 ticks.

    Any insight would be greatly appreciated. If this could cause issues in an automated code, I might just have to forget it.

    #2
    Hello durdcash,

    Thanks for your post.

    You could consider detecting when the order you want to know was hit is filled and then implementing your breakeven logic in OnExecutionUpdate() to change the price of your stop loss.

    You could track what price the first profit target order is submitted to within a variable, create a condition to check and see if the current Close price is greater than that variable, and add your breakeven logic within that condition to move the stop loss.

    See the reference sample linked below from the NinjaTrader help guide demonstrating using OnOrderUpdate() and OnExecutionUpdate() methods to submit protective orders.

    https://ninjatrader.com/support/help...and_onexec.htm

    And, see the help guide documentation below.
    OnExecutionUpdate: https://ninjatrader.com/support/help...tionupdate.htm
    OnOrderUpdate: https://ninjatrader.com/support/help...rderupdate.htm

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,967 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    4 views
    0 likes
    Last Post rbeckmann05  
    Started by rhyminkevin, Today, 04:58 PM
    4 responses
    55 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by iceman2018, Today, 05:07 PM
    0 responses
    6 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    8 views
    0 likes
    Last Post lightsun47  
    Working...
    X