Testing strategy

I want to test the following strategy:

Using hourly candles, I want to generate a buy signal when price crosses EMA25 and closes below EMA25.

Buy takes place at the open of next hourly candle.

Stop loss and take profit takes place as soon as 20 pips are reached in any direction.

So basically I generate a buy signal using hourly candles but I want to exit the position using 1 minute candles.

How shall below code be modified to reflect this dual timeframe backtesting scenario?

Thanks,

EMA25 = EMA(Close, 25);

Price_cross_ema25 = (High > EMA25) AND (Low < EMA25);

Buy = Price_cross_ema25 AND (Close>EMA25);

ApplyStop(stopTypeProfit,
         stopModePoint,
         20,
         True );

ApplyStop(stopTypeLoss,
         stopModePoint,
         20,
         True );

You will want to run your backtest with the Periodicity set to 1 minute. The functions TimeFrameCompress() and TimeFrameExpand() will allow you to create hourly bars, generate the EMA, find the cross (use the Cross() function instead of your faulty logic in the example code), and then expand the entry signal back to 1-minute bars. Give it a try and then come back if you're still struggling.

1 Like

It is not necessary. The code should just have

Sell = False;

added and run on HOURLY interval.

Since he always exits only using ApplyStop() with exitAtStop = true, stops are triggered inside bar as soon as price reaches desired level regardless of data periodicity. Using 1-minute data would only be needed if he had regular exits (not via stop) or entries based on 1-minute data.

4 Likes

Good point @Tomasz, I didn't think about that.