i want to backtest strategy with two different timeframe:
- 5 m : where the indicator is calcultate
- 1 tick: where the entry is done
so, the entry is not a problem becuse the strategy enter wehn the condicion is true but the problem is stop loss: becuase it is not calculate by tick.
For exemple: if price open at 10 and wehen price go to 6 strategy open a position with SL and TP = 3 pt. in these case (for exemple the price start at 10, go to 6, go to 2 (stop loss hit) and return on 9) the strategy inicate take profit and not a stop loss, when the stop loss was hitten befaore take profit.
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Tick, 1);
Calculate = Calculate.OnEachTick;
}
if (BarsInProgress == 0){
emaValue = EMA(Closes[0], Period)[0];
emaSeries[0] = emaValue;
smaUP = emaValue * (1+scost);
emaIncreasedSeries[0] = smaUP;
smaDW = emaValue * (1-scost);
emaDecreasedSeries[0] = smaDW;
Values[0][0] = emaSeries[0];
Values[1][0] = emaIncreasedSeries[0];
Values[2][0] = emaDecreasedSeries[0];
}
if (BarsInProgress == 1){
if (Closes[1][0] < emaValue) {
CondicionSell2 = 1;
}
if (Closes[1][0] > emaValue) {
CondicionBuy2 = 1;
}
if (Closes[1][0] >= smaUP && CondicionSell2==1){
EnterShort(lots, "sell");
SetStopLoss(CalculationMode.Pips, pipstoploss); // Stop loss di 10 pips
SetProfitTarget("sell", CalculationMode.Pips, piptakeprofit); // Take profit di 12 pips
CondicionSell2 = 0;
}
if (Closes[1][0] <= smaDW && CondicionBuy2==1){
// Calcola la dimensione della posizione, ad esempio con una fissa percentuale dell'equità
// Apri una posizione di vendita e imposta stop loss e take profit
EnterLong(lots, "buy");
SetStopLoss(CalculationMode.Pips, pipstoploss); // Stop loss di 10 pips
SetProfitTarget("buy", CalculationMode.Pips, piptakeprofit); // Take profit di 12 pips
CondicionBuy2 = 0;
}

Comment