Different BarPeriods

Posted By: tickserver

Different BarPeriods - 05/12/23 21:08

Hi,
I have a binary-option strategy that works quite well with BarPeriod=120. The problem is that run() is running now only at 0, 2, 4, 6... o'clock and I am missing additional trade opportunities at the full hours in between (1, 3, 5, ... o'clock).
I get the desired behavior by running my backtest once with BarOffset=0 and a second time with BarOffset=60. but I cannot find a way to put it together in one test-run.
I understand that changing BarOffset in run()-method does not work.
Next thing I tried was using BarPeriod=60 with TimeFrame=2 but this yields very different results (and even the documentation states that "...BarPeriod 60 and TimeFrame 1 is not the same as a script with BarPeriod 1 and TimeFrame 60...")

Any idea how to run a strategy based on H2-candles every hour (not only every 2 hours)?

Thx for your help!
Posted By: jcl

Re: Different BarPeriods - 05/15/23 13:46

You need two overlapping time frames. Use BarPeriod = 60 and don't set Timeframe, but shift your series by script in alternating hours.
Posted By: tickserver

Re: Different BarPeriods - 09/12/23 23:10

Thanks for your reply!
I followed you staying with BarPeriod = 60 but was not lucky with shifting my series.
The foilowing did the trick:

BarPeriod = 60;
TimeFrame = 2;
LifeTime = 4;
...
TimeFrame = 1;
enterShort();
TimeFrame = 2;

I basically switch to a shorter Timeframe just for when I enter my trade and switch back afterwards. Otherwise half of my trades would not be entered.
After lots of testing this seems to be proper workaround for what docu states: "Trades entered in the run function are not executed when the TimeFrame has not ended."
© 2024 lite-C Forums