#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 SteelBlue
#property indicator_color2 DarkSlateGray
#property indicator_color3 Gainsboro
#property indicator_color4 C'60,30,90'
#property indicator_color5 RoyalBlue
#property indicator_color6 BlueViolet
#property indicator_color7 Navy
#property indicator_color8 Indigo

#property indicator_width1 3
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 3
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 1
#property indicator_width8 4

#property indicator_minimum 0
#property indicator_maximum 2
//---- indicator parameters
extern bool AlertsOn=false;
extern int TimeFrame=5;
extern int TimeFrame1=30;
extern int BarCount=3;

//---- indicator buffers
double Signal[];
double Signal1[];
double tf1Setup[];
double tf2Setup[];
double twos[], uptf1[], dntf1[], uptf2[], dntf2[];

datetime LastAlert;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers (8);
   IndicatorDigits ( 5 );
  SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,Signal);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"Signal");
   
  SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexArrow(1,159);
   SetIndexBuffer(1,Signal1);
   SetIndexEmptyValue(1,0.0);
   SetIndexLabel(1,"Signal1");
   
  SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexArrow(2,159);
   SetIndexBuffer(2,tf1Setup);
   SetIndexEmptyValue(2,0.0);
   SetIndexLabel(2,"tf1Setup");
   
   SetIndexStyle(3,DRAW_NONE);
   SetIndexArrow(3,159);
   SetIndexBuffer(3,tf2Setup);
   SetIndexEmptyValue(3,0.0);
   SetIndexLabel(3,"tf2Setup");
   
   SetIndexStyle(4,DRAW_NONE);
   SetIndexArrow(4,159);
   SetIndexBuffer(4,uptf1);
   SetIndexEmptyValue(4,0.0);
   SetIndexLabel(4,"uptf1");
     
  SetIndexStyle(5,DRAW_NONE);
   SetIndexArrow(5,233);
   SetIndexBuffer(5,dntf1);
   SetIndexEmptyValue(5,0.0);
   SetIndexLabel(5,"dntf1");
   
   SetIndexStyle(6,DRAW_NONE);
   SetIndexArrow(6,234);
   SetIndexBuffer(6,uptf2);
   SetIndexEmptyValue(6,0.0);
   SetIndexLabel(6,"uptf2");
   
   SetIndexStyle(7,DRAW_NONE);
   SetIndexArrow(7,233);
   SetIndexBuffer(7,dntf2);
   SetIndexEmptyValue(7,0.0);
   SetIndexLabel(7,"dntf2");
   
  
   LastAlert=Time[0];
   
   
   switch(TimeFrame)
   {
      case 1 : string TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe";
   } 
   
    switch(TimeFrame1)
   {
      case 1 : string TimeFrameStr1="Period_M1"; break;
      case 5 : TimeFrameStr1="Period_M5"; break;
      case 15 : TimeFrameStr1="Period_M15"; break;
      case 30 : TimeFrameStr1="Period_M30"; break;
      case 60 : TimeFrameStr1="Period_H1"; break;
      case 240 : TimeFrameStr1="Period_H4"; break;
      case 1440 : TimeFrameStr1="Period_D1"; break;
      case 10080 : TimeFrameStr1="Period_W1"; break;
      case 43200 : TimeFrameStr1="Period_MN1"; break;
      default : TimeFrameStr1="Current Timeframe";
   } 

  IndicatorShortName("updowns_mtf");
//---- initialization done
   return(0);
  }
  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,shift,limit,y=0,counted_bars=IndicatorCounted();
   
// Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame1); 
   
   limit=BarCount;
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++; 
   
   uptf1[i]=iCustom(NULL,TimeFrame,"updown",0,y+1);
   dntf1[i]=iCustom(NULL,TimeFrame,"updown",1,y+1);
   uptf2[i]=iCustom(NULL,TimeFrame1,"updown",0,y+1);
   dntf2[i]=iCustom(NULL,TimeFrame1,"updown",1,y+1);
   }

  
  double up1, dn1, prevup1, prevdn1;   
  for (i=0; i>=0; i--)
   {     
    up1=iCustom(NULL,0,"updown",0,i);
    dn1=iCustom(NULL,0,"updown",1,i);
    prevup1=iCustom(NULL,0,"updown",0,i+1);
    prevdn1=iCustom(NULL,0,"updown",1,i+1);
    
    Signal[i]=0;
    tf1Setup[i]=0;
    tf2Setup[i]=0;
    Signal1[i]=0;
   
           
    if (uptf1[i]==1) tf1Setup[i]=1;
    if (dntf1[i]==1) tf1Setup[i]=2;
    if (uptf2[i]==1) tf2Setup[i]=1;
    if (dntf2[i]==1) tf2Setup[i]=2;
    if (uptf1[i]==1 && Close[i]>Open[i]) Signal[i]=1;
    if (dntf1[i]==1 && Close[i]<Open[i]) Signal[i]=2;
    if (Close[i]>Open[i] && Close[i+1]>Open[i+1]) Signal1[i]=1;
    if (Close[i]<Open[i] && Close[i+1]<Open[i+1]) Signal1[i]=2;
    
    
       
      
     }
  return(0);
  }    