_time_avg_v1.0





//+------------------------------------------------------------------+
//|                                                time_avg_v1.0.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_buffers 2
#property indicator_separate_window
#property indicator_color1  MediumTurquoise
#property indicator_width1 2
#property indicator_color2  CadetBlue
#property indicator_width2 1

extern int MA1=12;
extern int MA2=24;
extern int Crosses=50;
extern int Bars_=600;


double buff1[],buff2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  	IndicatorBuffers(2); 
	SetIndexStyle(0, DRAW_LINE);
	SetIndexBuffer(0, buff1);
	SetIndexStyle(1, DRAW_LINE,STYLE_DOT);
	SetIndexBuffer(1, buff2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int cnt;
   int dir,a;
   double h_u,h_d,l_u,l_d;
   double delta_u,delta_d;
//----

dir=1;   
cnt=0;
   for(int i=Bars_;i>0;i--)
   {
   double m1_=iMA(NULL,Period(),MA1,0,MODE_SMA,PRICE_CLOSE,i);
   double m2_=iMA(NULL,Period(),MA2,0,MODE_SMA,PRICE_CLOSE,i);

   cnt=1;
   h_u=0; h_d=0; l_u=100000; l_d=100000;
   delta_u=0;
   int q=i;

      while(cnt<50)
      {
      double m1=iMA(NULL,Period(),MA1,0,MODE_SMA,PRICE_CLOSE,q);
      double m2=iMA(NULL,Period(),MA2,0,MODE_SMA,PRICE_CLOSE,q);

         if(m1>m2&&dir==-1)
         {
         dir=1;
         cnt++;
         }
         if(m1<m2&&dir==1)
         {
         dir=-1;
         cnt++;
        }
      q++;
      }

int aaa=q-i;

   cnt=1;
   h_u=0; h_d=0; l_u=100000; l_d=100000;
   delta_u=0;

      while(q>i)
      {
      m1=iMA(NULL,Period(),MA1,0,MODE_SMA,PRICE_CLOSE,q);
      m2=iMA(NULL,Period(),MA2,0,MODE_SMA,PRICE_CLOSE,q);

      if(High[q]>h_u)h_u=High[q];
      if(Low[q]<l_u)l_u=Low[q];

      
         if(m1>m2&&dir==-1)
         {
         dir=1;
         cnt++;
         delta_u=delta_u+(h_u-l_u);
         h_u=0; h_d=0; l_u=100000; l_d=100000;

         }
         if(m1<m2&&dir==1)
         {
         dir=-1;
         cnt++;
         delta_u=delta_u+(h_u-l_u);
         h_u=0; h_d=0; l_u=100000; l_d=100000;   

        }
      q--;
      }

      delta_u=delta_u/cnt;
      delta_u=delta_u/2;
      cnt=aaa/cnt;

      buff2[i]=cnt;
      buff1[i]=NormalizeDouble(delta_u/Point,0);
   }
if (!IsTesting()){
     Comment(" Áîêîâûå îòêëîíåíèÿ: "+DoubleToStr((delta_u/Point),0)+" ïóíêòîâ\n Ñðåäíåå êîëè÷åñòâî áàðîâ: "+cnt+"\n Ïåðåñå÷åíèé: "+ Crosses+"\n Èñïîëüçóåòñÿ áàðîâ: "+aaa);
}
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: