Issue with Reading MACD Histogram – Error 4806 in Strategy Tester / Problem z odczytem danych histogramu MACD – błąd 4806 w testerze strategii

 

Hello,

I'm working on a simple Expert Advisor (EA) in MQL5 that uses the MACD indicator on the M5 timeframe. The code relies on iMACD() and CopyBuffer() to retrieve the histogram values (buffer index 2 ).

Even though the code compiles correctly and the handle is successfully created, during strategy testing I frequently encounter this error:

 MACD histogram data still unavailable after 10 attempts. Error code: 4806

I've taken multiple precautions to ensure data synchronization:

  • Bars(_Symbol, PERIOD_M5) > 100

  • BarsCalculated(macdHandle) > 2

  • Added a condition to wait for at least 50 M5 bars via iTime(_Symbol, PERIOD_M5, 50)

  • Historical and tick data seem fully synchronized in the logs

  • Test parameters:

    • Symbol: NASUSD

    • Period: 2024.01.01 to 2025.07.12

    • Testing mode: "Every tick based on real ticks"

Despite all this, the function:

mql5
Kopiuj Edytuj
CopyBuffer(macdHandle, 2, 0, 2, histogram)

returns 0 , with GetLastError() = 4806 , and the histogram buffer is unavailable.


Questions:

  1. Could there be an issue with histogram buffer generation in the MT5 Strategy Tester?

  2. Is this a known issue with how iMACD and CopyBuffer behave in tester mode?

  3. Could this be caused by tick mismatch or uninitialized indicator buffers during early bars?

I can provide the complete code if needed — it’s short and well-isolated.

I've been debugging this for hours, and it appears the issue is not on the code side, but potentially a platform or data handling limitation.

Any help or suggestions would be much appreciated.

Kind regards,

Robert


Dzień dobry,

Tworzę prostego eksperta (EA) w MQL5, który wykorzystuje narzędzie MACD na międzywale M5. Kod działa w oparciu o iMACD() odczytu CopyBuffer() histogramu (indeks bufora 2).

Mimo prawidłowej zawartości i otrzymania prawidłowego uchwytu (uchwytu MACD), w testerze strategii ( Strategy Tester ) podczas pojawiania się błędu:

Dalej brak danych histogramu MACD po 10 pr óbach. Kod bl du : 4806

Całość, aby sprawdzić synchronizację danych:

  • liczba świec w Bars() jest większa niż 100,

  • BarsCalculated(macdHandle) również wartość większa niż 2,

  • dotrzymać warunku, przez czekanie na minimum 50 świec M5 ( iTime(_Symbol, PERIOD_M5, 50) ),

  • logi występujące, że dane historyczne i tickowe są zsynchronizowane,

  • testuję na symbolu NASUSD, dane z dnia 2024.01.01 – 2025.07.12, tryb „każdy tick (realne dane tickowe)”.

pomimo tego oznaczenia CopyBuffer(macdHandle, 2, 0, 2, histogram) 0 i błąd 4806, histogram nie jest dostępny.

Pytania:

  1. Czy może być problem z wygenerowaniem histogramu bufora w testerze MT5?

  2. Czy jest znany błąd platformy z obsługą iMACD i CopyBuffer w testerze?

  3. Czy możliwe jest, że dane z MACD są nieobliczalne w warunkach testowych (niezgodność historii zaznaczeń)?

Kod przykładowy dostępny jest do wglądu – można go włożyć w razie potrzeby.

Dziękuję za każdą sugestię – od rana próbuję sprawdzić problem i wygląda na to, że nie leży na stronie kodu.

Z poważaniem,

Robert

 

Without seeing your code, I have to guess that iTime() is your likely culprit. You're only checking 50 bars back on the M5 timeframe and within 19 months of historic data.

Unless you're running a multi-timeframe EA, the EA will simply start processing indicator data when it's received from the indicator.

I generally use something like:

   if(CopyBuffer(handleMACDsignal, 0, 0, Bars(NULL, 0), bufferMACDsignal) < 0)
     {
      Print("CopyBuffer MACD error =", GetLastError());
     }
Documentation on MQL5: Timeseries and Indicators Access / iTime
Documentation on MQL5: Timeseries and Indicators Access / iTime
  • www.mql5.com
Returns the opening time of the bar (indicated by the 'shift' parameter) on the corresponding chart. Parameters symbol [in]  The symbol name...
 

Interesting question.

Drawing the high and low of specific candles using bar indexes is definitely doable. I’ve done something similar in the past for marking key reference bars (like news or breakout points).

You can use the bar index as input, and then have the indicator draw two horizontal lines with ObjectCreate. Adding a price label is straightforward too with ObjectSetText.

Curious—do you plan to track those levels dynamically (like across sessions), or just mark them manually for visual reference?

 

Can't really say anything without seeing your exact code sorry.