Help with iBandsOnArray in MQL4

 

I've having trouble setting up bollinger bands for rsi values

What I've attempted so far

for(int a=0; a<40; a++)
           {
            rsi[a] = iRSI(Symbol(),Period(),14,PRICE_CLOSE,a);
            bbrsiup[a] = iBandsOnArray(rsi,0,34,2.0,0,MODE_UPPER,a);
            bbrsidn[a] = iBandsOnArray(rsi,0,34,2.0,0,MODE_LOWER,a);
           }

if(rsi[1]>70 && rsi[1]>bbrsiup[1])
{
//Sell
}

if(rsi[1]<30 && rsi[1]<bbrsidn[1])
{
//BUY
}

I printed out the values in bbrsiup and bbrsidn to check with the chart in the data window, these values don't match.

What am I doing wrong ?

 
DroidM:

I've having trouble setting up bollinger bands for rsi values

What am I doing wrong ?

You must fill the rsi array first.

 
Keith Watford #:

You must fill the rsi array first.

I moved bbrsiup and bbrsidn outside the loop but the values seem to be of the rsi[5] not rsi[1]

 
Set the rsi array to as series before filling it completely so OnArray knows how to process it.
 
William Roeder #:
Set the rsi array to as series before filling it completely so OnArray knows how to process it.

Thanks a lot mate, I was setting the onArray as series and wondering why it didn't work

 
@DroidM in my opinion you will get a better result, and easier to program if you try BB and RSI separately. Reason is that according to your condition, you will get many signals when price is in between RSI 30 and 70. So it is better to Buy if(rsi <30 && Close[1]< bb lower). 
Reason: