//+------------------------------------------------------------------+
//|                                                 TTM original.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_color3 Red
#property indicator_color4 LimeGreen
#property indicator_color5 Yellow
#property indicator_color6 Yellow
#property indicator_color7 Yellow
#property indicator_color8 Yellow
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 2
#property indicator_width8 2

//
//
//
//
//

extern int TTMLength            = 25;
extern int NumberOfComputations = 2;
extern int NumberOfBars         = 6000;
extern int Price                = PRICE_CLOSE;

//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double buffer6[];
double buffer7[];
double buffer8[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   SetIndexBuffer(0,buffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(4,buffer5); SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexBuffer(5,buffer6); SetIndexStyle(5,DRAW_HISTOGRAM);
   SetIndexBuffer(6,buffer7); SetIndexStyle(6,DRAW_HISTOGRAM);
   SetIndexBuffer(7,buffer8); SetIndexStyle(7,DRAW_HISTOGRAM);
   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--)
   {  
      double median = iCustom(NULL,0,"SSA of price",TTMLength,NumberOfComputations,NumberOfBars,Price ,0,i);
      double medias = iCustom(NULL,0,"SSA of price",TTMLength,NumberOfComputations,NumberOfBars,Price ,0,i+1);
            
      //
      //
      //
      //
      //
      
      buffer1[i] = EMPTY_VALUE;
      buffer2[i] = EMPTY_VALUE;
      buffer3[i] = EMPTY_VALUE;
      buffer4[i] = EMPTY_VALUE;
      buffer5[i] = EMPTY_VALUE;
      buffer6[i] = EMPTY_VALUE;
      buffer7[i] = EMPTY_VALUE;
      buffer8[i] = EMPTY_VALUE;
         if (median < medias)
            {
              buffer1[i] = High[i];
              buffer2[i] = Low[i];
              if (Close[i]>Open[i]) { buffer3[i] = Close[i]; buffer4[i] = Open[i]; }  
              else                  { buffer4[i] = Close[i]; buffer3[i] = Open[i]; }  
            }                   
         if (median > medias)
            {
               buffer1[i] = Low[i];
               buffer2[i] = High[i];
               if (Close[i]<Open[i]) { buffer3[i] = Close[i]; buffer4[i] = Open[i]; }  
               else                  { buffer4[i] = Close[i]; buffer3[i] = Open[i]; }  
            }                   
         if (median == medias)
            {
               buffer5[i] = Low[i];
               buffer6[i] = High[i];
               buffer7[i] = Open[i];
               buffer8[i] = Close[i];
            }
   }
   return(0);
}