//+------------------------------------------------------------------+
//|                                              TMA_Turn_Signal.mq4 |
//|                                  Copyright 2012, SANFIC, GELLYUS |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, SANFIC, GELLYUS"
#property link      "http://www.metaquotes.net"
#property indicator_minimum 0.0
#property indicator_maximum 1.0

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red

extern string TimeFrame       = "current time frame";
extern string StTimeFrame     = "5";
extern int    HalfLength      = 20;
extern int    Price           = PRICE_CLOSE;
extern double ATRMultiplier   = 2.0;
extern int    ATRPeriod       = 100;
extern bool   Interpolate     = true;

double TMA_center[];
double TMA_up[];
double TMA_low[];
double Setup_up[];
double Setup_down[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 SetIndexStyle(0,DRAW_HISTOGRAM);
 SetIndexBuffer(0,Setup_up);
 SetIndexStyle(1,DRAW_HISTOGRAM);
 SetIndexBuffer(1,Setup_down);
 SetIndexStyle(2,DRAW_NONE);
 SetIndexBuffer(2,TMA_center);
 SetIndexStyle(3,DRAW_NONE);
 SetIndexBuffer(3,TMA_up);
 SetIndexStyle(4,DRAW_NONE);
 SetIndexBuffer(4,TMA_low); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for (int i=limit;i>=0;i--) {
   
   TMA_center[i] = iCustom(NULL,0,"TMA",StTimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,0,i);
   TMA_up[i] = iCustom(NULL,0,"TMA",TimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,1,i);
   TMA_low[i] = iCustom(NULL,0,"TMA",TimeFrame,HalfLength,Price,ATRMultiplier,ATRPeriod,Interpolate,2,i);
   
   if (TMA_up[i] < TMA_center[i])
   {Setup_up[i]=1;   Setup_down[i]=EMPTY_VALUE;}
   if (TMA_low[i] > TMA_center[i])
   {Setup_down[i]=1;   Setup_up[i]=EMPTY_VALUE;}
   
   
   }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

