i have problem please can sameone help me with zero divide error

Back to topics list To post a new topic, please log in or register
avatar
8
shir266 2015.05.30 17:54
 
int init()
  {
//---- indicators
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,zscore);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit = barsToCount;
   
//----
   
   for(int i = 0 ;i <= limit-20 ;i++)
   
   {  
      
      zscore[i] = (iClose(NULL,0,i)-iMA(NULL,0,maPeriod,0,0,0,i))/iStdDev(NULL,0,maPeriod,0,0,0,i);  
   }
//----
   return(0);
  }
//+----------------------------------

avatar
Moderator
3206
angevoyageur 2015.05.30 21:48 #
 

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

avatar
8
shir266 2015.05.30 22:26 #
 
#property copyright "Mod"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
#property indicator_level1 0
//---- input parameters
extern int       barsToCount = 2000;
//---- buffers
double zscore[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,zscore);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit = barsToCount;
   
//----
   
   for(int i = 0 ;i <= limit-20 ;i++)
   {  
      
      zscore[i] = (iClose(NULL,0,i)-iMA(NULL,0,60,0,0,0,i))/iStdDev(NULL,0,60,0,0,0,i);  
   }
//----
   return(0);
  }
//+--------------------------------------------

avatar
8
shir266 2015.05.30 22:38 #
 
angevoyageur:

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

ok reply src
avatar
12985
WHRoeder 2015.05.30 23:53 #
 
extern int       barsToCount = 2000;
:
   int limit = barsToCount;
   
   for(int i = 0 ;i <= limit-20 ;i++)

  /iStdDev(NULL,0,60,0,0,0,i);  
What happens if there are not 2000-20 bars on the chart?
avatar
8
shir266 2015.05.31 14:09 #
 
WHRoeder:
What happens if there are not 2000-20 bars on the chart?

thank you whroeder  i change the bars to 1500 and its ok 

thanks  

avatar
12985
WHRoeder 2015.05.31 14:41 #
 
Don't change it to 1500, what if there are only 100 like in the tester? Do it right.
   int limit = MathMin(Bars, barsToCount);

avatar
313
JD4 2015.06.25 02:33 #
 
One possible solution is an if/else test where you test the item that might possibly give you a divide by zero error before you get to that division.  Test to see if it is a zero first, if not, then do the test, but if it is, skip the test part.
Back to topics list  

To add comments, please log in or register