How do you back test a multi time frame strategy.

To add comments, please log in or register
Bill Morris
287
Bill Morris  

I'm just finishing my first ea based on a multi time frame strategy. It looks at the 4 hour trend, but uses the 15 minute chart to trigger the order.

Obviously if the 4 hour trend reverses during the 1st 15 minutes, I'm using a bad trend to trigger orders because the system can't tell when the trend reversed.

The only thing I can think of is to copy the 4 hour buffer into another array and replace the appropriate bar with the accumulated data from the 15 minute data bars for each 4 hour period and then use that array for the calculations.

What other choice is there?

Is there a way to use the 1 minute charts to test this kind of strategy?

Bill Morris
287
Bill Morris  
FoxGuy:

I'm just finishing my first ea based on a multi time frame strategy. It looks at the 4 hour trend, but uses the 15 minute chart to trigger the order.

Obviously if the 4 hour trend reverses during the 1st 15 minutes, I'm using a bad trend to trigger orders because the system can't tell when the trend reversed.

The only thing I can think of is to copy the 4 hour buffer into another array and replace the appropriate bar with the accumulated data from the 15 minute data bars for each 4 hour period and then use that array for the calculations.

What other choice is there?

Is there a way to use the 1 minute charts to test this kind of strategy?

bump
William Roeder
18684
William Roeder  
FoxGuy:

I'm just finishing my first ea based on a multi time frame strategy. It looks at the 4 hour trend, but uses the 15 minute chart to trigger the order.

Obviously if the 4 hour trend reverses during the 1st 15 minutes, I'm using a bad trend to trigger orders because the system can't tell when the trend reversed.

Run on the 15 minute chart using Time[], Close[] etc. Loot at 4 hour chart with iTime(NULL, PERIOD_H4, ...), iClose(), iCustom(NULL, PERIOD_H4, ...) etc.

In the tester you can NOT get bar zero data for other timeframes, don't use iTime(NULL, PERIOD_H4, 0)

If the "4 hour trend reverses during the first 15 minutes," then you are NOT using the 4 hour as a multi time frame strategy. You are using a 15 minute trend.

If you want a multi time frame strategy, use the 15 minute chart and only open if the direction agrees with the higher TF direction.

Bill Morris
287
Bill Morris  
WHRoeder:

Run on the 15 minute chart using Time[], Close[] etc. Loot at 4 hour chart with iTime(NULL, PERIOD_H4, ...), iClose(), iCustom(NULL, PERIOD_H4, ...) etc.

In the tester you can NOT get bar zero data for other timeframes, don't use iTime(NULL, PERIOD_H4, 0)

If the "4 hour trend reverses during the first 15 minutes," then you are NOT using the 4 hour as a multi time frame strategy. You are using a 15 minute trend.

If you want a multi time frame strategy, use the 15 minute chart and only open if the direction agrees with the higher TF direction.

I think you missed my point, or I missed your point. I'm running the EA on a 15 minute chart, but since I'm looking for a MA cross to trigger the trade, and I can only see the close of the 4 hour chart the only time that I will trade is when a cross occurs on a 4 hour break.

Example: The 4 hour trend turns positive at 00:07, but my EA only has access to the 4 hour bar that closed at 00:00 or 04:00. If my EA shows a cross at 00:15 do I look at the 4 hour 00:00 bar to see what the trend is or the 4 hour 04:00 bar? Either one can be wrong because the trend changed part way through the bar. The only time I can safely trust that it's correct is if my cross occurs at 00:00 or 04:00. In real time I will be able to confirm the 4 hour trend before executing the order by opening the 4 hour chart. I can't do that in the tester, so there are going to be an awful lot of "missed" trades. 15 out of every 16 "possible" trades will be missed, because I can't tell what the 4 hour trend is.

Ubzen
5298
Ubzen  

So then use the 4-Hour TimeFrame for testing and Hard-Code the 15-Mins TimeFrame. If you require something within the 15-Minutes TimeFrame which requires 0-Bar information then you're have to decide your priorities. Put simply, the strategy tester has limitations.

Bill Morris
287
Bill Morris  
ubzen:

So then use the 4-Hour TimeFrame for testing and Hard-Code the 15-Mins TimeFrame. If you require something within the 15-Minutes TimeFrame which requires 0-Bar information then you're have to decide your priorities. Put simply, the strategy tester has limitations.

I think you missed my point, or I missed your point.

I want to see how many trades would occur during a specified time frame. If all the signals show trades at 00:15 and then again at 03:45 I want to see 2 trades. I assume that I need to work off the 15 minute chart to see 2 trades during that 4 hour period.

But the 4 hour trend might have changed at 01:45, so 1 of the trades would be wrong because they would both be working off the same 4 hour calculation.

