-
ArrayResize does not result in an out of range.
-
for (int i = m_BarStart; i < m_BarCount; i++) ⋮ VEMAs[i][_nFastMA] = VEMAs[i-1][_nFastMA] + alphaFast *(volume * price - VEMAs[i-1][_nFastMA]);
m_BarStart is zero. Therefor when i is zero [i-1] does not exist. That is your out of range.
-
double VEMAs[][6]; #define _nFastMA 0 // numerator Fast MA #define _dFastMA 1 // denominator Fast MA #define _EMAFast 2 #define _nSlowMA 3 // numerator Slow MA #define _dSlowMA 4 // denominator Slow MA #define _EMASlow 5
This is bad style. A one dimension array of a struct would be better.
-
ArrayResize does not result in an out of range.
-
m_BarStart is zero. Therefor when i is zero [i-1] does not exist. That is your out of range.
- This is bad style. A one dimension array of a struct would be better.
UPDATE: Traced the error in method call, I was trying to call two instances with same name. Array Out of Range is Sorted out. However, continues to get wrong values / results now.
Thanks William
There is an if..loop when i < 2, so VEMAs[i-1] should be processed only when i != 0, that is what I understand. Actually this is working well in the VWMACD Indicator I have downloaded from the Forum Market. The only difference in indicator he has used LOOP as "for (int i = (int)MathMax(prev_calculated-1,0); i < rates_total; i++)"
I have tried changing BarStart to 1 (from Zero), still out of range error continues.
Also I am not sure how to SetArrayAsSeries (multidimensional array) in Class, because in in Indicaor it is done automatically while in method / function we need to do with code.
" This is bad style. A one dimension array of a struct would be better." I remember seeing post on forum somewhere, I will be grateful if you can share the link here please.
for (int i = m_BarStart; i < m_BarCount; i++) { double volume = (double)iVolume(m_Symbol,m_TimeFrame,i); // for now use only Tick Volume double price = iClose(m_Symbol,m_TimeFrame,i); // for now use only Close Price //--- Calculate the First Index Value of EMA if(i < 2) { VEMAs[i][_nFastMA] = (volume * price); VEMAs[i][_dFastMA] = (volume); VEMAs[i][_nSlowMA] = (volume * price); VEMAs[i][_dSlowMA] = (volume); continue; } //--- Calculate the Remaining Index Values of EMA VEMAs[i][_nFastMA] = VEMAs[i-1][_nFastMA] + alphaFast *(volume * price - VEMAs[i-1][_nFastMA]);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Forum Members
please help me to get rid of "Array Out of Range" code for IndicatorClass ...
The code is picked up from a custom indicator on MQL5 Market.