Navigation´╝ÜHome > Content >

AverageMADirection.mq4

Time: 2010-12-03 | Download file:AverageMADirection.mq4

//+------------------------------------------------------------------+
//|                                            AverageMADistance.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//--- input parameters
extern int       min=15;
extern int       max=60;
extern int       step=5;
extern int       method = 2;
extern int       avg = 1;
extern int       factor = 10;
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Yellow

double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
      SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
  

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

double maFunction(int len, int shift){
//return (iMA(Symbol(), Period(), len, 0, method, PRICE_CLOSE, shift));
  return (iCustom(Symbol(), Period(), "JMA", len, factor, 0, shift));
  return(0);
}

int start()
  {
//----
   int c = Bars - IndicatorCounted();
  
   for(int i = 0; i < c;i++){
      
      ExtMapBuffer2[i] = 0;
      int j = 0;
      
      for(int m = min; m <= max - step + 1 ; m+=step){
         j++;
         double ma1 = maFunction(m, i) -  maFunction(m, i+1);
         if(ma1 > 0){
            ExtMapBuffer2[i]++;
         } else if(ma1 < 0){
            ExtMapBuffer2[i]--;
         }}
   }
   
    for( i = 0; i < c;i++){
      //ExtMapBuffer1[i] -= MathTan(ExtMapBuffer1[i-1] - ExtMapBuffer1[i]) ;
     // ExtMapBuffer2[i] -= MathTan(ExtMapBuffer2[i-1] - ExtMapBuffer2[i]) ;
     //ExtMapBuffer1[i] = Avg(ExtMapBuffer1, i, avg);
     ExtMapBuffer2[i] = Avg(ExtMapBuffer2, i, avg);
    }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

double Avg(double & array[], int shift, int count){
double sum = 0;
for(int i = 0; i < count; i++){
sum += array[shift+i];
}

return (sum / count);
}


























Recommend