diff --git a/Experts/JsonAPI.mq5 b/Experts/JsonAPI.mq5 index f6e6a67..64a3033 100644 --- a/Experts/JsonAPI.mq5 +++ b/Experts/JsonAPI.mq5 @@ -914,6 +914,32 @@ bool PushHistoricalData(CJAVal &data) return true; } +//+------------------------------------------------------------------+ +//| Correct historical tick data | +//+------------------------------------------------------------------+ +// Some brokers (markets.com) deliver incorrect historical tick data +// with an incorrect spread. +// This attempts to automatically adjust the +// historical tick data. +// Live bar data is also represented with the same, incorrect spread so we attempt +// to adjust historical tick data by that same amount. +void CorrectTicks(string symbol, MqlTick ©TicksArray[]) + { + MqlTick symbolInfoTick; + double offsetBid, offsetAsk; + int tickCount = ArraySize(copyTicksArray); + SymbolInfoTick(symbol,symbolInfoTick); + + offsetBid = copyTicksArray[tickCount-1].bid - symbolInfoTick.bid; + offsetAsk = copyTicksArray[tickCount-1].ask - symbolInfoTick.ask; + + for(int i=0; i