Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reverse Trade When Stop Hit

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

    Reverse Trade When Stop Hit

    I'm using Strategy Builder. The stop is a set of conditions, not a hard stop. When the stop is hit, I would like the strategy to initiate a new position in the opposite direction with a different number of contracts, Profit Target and Stop Loss. Can you give me some ideas as to how I can set this up. Thank you.

    #2
    Hello Fran888,

    Thank you for your post.

    To reverse based specifically on the fill of the stop loss is not possible in the Strategy Builder as it would require manual coding. You would need to unlock the script and code the logic by hand.

    For the detection of an order execution, you can look for the order name of your stop loss in OnExecutionUpdate().



    Here is an example of code that detects and prints what the order is:

    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (execution.Name == "Stop loss")
    Print(string.Format("{0} - Stop loss was filled", execution.Time));
    }
    You can use the above code to test the detection out as it will send the print statements to the output window (New > NinjaScript Output).

    With the above code you can then add logic to your code to then enter an opposite direction order from within OnExecutionUpdate() if the filled order was a stop loss.

    Please let us know if we may be of further assistance to you.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    79 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X