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

Strategy reverse position fills profit target

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

    Strategy reverse position fills profit target

    I have a strategy that uses the following code every time it is triggered in one direction or the other.
    Code:
    SetStopLoss(order1Name, CalculationMode.Ticks, 50, false);
    SetProfitTarget(order1Name, CalculationMode.Ticks, 50);
    EnterLong(Convert.ToInt32(TargetSize), order1Name);
    ... or it uses EnterShort() to go short. The documentation says that NT8 will effectively reverse the position if the opposite Enter* order is called. This works sometimes, and sometimes it will fill the profit target order immediately.

    See the attached CSV document with the data from the Orders window. See that transition from 1:00 and the orders at 1:09 where the problem happened. Also, it is not shown in the CSV format, but the orders at the same minute mark (like 1:09) all happen at the same second (it happens fast). There's one Sell Short at 1:09 and then immediately the Profit Target is filled, however, the price is nowhere near the profit target.

    Note, the immediate close of the position (profit target) happens intermittently, not always. How can I fix this or is there a cleaner way to reverse a position with stop loss and profit target orders?

    If the above code was used to enter a position, then when the strategy is triggered again, for example, the following code would reverse that position:
    Code:
    SetStopLoss(order1Name, CalculationMode.Ticks, 50, false);
    SetProfitTarget(order1Name, CalculationMode.Ticks, 50);
    EnterShort(Convert.ToInt32(TargetSize), order1Name);
    Also note, it uses the same order name.

    #2
    Hi bfalls, thanks for posting.

    Make sure you are giving a unique signal name to each entry signal so they can be targeted by their own SetStopLoss/SetProfitTarget methods. Make sure the long order has a signal name different from order1Name.

    For a more consistent reversal behavior, it would be best to set up a bool variable "WaitingForCancel" set to true when the position needs to reverse. Then check in OnOrderUpdate if the stop and target are in State.Canceled and WaitingForCancel == true, then reverse using EnterLong/EnterShort.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    26 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, Yesterday, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    192 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,234 views
    0 likes
    Last Post xiinteractive  
    Working...
    X