Page 1 of 1

How to avoid negative spread when adjust during MT5 export

Posted: Sun May 28, 2023 7:11 pm
by shawnsuen
Dear Support team,

I have been using your previous suggestion to adjust tick spread with below commands to export data to MT5, as I would like to replicate my ECN account's real spreads.

Bars:
{BarBeginTime:yyyyMMdd},{BarBeginTime:HH\:mm\:ss},{Open},{High},{Low},{Close},{BarTickCount},{BarTickCount},{BarMaxSpread*100000-10:F0}
Ticks:
{Timestamp:yyyyMMdd},{Timestamp:HH\:mm\:ss},{BidPrice+0.00005},{AskPrice-0.00005},{BidPrice+0.00005},{BidVolume:F0}

However, this leads to negative spreads for some ticks, e.g. ask price < bid price. How can I avoid the negative spreads? Is there a place that can set mininum value of spreads to be 0?

Please let me know if my question is unclear, and look forward to hearing from you soon!

Thanks,
Shawn

Re: How to avoid negative spread when adjust during MT5 export

Posted: Mon May 29, 2023 1:11 pm
by tickstory
Hi Shawn,

I assume the problem lies when importing ticks into MT5 (as opposed to the bar data)? Is MT5 giving you any error when it comes across overlapping bid/ask prices or is it using the data as-is and returning a negative spread in your EA?

One solution might be to make sure that your price adjustments are specified so they don't cause a negative number. Of course, not knowing how much overlap there is going to be a problem. The only solution I can think of is calculating the "absolute"/non-negative price in your EA in MT5. This would be the correct approach given this could also potentially occur in a live environment.

Hope this helps.