Navigation´╝ÜHome > Content >

TVI_Histogram.mq4

Time: 2017-06-14 | Download file:TVI_Histogram.mq4

//+------------------------------------------------------------------+
//|   TVI_Histogram.mq4
//+------------------------------------------------------------------+
#property indicator_separate_window
#include 
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_level1 0.00
#property indicator_levelcolor Black

extern int r=12;
extern int s=12;
extern int u=5;
extern bool SendAlert = false;

double ev=EMPTY_VALUE;
bool AlertDone = false;
 
double UpPos[];
double DnPos[];
double UpNeg[];
double DnNeg[];

double TVI[];
double Trend[];

int init()
{
   IndicatorBuffers(4);
   
   SetIndexStyle(0,DRAW_HISTOGRAM,0,3);
   SetIndexBuffer(0,UpPos);

   SetIndexStyle(1,DRAW_HISTOGRAM,0,3);
   SetIndexBuffer(1,DnPos);

   SetIndexStyle(2,DRAW_HISTOGRAM,0,3);
   SetIndexBuffer(2,UpNeg);

   SetIndexStyle(3,DRAW_HISTOGRAM,0,3);
   SetIndexBuffer(3,DnNeg);

   ArraySetAsSeries(TVI,true);
   ArraySetAsSeries(Trend,true);

   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--)
   {
      ArrayResize(TVI,Bars);   
      ArrayResize(Trend,Bars);   

      Trend[i] = Trend[i+1];
      
      TVI[i] = iCustom(NULL,0,"TVI",r,s,u,0,i);
      
      if (TVI[i] > TVI[i+1])
      {Trend[i] = 1;}
      else
      if (TVI[i] < TVI[i+1])
      {Trend[i] = -1;}
      
      if (Trend[i] > 0)
      {
         if (TVI[i] >= 0)
         {
            UpPos[i] = TVI[i];
            DnPos[i] = 0;
         }
         else
         {
            UpNeg[i] = TVI[i];
            DnNeg[i] = 0;
         }
      }
      else
      if (Trend[i] < 0)
      {
         if (TVI[i] >= 0)
         {
            DnPos[i] = TVI[i];
            UpPos[i] = 0;
         }
         else
         {
            DnNeg[i] = TVI[i];
            UpNeg[i] = 0;
         }
      }
      DoAlerts(i);
   }
}

void DoAlerts(int i)
{
   if (SendAlert && i == 0)
   {
      if (Trend[i+1] != Trend[i+2])
      {
         if (AlertDone == false)
         {
            AlertDone = true;      
            if (Trend[i+1] > 0)
            {
               Alert("TVI Up ",Symbol());
            }               
            else
            {
               Alert("TVI Down ",Symbol());
            }               
            PlaySound("Alert.wav");
         }   
      }
      else
      {AlertDone = false;}
   }
}
//+------------------------------------------------------------------+

Recommend