//+------------------------------------------------------------------+
//|        Fractal_radar.mq4                                         |
//|                                                                  |
//|        Shane Lee                                                 |
//|        tradingmail@bigpond.com                                               |
//+------------------------------------------------------------------+
#property indicator_separate_window
//---- input parameters

   extern int search_period = 400;
   extern string font="Arial";
   extern color upper_rows_color= Red;
   extern color price_row_color= BurlyWood;
   extern color lower_rows_color= RoyalBlue;
   extern color period_color=DarkSlateGray;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   label ("sp",65,3);
   ObjectSetText("sp","("+DoubleToStr(search_period,0)+")",8,"Arial",White);
   
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

//---Row headings
   label ("PU5",30,20);
   label ("PU4",30,35);
   label ("PU3",30,50);
   label ("PU2",30,65);
   label ("PU1",30,80);
   label ("P",15,95);
   label ("PD1",30,115);
   label ("PD2",30,130);
   label ("PD3",30,145);
   label ("PD4",30,160);
   label ("PD5",30,175);

   ObjectSetText("PU5",DoubleToStr(Close[0]+Point*5,Digits),10,font,upper_rows_color);
   ObjectSetText("PU4",DoubleToStr(Close[0]+Point*4,Digits),10,font,upper_rows_color);
   ObjectSetText("PU3",DoubleToStr(Close[0]+Point*3,Digits),10,font,upper_rows_color);
   ObjectSetText("PU2",DoubleToStr(Close[0]+Point*2,Digits),10,font,upper_rows_color);
   ObjectSetText("PU1",DoubleToStr(Close[0]+Point,Digits),10,font,upper_rows_color);
   ObjectSetText("P",DoubleToStr(Close[0],Digits),14,font,price_row_color);
   ObjectSetText("PD1",DoubleToStr(Close[0]-Point,Digits),10,font,lower_rows_color);
   ObjectSetText("PD2",DoubleToStr(Close[0]-Point*2,Digits),10,font,lower_rows_color);
   ObjectSetText("PD3",DoubleToStr(Close[0]-Point*3,Digits),10,font,lower_rows_color);
   ObjectSetText("PD4",DoubleToStr(Close[0]-Point*4,Digits),10,font,lower_rows_color);
   ObjectSetText("PD5",DoubleToStr(Close[0]-Point*5,Digits),10,font,lower_rows_color);

//---Column headings
   label ("M1",100,1);
   label ("M5",150,1);
   label ("M15",200,1);
   label ("M30",250,1);
   label ("H1",300,1);
   label ("H4",350,1);
   label ("D1",400,1);
   label ("W1",450,1);
   label ("MN",500,1);

   ObjectSetText("M1","M1",12,font,period_color);
   ObjectSetText("M5","M5",12,font,period_color);
   ObjectSetText("M15","M15",12,font,period_color);
   ObjectSetText("M30","M30",12,font,period_color);
   ObjectSetText("H1","H1",12,font,period_color);
   ObjectSetText("H4","H4",12,font,period_color);
   ObjectSetText("D1","D1",12,font,period_color);
   ObjectSetText("W1","W1",12,font,period_color);
   ObjectSetText("MN","MN",12,font,period_color);

