I'm trying to translate an indicator from MQL4 (Metatrader language) to Matlab. The Bollinger bands code is as follows:
for(int i=Bars;i>=0;i--)
{
BANDS=iBands(Symbol(),0,20,2,1,0,1,i+1);
}
the iBands() documentation lists the 8 inputs as:
symbol
timeframe
period
deviation
bands_shift
applied_price
mode
shift
I understand all these except bands_shift
and shift
. Question: If i = Bars
is the entire range of the data, why does the i+1
not create an out of range error? As far as I can tell, this is code for a 20 period, 2 standard deviation Bollinger band. For a given time interval, are the associated Bollinger band values the values calculated for the previous time interval (hence the 1
after the fourth comma)? What does the i+1
do then? Given this code, how would I implement in matlab? My attempt, using this moving standard deviation and this moving average:
moving_average = movemean(EURUSD_closes(1:end-1),20); %end-1 in order to shift by 1
moving_average = [NaN; moving_average]; %adding NaN to make BANDS the length of price
moving_std = movestd(EURUSD_closes(1:end-1),20,'backward');
moving_std = [NaN; moving_std1];
BANDS = moving_average + 2*moving_std;
I don't think this gives the same output as the MQL4 code. Any hints would definitely be appreciated!