Hi Daniele,
Yes, the MT5 Tester does support variable spread if you have imported tick data as described in the previous link. The tick data contains the actual bid/ask
prices and MT5 will show this when "
Every tick based on real ticks" modelling method is selected in the Strategy Tester. If you follow the exact steps in the document, there should be nothing else needed.
Please see the following code example how to use it. The code below will print the current spread in the top-left of the visual chart (the example was taken from the MT5 Help file under 'SymbolInfoDouble'):
Code: Select all
void OnTick()
{
//--- obtain spread from the symbol properties
bool spreadfloat=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD_FLOAT);
string comm=StringFormat("Spread %s = %I64d points\r\n",
spreadfloat?"floating":"fixed",
SymbolInfoInteger(Symbol(),SYMBOL_SPREAD));
//--- now let's calculate the spread by ourselves
double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
double spread=ask-bid;
int spread_points=(int)MathRound(spread/SymbolInfoDouble(Symbol(),SYMBOL_POINT));
comm=comm+"Calculated spread = "+(string)spread_points+" points";
Comment(comm);
}
Hope this helps.