Download MetaTrader 5
To add comments, please log in or register
Any questions regarding MQL5 Cloud Network? FAQ will help you!
shir
29
shir 2015.05.30 15: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);
  }
//+----------------------------------
Alain Verleyen
Moderator
28659
Alain Verleyen 2015.05.30 19:48  

Hello,

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


This time, I edited it for you.

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

Hello,

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


This time, I edited it for you.

ok reply src
whroeder1
13641
whroeder1 2015.05.30 21: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?
shir
29
shir 2015.05.31 12: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  

whroeder1
13641
whroeder1 2015.05.31 12: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);
JD4
1101
JD4 2015.06.25 00: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.
/
To add comments, please log in or register