I can only think of one way to do that (but I'm new to MT4). Work off the 15 minute chart, but plug the accumulated 15 minute #s into an array and calculate the 4 hour trend from arrays (for example: iMAOnArray() instead if iMA()). During the 4 hour period the EA would plug 16 different #s into the 4 hour array and recalculate. That means writing a custom indicator that will only be used for testing. Bar 0 does that automatically during real time.

That seems like a lot of work just to test the strategy. So before I write a custom indicator for all the indicators that I want to use I would like to find out if there is a different way to accomplish what I want.

Assuming that there is no other way to get what I want, I would like to know if my idea would even work. I can't be the first one to come across this problem, so I assume others have thought of the same thing. Hopefully one of those people will tell me where I'm right or wrong.

Ubzen
5298
Ubzen  

Download Tick charts, Hard code the rest of your indicator Time-frame as suggested by WHRoeder. Then run it on M1-Timeframe. Start Here.

Here's the response I really wanted to give. "Hey man, you're having a 0-bar Issue. The very fact that it works on Live chats the way you want but not within the back-tester should validate the problem for you. The way we get around 0-bar issues around here is by not using 0_bar but rather bar_1 instead. If you wanna re-array 1-minutes time-frames be my guest, in the end, you'll still be 1-Minute off_from_reality."

Ps- If your strategy depends on scalping (takeprofit or stoploss) within 10-Pips then mt4 1-Minute data would not serve you well. The wider your values the more accurate the tester will serve you in default 1-minute data.

Bill Morris
287
Bill Morris  
ubzen:

Download Tick charts, Hard code the rest of your indicator Time-frame as suggested by WHRoeder. Then run it on M1-Timeframe. Start Here.

Here's the response I really wanted to give. "Hey man, you're having a 0-bar Issue. The very fact that it works on Live chats the way you want but not within the back-tester should validate the problem for you. The way we get around 0-bar issues around here is by not using 0_bar but rather bar_1 instead. If you wanna re-array 1-minutes time-frames be my guest, in the end, you'll still be 1-Minute off_from_reality."

Ps- If your strategy depends on scalping (takeprofit or stoploss) within 10-Pips then mt4 1-Minute data would not serve you well. The wider your values the more accurate the tester will serve you in default 1-minute data.

I'm going to read you link, but in the mean time:

I don't understand why you think it's a 0-bar issue. My indicator works fine at the 0-bar. I want to back-test the EA it to see how profitable or unprofitable it is.

At the 0-bar, the 4 hour trend gets recalculated with every tick. So I may get a buy trigger on the 15 minute chart at 00:15 when the 4 hour trend is up, but then when the 4 hour trend turns down at 01:45 the 4 hour trend gets recalculated at the next tick so I may get a sell trigger at 03:45 and the buy trigger at 02:30 gets ignored because the 4 hour trend is down at that point.

The point is that the 4 hour trend keeps getting recalculated during the 15 minute 0-bars, but it doesn't get recalculated during every bar earlier than the 4 hour 1-bar.

Ubzen
5298
Ubzen  
Show your code and some pictures.
Bill Morris
287
Bill Morris  
ubzen:
Show your code and some pictures.

Now I'm really confused. What's the point in showing my calculations? It calculates just fine. I'm trying to figure out how to back test it.

I have started reading more about back testing, and maybe I have the wrong idea of how it works.

I run it on a 15 minute chart. When it's working on bar 200 (say it is 2001.09.01 01:00) my indicator wants to calculate the 4 hour trend as it would have been when TimeCurrent() was 2001.09.01 01:00. Does it do that automatically?

IOW at 01:00 the 4 hour bar close=1.40000, but at 04:00 the 4 hour bar close=1.75500, so at 01:00 does the tester use 1.40000 or 1.75500 to calculate the 4 hour trend? If it uses 1.40000 then that solves my problem. I have been assuming that it used 1.75500 (00:00 bar) for every 15 minute bar between 00:00-04:00.

IOW does the tester use the 15 minute history files to calculate the 4 hour trend, or does it use the 4 hour history files to calculate the 4 hour trend?

Ubzen
5298
Ubzen  

You're making too many assumptions friend. I'll strongly recommend the mql4.com book to begin with. My guess is because you're new, you're getting very confused.

1) To calculate the LAST 4-hour trend using moving averages on a 15-Minutes chart, all it needs is 16-Bars and not 200.

2) The back-tester does-Not look into the future while it's processing the current bar. In your example at 01:00 it'll look at Only the 01:00 bar and earlier 200 bars which are at the Left side of it.

3) IOW does the tester use the 15 minute history files to calculate the 4 hour trend, or does it use the 4 hour history files to calculate the 4 hour trend? Take this question for example, it makes no sense. This is why you have to show your code. Because the answer is any. It could use 15-Minutes or 4-Hours or 1-Minutes for that matter of fact.

You're guessing that we know what you're talking about. And I for one don't have a clue.

12
To add comments, please log in or register