Download MetaTrader 5

Variable values blank in backtesting

To add comments, please log in or register
Leon Lodewyks
288
Leon Lodewyks  

Hi

Could anyone tell me why when I run the below in MT4 back testing, the EntryLevel and MA10 values are 0? When I attach the EA to the live chart, and I check the journal, it contains the correct values for EntryLevel and MA10, but when trying to back-test, it prints 0. It also contains the expected values when I debug.

Relevant extracts below, I do not use EntryLevel in any other part of the code other than for the below: 

Many thanks 

double MA10  = iMA(_Symbol,PERIOD_D1,10,1,MODE_EMA,PRICE_CLOSE,1);

double EntryLevel =  NormalizeDouble(MA10,Digits);

Print("EntryLevel: " + EntryLevel);

         Print("MA10 Level: " + MA10);


if( (Bid >= EntryLevel - 0.00100) && (Bid <= EntryLevel)

Marco vd Heijden
Moderator
5667
Marco vd Heijden  

Are you sure that the historic data from at least the last eleven days is present ? before the indicator can give average reading.

Can you print OHLC values for these days?

Leon Lodewyks
288
Leon Lodewyks  
Marco vd Heijden:

Are you sure that the historic data from at least the last eleven days is present ? before the indicator can give average reading.

Can you print OHLC values for these days?

Hi Marco

Yep, I have downloaded 99.9% tick data back to 1st Jan 2015 so there is roughly 505 days worth of data. 

Leon Lodewyks
288
Leon Lodewyks  
Leon Lodewyks:

Hi Marco

Yep, I have downloaded 99.9% tick data back to 1st Jan 2015 so there is roughly 505 days worth of data. 

I actually think you have a point Marco. I just changed the test period to start on 1st Jan 2016 and it does now produce a value. Thanks very much.
Fernando Carreiro
2958
Fernando Carreiro  
Leon Lodewyks: Yep, I have downloaded 99.9% tick data back to 1st Jan 2015 so there is roughly 505 days worth of data. 

When you use 3rd Party tick data, you must also produce the HST files as well and protect both FXT and HST files as Read-Only.

When you run a Back-test in the Strategy Tester, the FXT files are used for the current chart data, but for other time frames it will use the HST files. So, they must be absolutely in Sync.

Hence the reason to have TickStory produce both FXT and HST files, and protect them by setting them to Read-Only so that the Broker data does not overwrite the HST files.

PS! You will have to set the read-only flag on HST manually as TickStory does not do it. Also double-check that FXT files are also read-only.

Fernando Carreiro
2958
Fernando Carreiro  
Leon Lodewyks:
I actually think you have a point Marco. I just changed the test period to start on 1st Jan 2016 and it does now produce a value. Thanks very much.

When Using 3rd Party tick data, your test date must be several periods after the initial data date, otherwise your "data" will be empty. You should also always check your "Bars" variable to detect this problem.

For example, if your test data starts 1st January 2015 and your test also starts on that date, then obviously there will not be data before that to be able to obtain "iMA(_Symbol,PERIOD_D1,10,1,MODE_EMA,PRICE_CLOSE,1);" because it refers to data for at least 11 days before that, which obviously is not there!

So your test date should start at least 11 trade days after that start date of your tick data.

Leon Lodewyks
288
Leon Lodewyks  
Fernando Carreiro:

When you use 3rd Party tick data, you must also produce the HST files as well and protect both FXT and HST files as Read-Only.

When you run a Back-test in the Strategy Tester, the FXT files are used for the current chart data, but for other time frames it will use the HST files. So, they must be absolutely in Sync.

Hence the reason to have TickStory produce both FXT and HST files, and protect them by setting them to Read-Only so that the Broker data does not overwrite the HST files.

PS! You will have to set the read-only flag on HST manually as TickStory does not do it. Also double-check that FXT files are also read-only.

Thanks Fernando. I'm pretty sure I have those settings as you mention, but I'll double check. 

Fernando Carreiro
2958
Fernando Carreiro  
Leon Lodewyks:

Thanks Fernando. I'm pretty sure I have those settings as you mention, but I'll double check. 

Also, please read my previous post about the Initial Test date having to be further on past the start date of your data!

EDIT: In essence - Always check your "Bars" variable before accessing any data in the past which is not in reference to the current bar.

To add comments, please log in or register