Spread Filter / not working in the Backtest

 

Hello,

I wrote following spreadfilter:


bool MaxSpreadFilter()
{
   RefreshRates();
   if ((Digits == 4 || Digits == 5)&&(10000.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   if ((Digits == 2 || Digits == 3)&&(100.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   else
   printf("Current Spread too high or adjusted MaxSpread >3. Choose values <=3!");
   return(false);

}


Unfortunately the Spreadfilter works not properly in the Backtest. Only if I am choosing a Spread of 100 in the Strategy Tester, return of false occurs. Otherwise, the EA is Trading all the time.

Do you have an idea, what is wrong?

 
Julian Pachernegg:

Hello,

I wrote following spreadfilter:


bool MaxSpreadFilter()
{
   RefreshRates();
   if ((Digits == 4 || Digits == 5)&&(10000.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   if ((Digits == 2 || Digits == 3)&&(100.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   else
   printf("Current Spread too high or adjusted MaxSpread >3. Choose values <=3!");
   return(false);

}


Unfortunately the Spreadfilter works not properly in the Backtest. Only if I am choosing a Spread of 100 in the Strategy Tester, return of false occurs. Otherwise, the EA is Trading all the time.

Do you have an idea, what is wrong?

You have to understand first, that Digits and Spread are two different functions.
To get Spread value, more quickly using SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);, rather than using (10000.0 * Ask-Bid)

To get the value of Digits use SymbolInfoInteger(Symbol(), SYMBOL_DIGITS);


 
Spread is not accurate in backtesting, it's an approximation / average. 
 
Stuart Browne:
Spread is not accurate in backtesting, it's an approximation / average. 

I don't understand your answer Stuart.

The topic is about MT4. The MT4 Strategy Tester always use a fixed spread. The tester spread setting is in points.

 
Julian Pachernegg:

Hello,

I wrote following spreadfilter:


bool MaxSpreadFilter()
{
   RefreshRates();
   if ((Digits == 4 || Digits == 5)&&(10000.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   if ((Digits == 2 || Digits == 3)&&(100.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   else
   printf("Current Spread too high or adjusted MaxSpread >3. Choose values <=3!");
   return(false);

}


Unfortunately the Spreadfilter works not properly in the Backtest. Only if I am choosing a Spread of 100 in the Strategy Tester, return of false occurs. Otherwise, the EA is Trading all the time.

Do you have an idea, what is wrong?

backtest have no spread history info, no history for ask price existe. you need enter the spread in tester you like to use, its fixed. more there is not
 
Julian Pachernegg:

Hello,

I wrote following spreadfilter:


bool MaxSpreadFilter()
{
   RefreshRates();
   if ((Digits == 4 || Digits == 5)&&(10000.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   if ((Digits == 2 || Digits == 3)&&(100.0 * (Ask - Bid) <= MaxSpread)&&MaxSpread<=3)
   {return(true);}
   else
   printf("Current Spread too high or adjusted MaxSpread >3. Choose values <=3!");
   return(false);

}


Unfortunately the Spreadfilter works not properly in the Backtest. Only if I am choosing a Spread of 100 in the Strategy Tester, return of false occurs. Otherwise, the EA is Trading all the time.

Do you have an idea, what is wrong?

Spread filter on native MT4 backtesting is useless. MT4 Strategy Tester uses only fixed spread that you select in the Spread parameter. If you select a higher value than your spread filter, EA will NOT open any trade, and if you select a lower value than your filter, it will open ALL the trades.

Therefore, in MT4, spread filter is useful ONLY on live trading, but not on native backtesting, unless you use other tools to download and generate tick data history and to make backtesting with floating spread. These tools exist but you would have to pay for them, as it's not possible through standard MT4 backtesting.

Regards.

Reason: