Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss not executing

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

    SetStopLoss not executing

    Hi,

    I have a basic opening range breakout strategy where the maximum and minimum range of the breakout is defined at a given time. I have a pre-set profit target in ticks and I'd like to use the price value of the minimum range of the breakout as my stop loss for longs and the maximum range of the breakout as my stop loss for shorts.

    Unfortunately when I define SetStopLoss in the Strategy Builder the stop loss does not execute. Can you help?

    My code for at long trade is...

    1. At the end of the opening range at a given time the maximum and minimum prices of the range will be stored and the stop loss (LongSL - defined as a double variable) will be stored:

    Code:
    if (Times[0][0].TimeOfDay == TimePeriodEnd.TimeOfDay)
    {
    MaxORBprice = MAX1[0]; //where MAX1 = MAX(High,2) in State == State.DataLoaded
    MinORBprice = MIN1[0];//where MAX1 = MAX(High,2) in State == State.DataLoaded
    LongSL = MinORBprice;
    }

    2. The user-defined profit target (in ticks) is defined in State == State.DataLoaded, this executes as intended.

    Code:
    SetProfitTarget(@"", CalculationMode.Ticks, ProfitTarget);

    3. I also have the stop loss defined in State == State.DataLoaded, this does not execute.

    Code:
    SetStopLoss(@"", CalculationMode.Price, LongSL, false);

    4. When the entry conditions are met I place a long order for a user-defined QTY of contracts:

    Code:
    EnterLong(Convert.ToInt32(NumberOfContracts), @"");

    I have tried to debug this by using an actual price value of, say 13000 for NQ, and this executes as intended with the trade being stopped out at 13000.

    Code:
    SetStopLoss(@"", CalculationMode.Price, 13000, false);

    Do you have any ideas on why the stop loss isn't being executed?

    I have developed this in Strategy Builder but I can revert to NinjaScript if this is an issue with the Strategy Builder.

    Thanks,

    Neil
    Last edited by burtoninlondon; 06-24-2022, 05:40 AM.

    #2
    Apologies, just after I posted this query I realised my error and have resolved this query.

    I have unlocked the code and moved the SetStopLoss from State == State.DataLoaded into the opening range condition section, I realised the SetStopLoss in the State == State.DataLoaded was acting as a global variable executed and fixed before the conditions had defined the value of the stop loss.

    Thanks,

    Neil

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    48 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X