multiple time frame backtesting

Questions about MultiCharts and user contributed studies.
kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

multiple time frame backtesting

Postby kernel » 11 Mar 2015

I tried to get a backtest on multiple time frame to work but failed. The idea was pretty straightforward as follows:

1m script is a signal script, keeping monitoring message sent by the 5m script, which is an indicator and sends a message to global space via GVsetNamedInt/GVgetNamedInt function pair.

If 5m sees a bullbar in a 5m chart, it sets a named value string "B5" to 1, likewise, if it sees a bearbar, it sets "S5" to 1. Otherwise, both are set to 0.

entry signal:
1m keeps pulling these two named values from global space, if it sees a bullbar in a 1m chart and also gets B5=1, a buy order is issued; if it sees a bearbar and gets S5=1, a shortsell order is issued.

exit signal:
exit on reverse entry signal.

Intraordergeneration set to be TRUE in both scripts.

5m indicator:

Code: Select all

[IntraBarOrderGeneration = true]


if C-O>0 then begin
GVSetNamedInt("B5",1);
end
else begin
GVSetNamedInt("B5",0);
end;


if O-C>0 then begin
GVSetNamedInt("S5",1);
end
else begin
GVSetNamedInt("S5",0);
end;


1m signal script:

Code: Select all

[IntraBarOrderGeneration = true]

B5sig=GVGetNamedInt("B5",-999);
S5sig=GVGetNamedInt("S5",-999);

if tradingtime and B5sig=1 then begin
if marketposition=0 and C-O>0 then
buy 1 contract next bar at market;
if marketposition=-1 then
buytocover 1 contract next bar at market;
end;

if tradingtime and S5sig=1 then begin
if marketposition=0 and O-C>0 then
sellshort 1 contract next bar at market;
if marketposition=1 then
sell 1 contract next bar at market;
end;
Load the 1m script and the 5m script to 1m and 5m chart respectively.

With such a loose entry condition, I was expecting many trades on backtesting. However, none was observed. More perplexing, it worked on replay mode and realtime. Anyone has any clue? thanks.

-K

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: multiple time frame backtesting

Postby tony » 11 Mar 2015

If you are backtesting on multiple data series (multiple being greater than 1) I believe it won't work properly. It's a limitation of MC. I signal off Data1 and use Data2 and Data3 as part of my conditionals for a signal, but in backtesting, it will not function properly.

It works perfectly fine in live and replay mode, but not in backtesting. MC seems to retroactively look at a conditional once the bar closes on Data2, Data3, DataN, etc. It may be near impossible from a calculation standpoint to back test by running the script for every single tick on every single data series over an extended period of time.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: multiple time frame backtesting

Postby kernel » 11 Mar 2015

If you are backtesting on multiple data series (multiple being greater than 1) I believe it won't work properly. It's a limitation of MC. I signal off Data1 and use Data2 and Data3 as part of my conditionals for a signal, but in backtesting, it will not function properly.

It works perfectly fine in live and replay mode, but not in backtesting. MC seems to retroactively look at a conditional once the bar closes on Data2, Data3, DataN, etc. It may be near impossible from a calculation standpoint to back test by running the script for every single tick on every single data series over an extended period of time.
Have you tried multiple charts instead of multiple data series in a single chart? Does it make any difference? I'm trying the former.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: multiple time frame backtesting

Postby tony » 11 Mar 2015

I have 3 charts in my WS. The first is Data1, the second Data2, third Data3. Each has a different bar duration (20, 5, 1). So I believe I am doing what you are asking. I don't have 3 data series in one chart, not sure that can be done or not. But side tracking.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: multiple time frame backtesting

Postby kernel » 11 Mar 2015

I have 3 charts in my WS. The first is Data1, the second Data2, third Data3. Each has a different bar duration (20, 5, 1). So I believe I am doing what you are asking. I don't have 3 data series in one chart, not sure that can be done or not. But side tracking.
Do you access other data series by quoting "of data2", "of data3" or GVsetNamedXXX/GVgetNamed function pair?

Was IntraBarorderGeneration set to TRUE or False in your scripts?

not sure if these would make any difference.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: multiple time frame backtesting

Postby tony » 11 Mar 2015

I do reference data series like "if close > var1 of Data2" and I am using IOG mode. Perhaps a moderator will highlight something I am missing. But I did spend a bit of time over a year ago understanding this issue as it relates to back testing. And I believe it's a limitation. And again, it may be too much of a resource draw to recalc on every tick on every data series for an extended period, not sure why.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: multiple time frame backtesting

Postby kernel » 11 Mar 2015

I do reference data series like "if close > var1 of Data2" and I am using IOG mode. Perhaps a moderator will highlight something I am missing. But I did spend a bit of time over a year ago understanding this issue as it relates to back testing. And I believe it's a limitation. And again, it may be too much of a resource draw to recalc on every tick on every data series for an extended period, not sure why.
I used GVSetNamedInt/GVGetNamedInt function pair, and found that the value set in 5m script didn't get passed out to 1m script in time before it got reset to zero again. It seemed to me like a synchronization issue, so I played with RecalcLastBarAfter(N) in both scripts, tweaking N a bit to see if I'd get any luck...unfortunately, no.

I agree with you on the resource barrier it has to overcome on tick-based backtesting.

Maybe a Moderator may shed some light on this issue? thanks.


Return to “MultiCharts”