Post your code.
here it is, the problematic section in bold
//---- input parameters extern string CorrelatedSymbol="USDCHF"; extern int band_len=20; extern int band_dev=2; extern bool alerts=false; //---- buffers double buf1[]; double buf2[]; double buf3[]; datetime lastbar,lastalert; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,buf1); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,buf2); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,buf3); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); int limit=Bars-counted_bars;for(int i=(limit-1); i>=0; i--) { buf1[i]=iClose(NULL,Period(),i)/iClose(CorrelatedSymbol,Period(),i); buf2[i]=iBandsOnArray(buf1,0,band_len,band_dev,0,MODE_UPPER,i); buf3[i]=iBandsOnArray(buf1,0,band_len,band_dev,0,MODE_LOWER,i); }
if (lastalert<Time[0])
{
lastbar=Time[0];
if (alerts) {
if (buf1[0]>buf2[0]) {PlaySound("vendi.wav");aspettaMs(290);
Print("corr Band -- SELL "+Symbol()+" "+Period());
if(Period()>15)Alert("corr Band -- SELL "+Symbol()+" "+Period());
lastalert=Time[0];
}
if (buf1[0]<buf3[0]) {PlaySound("compra.wav");aspettaMs(290);
Print("corr Band -- BUY "+Symbol()+" "+Period());
if(Period()>15)Alert("corr Band -- BUY "+Symbol()+" "+Period());
lastalert=Time[0];
}
}
}
return(0);
}
//+------------------------------------------------------------------+
void aspettaMs(int quanti)
{
int inizio,ciao;
inizio = GetTickCount();
while (GetTickCount()<(inizio+quanti)) {ciao=ciao+1;}
}
First of all it should be 2 loops instead of 1
int i; for(i=(limit-1); i>=0; i--) buf1[i]=iClose(NULL,Period(),i)/iClose(CorrelatedSymbol,Period(),i); for(i=(limit-1); i>=0; i--) { buf2[i]=iBandsOnArray(buf1,0,band_len,band_dev,0,MODE_UPPER,i); buf3[i]=iBandsOnArray(buf1,0,band_len,band_dev,0,MODE_LOWER,i); }
Thank You! I will try that.
It worked flawlessly.. stupid me, thanks Stringo!

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
Hello I have a weird problem with an indicator I wrote that uses IBandonArray.
When I first drag the indicator on the chart it doesnt work properly -- the values of ibandsonarray are not displayed at all.
However if I recompile the indicator while it is still attached to the chart it will start to work properly.
What am I doing wrong, is there a workaround for this?
Thanks and many regards
Alex