Can anybody help me? tks a lot. About error shows "zero divide" when uploading my indicator to EA

 

Within the strategy testor, when i run my EA, every time it show the error code in the Journal like this:

"QWYSC EURUSD daily: load successfully

QWYSC EURUSD daily: zero divide"

QWYSC is the name of my indicator.

however, if i add my EA into the EURUSD, in the journal, it shows no error:

"Custom indicator QWYSC EURUSD,Daily: loaded successfully"

the problem is, the buysignal always wrong, which i think, is due to the "zero divide" error.

anybody can help me, i appreciate a lot.

 
The strategy tester is simply coming across a bad equation in your program that you are not yet running into when loading the EA to the chart. The problem still exists, but you don,t see it yet. Double check all of the divisions in your code, because somewhere the variable in the denominator has a value of zero.
 
soothsayer wrote >>
The strategy tester is simply coming across a bad equation in your program that you are not yet running into when loading the EA to the chart. The problem still exists, but you don,t see it yet. Double check all of the divisions in your code, because somewhere the variable in the denominator has a value of zero.

soothsayer
wrote
>>
The strategy tester is simply coming across a bad equation in your program that you are not yet running into when loading the EA to the chart. The problem still exists, but you don,t see it yet. Double check all of the divisions in your code, because somewhere the variable in the denominator has a value of zero.

Tks for you reply! At first, i also thought there were incorrect equations in the code, however, the only denominator throughout the whole code is the closing price of the previous day, like, close(i+1), so i guess somewhere else be wrong. after all, the error message deos not appear when i upload the EA into the chart as live trading, it only appear when i run it through the strategy testor.

 
bondtrader wrote >>

Tks for you reply! At first, i also thought there were incorrect equations in the code, however, the only denominator throughout the whole code is the closing price of the previous day, like, close(i+1), so i guess somewhere else be wrong. after all, the error message deos not appear when i upload the EA into the chart as live trading, it only appear when i run it through the strategy testor.

Post the portion of your code that has the close(i+1) as a divisor or post as much of your code as you feel comfortable posting. That would help us to offer solutions.

You may want to consider adding a print statement if the divisor is zero and print the date/time Open.High/Low/Close for that bar.

then you can check if your data is missing the bar indo found in your print journal.

you may want to do this before posting your code extract.

 

/*As per the code, i abstract the related part below:

i have no idea there is any zero dividor. if i cant find the final reason, i will give up, since after i revise several errors elsewhere in my EA code, this indicator works as well, normally at least, i guess, since it has no occurance of errors further.

//qwysc indicates whether the closing price is bigger than several st.devs from the lowest closing price

if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(i=0; i<limit; i++)
atr[i]=iMAOnArray(tr1,Bars,ATR_period,0,MODE_SMA,i);


for(i=0; i<limit; i++)
{
double curntclose=Close[i];
double pclose=Close[i+1];
double val=Low[iLowest(NULL,0,MODE_LOW,days_low,i)];

double zsy=val+long_stdev*atr[i]*pclose;
qwysc[i]=(curntclose-zsy)/pclose*100;
}

 
bondtrader:


if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;

for(i=0; i<limit; i++)
{
double curntclose=Close[i];
double pclose=Close[i+1];
double val=Low[iLowest(NULL,0,MODE_LOW,days_low,i)];

double zsy=val+long_stdev*atr[i]*pclose;

qwysc[i]=(curntclose-zsy)/pclose*100;
}

When you start the indicator variable limit = Bars.


Last loop iteration fails with zero divide because 

pclose = Close[i + 1] = Close[limit - 1 + 1] = Close[limit] = Close[Bars]

Close[Bars] = 0 as this bar doesn't exist. The last bar in the array is Close[Bars - 1];


Change the line

if (counted_bars>0) counted_bars--;

to


if (counted_bars>0) counted_bars--;
else counted_bars++;
 
Irtron wrote >>

When you start the indicator variable limit = Bars.

Last loop iteration fails with zero divide because

Close[Bars] = 0 as this bar doesn't exist. The last bar in the array is Close[Bar - 1];

Change the line

to

woo, zero divide disappears! many tks, learned a lot.

 
Irtron:

When you start the indicator variable limit = Bars.


Last loop iteration fails with zero divide because

Close[Bars] = 0 as this bar doesn't exist. The last bar in the array is Close[Bars - 1];


Change the line

to


I have the same zero divide too and these are alittle bit compplex can you help on this too. I attach this EA for some improvement this run on EUGBP

Reason: