Download MetaTrader 5

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

To add comments, please log in or register
shir
29
shir  
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);
  }
//+----------------------------------
Alain Verleyen
Moderator
33502
Alain Verleyen  

Hello,

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


This time, I edited it for you.

shir
29
shir  
#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);
  }
//+--------------------------------------------
shir
29
shir  
angevoyageur:

Hello,

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


This time, I edited it for you.

ok reply src
whroeder1
16105
whroeder1  
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?
shir
29
shir  
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  

whroeder1
16105
whroeder1  
Don't change it to 1500, what if there are only 100 like in the tester? Do it right.
   int limit = MathMin(Bars, barsToCount);
JD4
1100
JD4  
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.
To add comments, please log in or register