paulcpk / mql5-MT5-MACD-Classic

A "classic" non-native version of the MACD Indicator for Meta Trader 5, written in MQL5
MIT License
8 stars 4 forks source link

array out of range in 'MACDClassic.mq5' (158,64) #1

Open m4ddav3 opened 3 years ago

m4ddav3 commented 3 years ago

Hi! Love the indicator, however when I tried to incorporate it into an EA, it failed to calculate properly.

2020.11.13 23:37:04.748 2017.01.02 00:01:30 array out of range in 'MACDClassic.mq5' (158,64)

The offending line is: ExtMacdBuffer[i] = ExtFastMaBuffer[i] - ExtSlowMaBuffer[i]; It fails on ExtSlowMaBuffer[i] almost immediately, then the indicator shows no values

m4ddav3 commented 3 years ago

Added #2 to resolve this

paulcpk commented 3 years ago

@m4ddav3 Thank you so much for contributing! I would like to take just a few minutes to reproduce the error and the fix, could you give me a quick explanation on how to trigger the error (is it possible to get this purely programmatically or does it also show up when using the indicator in the charts?)?

YADenisB commented 3 years ago

The solution is pretty simple:

   //--- calculate MACD
    if(ArraySize(ExtMacdBuffer)>=rates_total-1) 
    if(ArraySize(ExtFastMaBuffer)>=rates_total-1) 
    if(ArraySize(ExtSlowMaBuffer)>=rates_total-1) 
    for (int i = limit; i < rates_total && !IsStopped(); i++)
xmoney commented 4 months ago

@m4ddav3 Thank you so much for contributing! I would like to take just a few minutes to reproduce the error and the fix, could you give me a quick explanation on how to trigger the error (is it possible to get this purely programmatically or does it also show up when using the indicator in the charts?)?

right click -> refresh

then the indicator shows no values