TD_moving_average_I





//+------------------------------------------------------------------+
//|                                          TD moving average I.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_color3 Red
#property indicator_color4 LimeGreen
#property indicator_width1 2
#property indicator_width2 2

//
//
//
//
//

extern int HighsLowsPeriod  = 13;
extern int AllowedGapPeriod = 3;
extern int AveragesPeriod   = 5;

//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double buffer6[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(6);
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,159);
   SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159);
   SetIndexBuffer(4,buffer5);
   SetIndexBuffer(5,buffer6);
   return(0);
}
int deinit() { return(0); }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;
 
   //
   //
   //
   //
   //
   
   for(i=limit; i >= 0; i--)
   {
      if (iLowest(NULL,0,MODE_HIGH,HighsLowsPeriod,i)==i) buffer5[i] = 0; else buffer5[i] = buffer5[i+1]+1;
      if (iHighest(NULL,0,MODE_LOW,HighsLowsPeriod,i)==i) buffer6[i] = 0; else buffer6[i] = buffer6[i+1]+1;

      //
      //
      //
      //
      //
      
         buffer1[i] = EMPTY_VALUE;
         buffer2[i] = EMPTY_VALUE;
         buffer3[i] = EMPTY_VALUE;
         buffer4[i] = EMPTY_VALUE;
         
         if (buffer5[i] <= AllowedGapPeriod)  buffer1[i] = iMA(NULL,0,AveragesPeriod,0,MODE_SMA,PRICE_HIGH,i);
         if (buffer6[i] <= AllowedGapPeriod)  buffer2[i] = iMA(NULL,0,AveragesPeriod,0,MODE_SMA,PRICE_LOW ,i);
         if (buffer1[i] != EMPTY_VALUE && buffer1[i+1] == EMPTY_VALUE) buffer3[i] = buffer1[i];
         if (buffer2[i] != EMPTY_VALUE && buffer2[i+1] == EMPTY_VALUE) buffer4[i] = buffer2[i];
   }

   //
   //
   //
   //
   //
  
   return(0);
}



Sample





Analysis



Market Information Used:



Indicator Curves created:


Implements a curve of type DRAW_ARROW

Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: