Download MetaTrader 5

Calculate Z-score and take iMa of it (smoothing)

To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
Anton
23
Anton 2016.01.13 21:27 

Hi there,

I'm trying to calculate MA of Z-score. Z-Score calculation works fine but I can't get any value out of iMa. Any suggestions?

Cheers!

double GetZ(int bar)
   { 
  
  double z_score[];
   
  //Calculate Z-score
  z_score[bar] = ((iClose(NULL, PERIOD_CURRENT, bar) -
              iMA(NULL,PERIOD_CURRENT,Period_Z,0,Smoothing_Method,Price,bar))/
          iStdDev(NULL,PERIOD_CURRENT,Period_Z,0,Smoothing_Method,Price,bar));
          
 
  //Smooth z-score
  return(iMA(NULL,PERIOD_CURRENT,10,0,0,z_score[bar],bar));
          
 } 
Keith Watford
Moderator
9624
Keith Watford 2016.01.13 21:45  
double z_score[];

You don't size the array

Do you even need the array?

 

return(iMA(NULL,PERIOD_CURRENT,10,0,0,z_score[bar],bar));

Why are you using the value in the array as the applied price in the  iMA call?

Anton
23
Anton 2016.01.13 21:55  
GumRai:

You don't size the array

Do you even need the array?

 

Why are you using the value in the array as the applied price in the  iMA call?

I tried without too but got some weird lines in the indicator window...

The calculated Z-score is way to "raw" I just want it to be smooth. I'm not sure how I can do that and was thinking I can achieve that using iMA.

double GetZ(int bar)
   { // Bar Close z-score
  
  double z_score;
   
  z_score = ((iClose(NULL, PERIOD_CURRENT, bar) -
              iMA(NULL,PERIOD_CURRENT,Period_Z,0,Smoothing_Method,Price,bar))/
          iStdDev(NULL,PERIOD_CURRENT,Period_Z,0,Smoothing_Method,Price,bar));
          
   
   return(iMA(NULL,PERIOD_CURRENT,10,0,0,z_score,bar));
          
 } 
Keith Watford
Moderator
9624
Keith Watford 2016.01.14 00:07  
double GetZ(int bar)
   { // Bar Close z-score
  
  double z_score;
   
  z_score = ((iClose(NULL, PERIOD_CURRENT, bar) -
              iMA(NULL,PERIOD_CURRENT,Period_Z,0,Smoothing_Method,Price,bar))/
          iStdDev(NULL,PERIOD_CURRENT,Period_Z,0,Smoothing_Method,Price,bar));
          
   
   return(iMA(NULL,PERIOD_CURRENT,10,0,0,z_score,bar));
          
 } 

Again, why are you using z_score as the applied price in the iMA call?

I am guessing that you probably want to do something with iMAonArray 

Anton
23
Anton 2016.01.14 01:21  
GumRai:

Again, why are you using z_score as the applied price in the iMA call?

I am guessing that you probably want to do something with iMAonArray 

iMAOnArray solved the problem! Thank you!
void MA1_Z() //First MA of Z
{
for(int i=limit-Period1; i>=0; i--)
   {
   Buff[i]= iMAOnArray(zscore,0,Period2,0,Mode2,i);

  } 
}
void MA2_Z() //Second MA of Z
{
for(int j=limit-Period1; j>=0; j--)
   {
   MAofMA[j]= iMAOnArray(Buff,0,Period3,0,Mode3,j);
   }
}
To add comments, please log in or register