Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey Folks,,, first off much appreciation for this community. Just slightly struggling with bollinger band code conversion from mt4 to mt5 and could really use some help sorting this issue! Will be highly appreciated!
Code below,
// GETTING THE AMOUNT OF ALL BARS OF THE CHART
int IBARSA = iBars(NULL,A_TF);
//---- Checking whether the bars number is enough for further calculation
if(IBARSA < A_MA)
return(0);
// INDICATOR BUFFERS EMULATION
if(ArraySize(BandWidthA) < IBARSA)
{
ArraySetAsSeries(BandWidthA, false);
ArraySetAsSeries(MainA, false);
ArraySetAsSeries(PercentA, false);
//----
ArrayResize(BandWidthA, IBARSA);
ArrayResize(MainA, IBARSA);
ArrayResize(PercentA, IBARSA);
//----
ArraySetAsSeries(BandWidthA, true);
ArraySetAsSeries(MainA, true);
ArraySetAsSeries(PercentA, true);
}
// INSERTION OF A STATIC INTEGER MEMORY VARIABLE
static int IndCountedA;
//----+ Insertion of integer variables and GETTING ALREADY CALCULATED BARS
int A, MaxBarA, barA, counted_barsA = IndCountedA;
//---- checking for possible errors
if(counted_barsA < 0)
return(-1);
//---- the last calculated bar must be recalculate
if(counted_barsA > 0)
counted_barsA--;
//----+ REMEMBERING THE AMOUNT OF ALL BARS OF THE CHART
IndCountedA = IBARSA - 1;
//---- defining the number of the oldest bar,
//---- starting from which new bars will be recalculated
A = IBARSA - counted_barsA - 1;
//---- defining the number of the oldest bar,
//---- starting from which new bars will be recalculated
MaxBarA = IBARSA - 1 - A_MA;
//---- initialization to zero
if(A > MaxBarA)
{
A = MaxBarA;
for(barA = IBARSA - 1; barA >= 0; barA--)
{
BandWidthA[barA] = 0.0;
MainA[barA] = 0.0;
PercentA[barA]=0.0;
}
}
//------MAIN CYCLE
//---------------------1
for(int a = IBARSA-1; a >= 0; a--)
{
double UpperBandA = iBands(NULL,A_TF,A_MA,Deviation,Shift,2,MODE_UPPER, a);
double LowerBandA = iBands(NULL,A_TF,A_MA,Deviation,Shift,3,MODE_LOWER, a);
double MiddlBandA = iBands(NULL,A_TF,A_MA,Deviation,Shift,4,MODE_MAIN, a);
double DenominatA = UpperBandA - LowerBandA;
if( MiddlBandA == 0.0 ) { MiddlBandA = 0.00001; }
if( DenominatA == 0.0 ) { DenominatA = 0.00001; }
BandWidthA[a] = ( UpperBandA - LowerBandA ) / MiddlBandA;
PercentA[a] = (Close[a]-LowerBandA)/DenominatA;
//----
}
while(A>=0)
{
//----
MainA[A] = iMAOnArray(BandWidthA,0,A_MAMA,Shift,MODE_SMA, A);
//----
A--;
}
A_PerCent=PercentA[0];
double A_DIFF=BandWidthA[0]-MainA[0];