i think i found why the code is not working into MQL5. i debug below code:
void OnInit()
{
min_rates_total=int(RSI_Period)+1;
PlotIndexSetString(0,PLOT_LABEL,"Traders Dynamic Index");
IndicatorSetString(INDICATOR_SHORTNAME,"Traders Dynamic Index");
SetIndexBuffer(5,RSIBuf);
SetIndexBuffer(0,UpZone,INDICATOR_DATA);
ArraySetAsSeries(UpZone,true);
SetIndexBuffer(1,MdZone,INDICATOR_DATA);
ArraySetAsSeries(MdZone,true);
SetIndexBuffer(2,DnZone,INDICATOR_DATA);
ArraySetAsSeries(DnZone,true);
SetIndexBuffer(3,MaBuf,INDICATOR_DATA);
ArraySetAsSeries(MaBuf,true);
SetIndexBuffer(4,MbBuf,INDICATOR_DATA);
ArraySetAsSeries(MbBuf,true);
//---- the number of the indicator's horizontal levels is 5
IndicatorSetInteger(INDICATOR_LEVELS,3);
//---- Values of the indicator horizontal levels
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,+50);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,+68);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,+32);
//---- gray and magenta colors are used for horizontal levels lines
IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrDimGray);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrDimGray);
IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrDimGray);
//---- Short dot-dash is used for the horizontal level line
IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DOT);
//----
}
for(int x=i; x <(i+Volatility_Band); x++) {
RSI[x-i] = RSIBuf[x];
MA += RSIBuf[x]/Volatility_Band;
mm++;
}
in this code a error rise on the line of "RSIBuf[x]" : "array out of range". i declare buffer double RSIBuf[]. now how can i solve this problem.
![Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Web Colors Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Web Colors](/i/community/logo_mql5_small.png)
- www.mql5.com
- Please EDIT your posts and use the SRC button when you post code. Thanks.
- In a mql5, index of a indicator's buffer must be strictly between 0 and rates_total-1.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am converting my old indicator of MQL4 to MQL5. I having a problem.
MQL code like :
int Volatility_Band = 34 ;
for(int i=limit; i>=0; i--)
{
RSIBuf[i] = (iRSI(NULL,0,RSI_Period,RSI_Price,i));
MA = 0;
for(int x=i; x<i+Volatility_Band; x++) {
RSI[x-i] = RSIBuf[x];
MA += RSIBuf[x]/Volatility_Band;
mm++;
}
UpZone[i] = (MA + (1.6185 * StDev(RSI,Volatility_Band)));
DnZone[i] = (MA - (1.6185 * StDev(RSI,Volatility_Band)));
MdZone[i] = ((UpZone[i] + DnZone[i])/2);
return(0);
}
the code is working fine in MQL4. but when I write same as MQL5.
for(i=limit; i>=0 && !IsStopped(); i--)
{
RSIBuf[i] = (iRSIMQL4(NULL,0,RSI_Period,RSI_Price,i));
UpZone[i] = (iRSIMQL4(NULL,0,RSI_Period,RSI_Price,i));
MA = 0;
mm=0;
for(int x=i; x <(i+Volatility_Band); x++) {
RSI[x-i] = RSIBuf[x];
MA += RSIBuf[x]/Volatility_Band;
mm++;
}
Alert(mm);
return(0);
}
but MQL5 code is not work. I found what's wrong there. second loop int x. never end into MQL5. second loop going and going. is anyone help me . how am I correct MQL5 code