zero divide В чем причина?

 

Написал индикатор на основе адаптивной скользящей средней. Однако на графике не прорисовывается. Не понимаю, в чем может быть причина.

Помогите, пожалуйста, разобраться!

Код индикатора внизу.

Заранее большое спасибо.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

//---- input parameters
extern int StdDev_Per =9;
extern int MA_Period =12;
extern int n_SD =2;

//---- buffers
double VidBuffer[];

int draw_begin=0;
double SC;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(1);

if (!SetIndexBuffer(0,VidBuffer) )
Alert("Cannot see indicator buffer!");

SetIndexStyle(0,DRAW_LINE);
SetIndexLabel(0,"VIDYA-MacCormik");

draw_begin=n_SD*StdDev_Per;
SetIndexDrawBegin(0,draw_begin);
SetIndexEmptyValue(0,0.0);

return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit,counted_bars=IndicatorCounted();
double K;

SC=2.0/(MA_Period+1);

if (counted_bars<0) return(-1);
if (counted_bars==0) limit=Bars-1;
if (counted_bars>0) limit=Bars-counted_bars-1;

Print("Bars=",Bars,"cbars=",counted_bars,"limit=", limit);

for(i=limit;i>=0;i--)
{
Print("i=",i);

if (i==Bars-n_SD*StdDev_Per-1) {VidBuffer[i+1]=Close[i+1]; Print("i=", i,"VidBuffer[i+1]=", VidBuffer[i+1]);}

K=iStdDev(NULL,0,StdDev_Per,MODE_EMA,0,PRICE_CLOSE,i)/iStdDev(NULL,0,n_SD*StdDev_Per, MODE_EMA,0,PRICE_CLOSE,i);
Print("K[i]=",K);

VidBuffer[i]=SC*K*Close[i]+VidBuffer[i+1]*(1-(SC*K));
Print("VidBuffer[i]=",VidBuffer[i]);
}
return(0);
}
//+------------------------------------------------------------------+

[Удален]  

Деление на ноль, в коде 2 таких места где используется операция деления:

SC=2.0/(MA_Period+1); K=iStdDev(NULL,0,StdDev_Per,MODE_EMA,0,PRICE_CLOSE,i)/iStdDev(NULL,0,n_SD*StdDev_Per,MODE_EMA, 0,PRICE_CLOSE,i);

Вставте перед ними проверку на 0 и какой-нибудь Print/Comment и поймете откуда что берется

 
Перед делением проверь выражение iStdDev(NULL,0,n_SD*StdDev_Per,MODE_EMA,0,PRICE_CLOSE,i); на ноль.
 

Деление на ноль, в коде 2 таких места где используется операция деления:

SC=2.0/(MA_Period+1); K=iStdDev(NULL,0,StdDev_Per,MODE_EMA,0,PRICE_CLOSE,i)/iStdDev(NULL,0,n_SD*StdDev_Per,MODE_EMA, 0,PRICE_CLOSE,i);

Вставте перед ними проверку на 0 и какой-нибудь Print/Comment и поймете откуда что берется


Спасибо, а как все просто оказалось... )))

 
Vinin:
Перед делением проверь выражение iStdDev(NULL,0,n_SD*StdDev_Per,MODE_EMA,0,PRICE_CLOSE,i); на ноль.

Пасиб, уже проверил... все ок