I've created a strategy that uses ATR to set stoploss and take profit. In backtests, most trades are executed correctly, but sometimes it doesn't work.
I made a screenshot of a trade (short) to show you the problems (blue horizontal lines):
1. Stoploss (1,08822) was triggered but not executed
2. take profit (1,07922) is calculated wrong
To determine stoploss and take profit, I use the following code, written under "OnBarUpdate":
double profitTargetPriceShort = Close[0]-(ATR(ATRperiode)[0]*CRV*2);
double stopLossPriceShort = Close[0]+(ATR(ATRperiode)[0]*2);
if (...my conditions...)
{
EnterShortLimit(10000, Close[0], "");
SetProfitTarget(CalculationMode.Price, profitTargetPriceShort);
SetStopLoss(CalculationMode.Price, stopLossPriceShort);
}
"CRV" is just a multiplier to test different risk ratios, "ATRperiode" is a variable to test different periods of ATR indicator.
Hope you can help me,
Best Regards
Comment