//+------------------------------------------------------------------+
//|                                                SemaphorTrue2.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, zznbrm"

//---- indicator settings
#property indicator_chart_window
#property  indicator_buffers 6 
#property  indicator_color1 Gray
#property  indicator_color2 Magenta
#property  indicator_color3 Yellow
#property  indicator_color4 Gray
#property  indicator_color5 Magenta
#property  indicator_color6 Yellow
#property  indicator_width1 2
#property  indicator_width2 2
#property  indicator_width3 2
#property  indicator_width4 2
#property  indicator_width5 2
#property  indicator_width6 2

//---- input parameters
extern ENUM_TIMEFRAMES TimeFrame=PERIOD_D1;
extern int eintDepth1 = 5;
extern int eintDepth2 = 13;
extern int eintDepth3 = 34;
extern double edblOffsetPoints=150.0;
extern int MaxBars=1000;

extern string _alerts="--- Alerts ---";
extern bool Ball1_Alerts = false;
extern bool Ball2_Alerts = true;
extern bool Ball3_Alerts = true;
extern bool Send_Emails= FALSE;
extern bool Show_Popup = true;


//---- indicator buffers
double gadblUp1[];
double gadblUp2[];
double gadblUp3[];
double gadblDn1[];
double gadblDn2[];
double gadblDn3[];

int MaxBars2;
datetime lastTime=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,gadblUp1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexLabel(0,"Up1");

   SetIndexBuffer(1,gadblUp2);
   SetIndexEmptyValue(1,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexLabel(1,"Up2");

   SetIndexBuffer(2,gadblUp3);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,159);
   SetIndexLabel(2,"Up3");

   SetIndexBuffer(3,gadblDn1);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,159);
   SetIndexLabel(3,"Dn1");

   SetIndexBuffer(4,gadblDn2);
   SetIndexEmptyValue(4,0.0);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,159);
   SetIndexLabel(4,"Dn2");

   SetIndexBuffer(5,gadblDn3);
   SetIndexEmptyValue(5,0.0);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,159);
   SetIndexLabel(5,"Dn3");

   IndicatorDigits(5);

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("SemaphorTrue2("+eintDepth1+","+eintDepth2+","+eintDepth3+")");

   lastTime=Time[0];

   return( 0 );
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return( 0 );
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();

// Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);

   limit=Bars-counted_bars;
   for(i=0,y=0;i<limit;i++)
     {
      if(Time[i]<TimeArray[y]) y++;

      gadblUp1[i]=iCustom(NULL,TimeFrame,"! ! !SemaphorTrue2_MTFBASE",eintDepth1,eintDepth2,eintDepth3,edblOffsetPoints,MaxBars,_alerts,Ball1_Alerts,Ball2_Alerts,Ball3_Alerts,Send_Emails,Show_Popup,0,y);
      gadblUp2[i]=iCustom(NULL,TimeFrame,"! ! !SemaphorTrue2_MTFBASE",eintDepth1,eintDepth2,eintDepth3,edblOffsetPoints,MaxBars,_alerts,Ball1_Alerts,Ball2_Alerts,Ball3_Alerts,Send_Emails,Show_Popup,1,y);
      gadblUp3[i]=iCustom(NULL,TimeFrame,"! ! !SemaphorTrue2_MTFBASE",eintDepth1,eintDepth2,eintDepth3,edblOffsetPoints,MaxBars,_alerts,Ball1_Alerts,Ball2_Alerts,Ball3_Alerts,Send_Emails,Show_Popup,2,y);
      gadblDn1[i]=iCustom(NULL,TimeFrame,"! ! !SemaphorTrue2_MTFBASE",eintDepth1,eintDepth2,eintDepth3,edblOffsetPoints,MaxBars,_alerts,Ball1_Alerts,Ball2_Alerts,Ball3_Alerts,Send_Emails,Show_Popup,3,y);
      gadblDn2[i]=iCustom(NULL,TimeFrame,"! ! !SemaphorTrue2_MTFBASE",eintDepth1,eintDepth2,eintDepth3,edblOffsetPoints,MaxBars,_alerts,Ball1_Alerts,Ball2_Alerts,Ball3_Alerts,Send_Emails,Show_Popup,4,y);
      gadblDn3[i]=iCustom(NULL,TimeFrame,"! ! !SemaphorTrue2_MTFBASE",eintDepth1,eintDepth2,eintDepth3,edblOffsetPoints,MaxBars,_alerts,Ball1_Alerts,Ball2_Alerts,Ball3_Alerts,Send_Emails,Show_Popup,5,y);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string PeriodToStr(int p)
  {
   switch(p)
     {
      case PERIOD_M1: return("M1");
      case PERIOD_M5: return("M5");
      case PERIOD_M15: return("M15");
      case PERIOD_M30: return("M30");
      case PERIOD_H1: return("H1");
      case PERIOD_H4: return("H4");
      case PERIOD_D1: return("D1");
      case PERIOD_W1: return("W1");
      case PERIOD_MN1: return("MN1");
      default: return("" + Period());
     }
  }
//+------------------------------------------------------------------+
