From e5e47664557835b178326982d923801dedb5c53a Mon Sep 17 00:00:00 2001 From: Gunther Schulz Date: Thu, 19 Nov 2020 14:38:46 +0100 Subject: [PATCH] add feature to correct historical tick data some brokers (markets.com) deliver tick incorrect historical tick data. this commit attempts to automatically correct the tick price data --- Experts/JsonAPI.mq5 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Experts/JsonAPI.mq5 b/Experts/JsonAPI.mq5 index 6e30143..62e4ac7 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