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, 05-11-2026, 05:56 AM
    0 responses
    52 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    194 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    355 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    274 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X