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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X