//+------------------------------------------------------------------+
//|                                                   TFT_Arrows.mq4 |
//|                           Zen_Leow based on work done by Kalenzo |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Blue
// The color for displaying arrows
#property indicator_color4 Green       // Long signal
#property indicator_color5 Red         // Short signal

#property indicator_width1 1
#property indicator_width2 3
#property indicator_width3 3
// Width of the arrows
#property indicator_width4 2  // Long signal arrow
#property indicator_width5 2  // Short signal arrow

extern int Lb = 3;
extern int Arrow_Distance = 5;
double ssla[],sslb[],sslc[],Up_Arrow_Buffer[],Down_Arrow_Buffer[],Hld,Hlv,Hlvprev;

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(5);
   SetIndexBuffer(0,sslc);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(1,ssla);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(2,sslb);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexBuffer(3, Up_Arrow_Buffer);
   SetIndexArrow(3, 233); // Up arrow
   SetIndexStyle(4, DRAW_ARROW);
   SetIndexBuffer(4, Down_Arrow_Buffer);
   SetIndexArrow(4, 234); // Down arrow
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
 
//----
   for(int i=Bars-Lb;i>=0;i--)
   {
      if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1))
      Hld = 1;
      else 
      {
       if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1))  
       Hld = -1;
       else
       Hld = 0;
      }
      
      if(Hld!=0)
      Hlv = Hld;
            
      if(Hlv == -1){
         sslc[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
         ssla[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
         
      }else{
         sslc[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1);
         sslb[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1);
         
         
      }
   }
   
   for(i=Bars-Lb;i>=0;i--)
   {
      if(sslb[i] == iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1) && sslb[i+1] != iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+2))
      {
         Up_Arrow_Buffer[i] = sslb[i] - (Arrow_Distance * Point);
         continue;
      }
      if(ssla[i] == iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1) && ssla[i+1] != iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+2))
      {
         Down_Arrow_Buffer[i] = ssla[i] + (Arrow_Distance * Point);
         continue;
      }
      Up_Arrow_Buffer[i] = EMPTY_VALUE;
      Down_Arrow_Buffer[i] = EMPTY_VALUE;
   }
  
//----
   return(0);
  }
//+------------------------------------------------------------------+

