//+------------------------------------------------------------------+
//|   IT_Candles.mq4
//+------------------------------------------------------------------+
#property indicator_chart_window
#include <stdlib.mqh>
#property indicator_buffers 2

extern color UpColor = LimeGreen;
extern color DnColor = Red;
extern int Width = 5;
extern double alpha = 0.09;

double ev=EMPTY_VALUE,Trend,Trigger,ALF;
 
double Up[];
double Dn[];

int init()
{
   IndicatorBuffers(2);
   
   SetIndexStyle(0,DRAW_HISTOGRAM,0,Width,UpColor);
   SetIndexBuffer(0,Up);

   SetIndexStyle(1,DRAW_HISTOGRAM,0,Width,DnColor);
   SetIndexBuffer(1,Dn);

   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1); //---- check for possible errors
   if(counted_bars>0) counted_bars--; //---- last counted bar will be recounted
   int limit = Bars-counted_bars;
   
   for (int i=limit;i>=0;i--)
   {
      Up[i] = ev;
      Dn[i] = ev;

      Trend = iCustom(NULL,0,"Instant_Trendline",alpha,0,i);
      Trigger = iCustom(NULL,0,"Instant_Trendline",alpha,1,i);

      ALF = iCustom(NULL,0,"ALF",0,i+1);

      if (Trigger > Trend && Close[i] > Open[i] && Close[i] > ALF)
      {
         Up[i] = MathMax(Open[i],Close[i]);
         Dn[i] = MathMin(Open[i],Close[i]);
      }

      if (Trigger < Trend && Close[i] < Open[i] && Close[i] < ALF)
      {
         Dn[i] = MathMax(Open[i],Close[i]);
         Up[i] = MathMin(Open[i],Close[i]);
      }
   }
}

