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:
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.
SetProfitTarget(@"", CalculationMode.Ticks, ProfitTarget);
3. I also have the stop loss defined in State == State.DataLoaded, this does not execute.
SetStopLoss(@"", CalculationMode.Price, LongSL, false);
4. When the entry conditions are met I place a long order for a user-defined QTY of contracts:
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.
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

Comment