I am having issues getting the SetStopLoss and SetProfitTarget to trigger exits. In this example, I have just used EMA with an ATR multiple for exits. When I print these values out, they are calculating correctly, but when the price moves above/below these, an exit is not triggered (either through Market Replay or backtest).
Here is my logic.Thanks for any help you can give me.
Kylie.
protectedoverridevoid Initialize()
{
Add(RSI(rsidays, 3));
SetProfitTarget("JB", CalculationMode.Price, profittarget);
SetStopLoss("JB", CalculationMode.Price, trailingstop, false);
CalculateOnBarClose = true;
}
protectedoverridevoid OnBarUpdate()
{
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Price, 0);
SetProfitTarget(CalculationMode.Price, 0);
}
elseif (Position.MarketPosition == MarketPosition.Long)
{
profittarget = EMA(ptemadays)[0]+2*ATR(atrdays)[0];
trailingstop = EMA(ptemadays)[0]-ATR(atrdays)[0];
SetStopLoss(CalculationMode.Price,trailingstop);
SetProfitTarget(CalculationMode.Price, profittarget);
}
if (MIN(RSI(rsidays, 3),20)[0] < rsitrigger
&& Close[0] > (MIN(Low, 20)[0]) + 2*ATR(atrdays)[0])
{
EnterLong(1, "JB");
}
}

Comment