//---Data labels

   label ("PU5_M1",110,20);
   label ("PU5_M5",160,20);
   label ("PU5_M15",210,20);
   label ("PU5_M30",260,20);
   label ("PU5_H1",310,20);
   label ("PU5_H4",360,20);
   label ("PU5_D1",410,20);
   label ("PU5_W1",460,20);
   label ("PU5_MN",510,20);
   
   label ("PU4_M1",110,35);
   label ("PU4_M5",160,35);
   label ("PU4_M15",210,35);
   label ("PU4_M30",260,35);
   label ("PU4_H1",310,35);
   label ("PU4_H4",360,35);
   label ("PU4_D1",410,35);
   label ("PU4_W1",460,35);
   label ("PU4_MN",510,35);

   label ("PU3_M1",110,50);
   label ("PU3_M5",160,50);
   label ("PU3_M15",210,50);
   label ("PU3_M30",260,50);
   label ("PU3_H1",310,50);
   label ("PU3_H4",360,50);
   label ("PU3_D1",410,50);
   label ("PU3_W1",460,50);
   label ("PU3_MN",510,50);

   label ("PU2_M1",110,65);
   label ("PU2_M5",160,65);
   label ("PU2_M15",210,65);
   label ("PU2_M30",260,65);
   label ("PU2_H1",310,65);
   label ("PU2_H4",360,65);
   label ("PU2_D1",410,65);
   label ("PU2_W1",460,65);
   label ("PU2_MN",510,65);

   label ("PU1_M1",110,80);
   label ("PU1_M5",160,80);
   label ("PU1_M15",210,80);
   label ("PU1_M30",260,80);
   label ("PU1_H1",310,80);
   label ("PU1_H4",360,80);
   label ("PU1_D1",410,80);
   label ("PU1_W1",460,80);
   label ("PU1_MN",510,80);

   label ("P_M1",110,95);
   label ("P_M5",160,95);
   label ("P_M15",210,95);
   label ("P_M30",260,95);
   label ("P_H1",310,95);
   label ("P_H4",360,95);
   label ("P_D1",410,95);
   label ("P_W1",460,95);
   label ("P_MN",510,95);

   label ("PD1_M1",110,115);
   label ("PD1_M5",160,115);
   label ("PD1_M15",210,115);
   label ("PD1_M30",260,115);
   label ("PD1_H1",310,115);
   label ("PD1_H4",360,115);
   label ("PD1_D1",410,115);
   label ("PD1_W1",460,115);
   label ("PD1_MN",510,115);

   label ("PD2_M1",110,130);
   label ("PD2_M5",160,130);
   label ("PD2_M15",210,130);
   label ("PD2_M30",260,130);
   label ("PD2_H1",310,130);
   label ("PD2_H4",360,130);
   label ("PD2_D1",410,130);
   label ("PD2_W1",460,130);
   label ("PD2_MN",510,130);

   label ("PD3_M1",110,145);
   label ("PD3_M5",160,145);
   label ("PD3_M15",210,145);
   label ("PD3_M30",260,145);
   label ("PD3_H1",310,145);
   label ("PD3_H4",360,145);
   label ("PD3_D1",410,145);
   label ("PD3_W1",460,145);
   label ("PD3_MN",510,145);

   label ("PD4_M1",110,160);
   label ("PD4_M5",160,160);
   label ("PD4_M15",210,160);
   label ("PD4_M30",260,160);
   label ("PD4_H1",310,160);
   label ("PD4_H4",360,160);
   label ("PD4_D1",410,160);
   label ("PD4_W1",460,160);
   label ("PD4_MN",510,160);

   label ("PD5_M1",110,175);
   label ("PD5_M5",160,175);
   label ("PD5_M15",210,175);
   label ("PD5_M30",260,175);
   label ("PD5_H1",310,175);
   label ("PD5_H4",360,175);
   label ("PD5_D1",410,175);
   label ("PD5_W1",460,175);
   label ("PD5_MN",510,175);


   ObjectSetText("PU5_M1",Frac_counter(5,PERIOD_M1),10,font,upper_rows_color);
   ObjectSetText("PU5_M5",Frac_counter(5,PERIOD_M5),10,font,upper_rows_color);
   ObjectSetText("PU5_M15",Frac_counter(5,PERIOD_M15),10,font,upper_rows_color);
   ObjectSetText("PU5_M30",Frac_counter(5,PERIOD_M30),10,font,upper_rows_color);
   ObjectSetText("PU5_H1",Frac_counter(5,PERIOD_H1),10,font,upper_rows_color);
   ObjectSetText("PU5_H4",Frac_counter(5,PERIOD_H4),10,font,upper_rows_color);
   ObjectSetText("PU5_D1",Frac_counter(5,PERIOD_D1),10,font,upper_rows_color);
   ObjectSetText("PU5_W1",Frac_counter(5,PERIOD_W1),10,font,upper_rows_color);
   ObjectSetText("PU5_MN",Frac_counter(5,PERIOD_MN1),10,font,upper_rows_color);

   ObjectSetText("PU4_M1",Frac_counter(4,PERIOD_M1),10,font,upper_rows_color);
   ObjectSetText("PU4_M5",Frac_counter(4,PERIOD_M5),10,font,upper_rows_color);
   ObjectSetText("PU4_M15",Frac_counter(4,PERIOD_M15),10,font,upper_rows_color);
   ObjectSetText("PU4_M30",Frac_counter(4,PERIOD_M30),10,font,upper_rows_color);
   ObjectSetText("PU4_H1",Frac_counter(4,PERIOD_H1),10,font,upper_rows_color);
   ObjectSetText("PU4_H4",Frac_counter(4,PERIOD_H4),10,font,upper_rows_color);
   ObjectSetText("PU4_D1",Frac_counter(4,PERIOD_D1),10,font,upper_rows_color);
   ObjectSetText("PU4_W1",Frac_counter(4,PERIOD_W1),10,font,upper_rows_color);
   ObjectSetText("PU4_MN",Frac_counter(4,PERIOD_MN1),10,font,upper_rows_color);

   ObjectSetText("PU3_M1",Frac_counter(3,PERIOD_M1),10,font,upper_rows_color);
   ObjectSetText("PU3_M5",Frac_counter(3,PERIOD_M5),10,font,upper_rows_color);
   ObjectSetText("PU3_M15",Frac_counter(3,PERIOD_M15),10,font,upper_rows_color);
   ObjectSetText("PU3_M30",Frac_counter(3,PERIOD_M30),10,font,upper_rows_color);
   ObjectSetText("PU3_H1",Frac_counter(3,PERIOD_H1),10,font,upper_rows_color);
   ObjectSetText("PU3_H4",Frac_counter(3,PERIOD_H4),10,font,upper_rows_color);
   ObjectSetText("PU3_D1",Frac_counter(3,PERIOD_D1),10,font,upper_rows_color);
   ObjectSetText("PU3_W1",Frac_counter(3,PERIOD_W1),10,font,upper_rows_color);
   ObjectSetText("PU3_MN",Frac_counter(3,PERIOD_MN1),10,font,upper_rows_color);

   ObjectSetText("PU2_M1",Frac_counter(2,PERIOD_M1),10,font,upper_rows_color);
   ObjectSetText("PU2_M5",Frac_counter(2,PERIOD_M5),10,font,upper_rows_color);
   ObjectSetText("PU2_M15",Frac_counter(2,PERIOD_M15),10,font,upper_rows_color);
   ObjectSetText("PU2_M30",Frac_counter(2,PERIOD_M30),10,font,upper_rows_color);
   ObjectSetText("PU2_H1",Frac_counter(2,PERIOD_H1),10,font,upper_rows_color);
   ObjectSetText("PU2_H4",Frac_counter(2,PERIOD_H4),10,font,upper_rows_color);
   ObjectSetText("PU2_D1",Frac_counter(2,PERIOD_D1),10,font,upper_rows_color);
   ObjectSetText("PU2_W1",Frac_counter(2,PERIOD_W1),10,font,upper_rows_color);
   ObjectSetText("PU2_MN",Frac_counter(2,PERIOD_MN1),10,font,upper_rows_color);

   ObjectSetText("PU1_M1",Frac_counter(1,PERIOD_M1),10,font,upper_rows_color);
   ObjectSetText("PU1_M5",Frac_counter(1,PERIOD_M5),10,font,upper_rows_color);
   ObjectSetText("PU1_M15",Frac_counter(1,PERIOD_M15),10,font,upper_rows_color);
   ObjectSetText("PU1_M30",Frac_counter(1,PERIOD_M30),10,font,upper_rows_color);
   ObjectSetText("PU1_H1",Frac_counter(1,PERIOD_H1),10,font,upper_rows_color);
   ObjectSetText("PU1_H4",Frac_counter(1,PERIOD_H4),10,font,upper_rows_color);
   ObjectSetText("PU1_D1",Frac_counter(1,PERIOD_D1),10,font,upper_rows_color);
   ObjectSetText("PU1_W1",Frac_counter(1,PERIOD_W1),10,font,upper_rows_color);
   ObjectSetText("PU1_MN",Frac_counter(1,PERIOD_MN1),10,font,upper_rows_color);

   ObjectSetText("P_M1",Frac_counter(0,PERIOD_M1),14,font,price_row_color);
   ObjectSetText("P_M5",Frac_counter(0,PERIOD_M5),14,font,price_row_color);
   ObjectSetText("P_M15",Frac_counter(0,PERIOD_M15),14,font,price_row_color);
   ObjectSetText("P_M30",Frac_counter(0,PERIOD_M30),14,font,price_row_color);
   ObjectSetText("P_H1",Frac_counter(0,PERIOD_H1),14,font,price_row_color);
   ObjectSetText("P_H4",Frac_counter(0,PERIOD_H4),14,font,price_row_color);
   ObjectSetText("P_D1",Frac_counter(0,PERIOD_D1),14,font,price_row_color);
   ObjectSetText("P_W1",Frac_counter(0,PERIOD_W1),14,font,price_row_color);
   ObjectSetText("P_MN",Frac_counter(0,PERIOD_MN1),14,font,price_row_color);

   ObjectSetText("PD1_M1",Frac_counter(-1,PERIOD_M1),10,font,lower_rows_color);
   ObjectSetText("PD1_M5",Frac_counter(-1,PERIOD_M5),10,font,lower_rows_color);
   ObjectSetText("PD1_M15",Frac_counter(-1,PERIOD_M15),10,font,lower_rows_color);
   ObjectSetText("PD1_M30",Frac_counter(-1,PERIOD_M30),10,font,lower_rows_color);
   ObjectSetText("PD1_H1",Frac_counter(-1,PERIOD_H1),10,font,lower_rows_color);
   ObjectSetText("PD1_H4",Frac_counter(-1,PERIOD_H4),10,font,lower_rows_color);
   ObjectSetText("PD1_D1",Frac_counter(-1,PERIOD_D1),10,font,lower_rows_color);
   ObjectSetText("PD1_W1",Frac_counter(-1,PERIOD_W1),10,font,lower_rows_color);
   ObjectSetText("PD1_MN",Frac_counter(-1,PERIOD_MN1),10,font,lower_rows_color);

   ObjectSetText("PD2_M1",Frac_counter(-2,PERIOD_M1),10,font,lower_rows_color);
   ObjectSetText("PD2_M5",Frac_counter(-2,PERIOD_M5),10,font,lower_rows_color);
   ObjectSetText("PD2_M15",Frac_counter(-2,PERIOD_M15),10,font,lower_rows_color);
   ObjectSetText("PD2_M30",Frac_counter(-2,PERIOD_M30),10,font,lower_rows_color);
   ObjectSetText("PD2_H1",Frac_counter(-2,PERIOD_H1),10,font,lower_rows_color);
   ObjectSetText("PD2_H4",Frac_counter(-2,PERIOD_H4),10,font,lower_rows_color);
   ObjectSetText("PD2_D1",Frac_counter(-2,PERIOD_D1),10,font,lower_rows_color);
   ObjectSetText("PD2_W1",Frac_counter(-2,PERIOD_W1),10,font,lower_rows_color);
   ObjectSetText("PD2_MN",Frac_counter(-2,PERIOD_MN1),10,font,lower_rows_color);

   ObjectSetText("PD3_M1",Frac_counter(-3,PERIOD_M1),10,font,lower_rows_color);
   ObjectSetText("PD3_M5",Frac_counter(-3,PERIOD_M5),10,font,lower_rows_color);
   ObjectSetText("PD3_M15",Frac_counter(-3,PERIOD_M15),10,font,lower_rows_color);
   ObjectSetText("PD3_M30",Frac_counter(-3,PERIOD_M30),10,font,lower_rows_color);
   ObjectSetText("PD3_H1",Frac_counter(-3,PERIOD_H1),10,font,lower_rows_color);
   ObjectSetText("PD3_H4",Frac_counter(-3,PERIOD_H4),10,font,lower_rows_color);
   ObjectSetText("PD3_D1",Frac_counter(-3,PERIOD_D1),10,font,lower_rows_color);
   ObjectSetText("PD3_W1",Frac_counter(-3,PERIOD_W1),10,font,lower_rows_color);
   ObjectSetText("PD3_MN",Frac_counter(-3,PERIOD_MN1),10,font,lower_rows_color);

   ObjectSetText("PD4_M1",Frac_counter(-4,PERIOD_M1),10,font,lower_rows_color);
   ObjectSetText("PD4_M5",Frac_counter(-4,PERIOD_M5),10,font,lower_rows_color);
   ObjectSetText("PD4_M15",Frac_counter(-4,PERIOD_M15),10,font,lower_rows_color);
   ObjectSetText("PD4_M30",Frac_counter(-4,PERIOD_M30),10,font,lower_rows_color);
   ObjectSetText("PD4_H1",Frac_counter(-4,PERIOD_H1),10,font,lower_rows_color);
   ObjectSetText("PD4_H4",Frac_counter(-4,PERIOD_H4),10,font,lower_rows_color);
   ObjectSetText("PD4_D1",Frac_counter(-4,PERIOD_D1),10,font,lower_rows_color);
   ObjectSetText("PD4_W1",Frac_counter(-4,PERIOD_W1),10,font,lower_rows_color);
   ObjectSetText("PD4_MN",Frac_counter(-4,PERIOD_MN1),10,font,lower_rows_color);

   ObjectSetText("PD5_M1",Frac_counter(-5,PERIOD_M1),10,font,lower_rows_color);
   ObjectSetText("PD5_M5",Frac_counter(-5,PERIOD_M5),10,font,lower_rows_color);
   ObjectSetText("PD5_M15",Frac_counter(-5,PERIOD_M15),10,font,lower_rows_color);
   ObjectSetText("PD5_M30",Frac_counter(-5,PERIOD_M30),10,font,lower_rows_color);
   ObjectSetText("PD5_H1",Frac_counter(-5,PERIOD_H1),10,font,lower_rows_color);
   ObjectSetText("PD5_H4",Frac_counter(-5,PERIOD_H4),10,font,lower_rows_color);
   ObjectSetText("PD5_D1",Frac_counter(-5,PERIOD_D1),10,font,lower_rows_color);
   ObjectSetText("PD5_W1",Frac_counter(-5,PERIOD_W1),10,font,lower_rows_color);
   ObjectSetText("PD5_MN",Frac_counter(-5,PERIOD_MN1),10,font,lower_rows_color);

   return(0);
  }
//+----

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int deinit()
  {
//----

   
//----
   return(0);
  }
//+---------------------------------------------------   
   string Frac_counter(int Price_level,int Timeframe)
   {
    int i=search_period;
    int count=0;
    double uptest,downtest;
    string count_s;
    while (i>=0)
      {
       uptest=iFractals(NULL,Timeframe,MODE_UPPER,i);
       if (uptest==Close[0]+Price_level*Point) count++;
       downtest=iFractals(NULL,Timeframe,MODE_LOWER,i);
       if (downtest==Close[0]+Price_level*Point) count++;
      i--;
      }
    if(count==0) count_s="";
    else count_s = DoubleToStr(count,0);
    return(count_s);
   }
//-----------------------------------------------------
   void label(string name,int X,int Y)
   {
    ObjectCreate(name,OBJ_LABEL,1,0,0);
    ObjectSet(name,OBJPROP_XDISTANCE,X);
    ObjectSet(name,OBJPROP_YDISTANCE,Y);
   }