//+------------------------------------------------------------------+
//|                                         TrendBolt_my_corners.mq4 |
//|                                    Copyright © 2011, Tudor Ceban |
//|                            http://www.worldclasstradingstars.com |
//+------------------------------------------------------------------+
#property copyright "Tudor Ceban"
#property link      "www.worldclasstradingstars.com"

// Corner selection modification added by bdeyes at mql4.com October 20, 2011

#property indicator_chart_window

//---- External inputs
extern string txt = " === Moving Averages Settings === ";
extern int FastMA = 5;
extern int SlowMA = 10;
extern int MovAvgType = 0;
extern string txt1 = " === MACD Settings === ";
extern int MACDFastEma = 12;
extern int MACDSlowEma = 26;
extern int MACDSMA = 9;
extern string txt2 = " === Stochastic Settings === ";
extern int KPeriod = 9;
extern int DPeriod = 4;
extern int Slowing = 3;
extern bool ShowM1 = FALSE;
extern bool ShowM5 = FALSE;
extern bool ShowM15 = FALSE;
extern bool ShowM30 = TRUE;
extern bool ShowH1 = TRUE;
extern bool ShowH4 = TRUE;
extern bool ShowD1 = FALSE;
extern color TextColor = C'70,70,70';
extern color UpTrendColor = LimeGreen;
extern color DownTrendColor = FireBrick;
extern string txt3 = " Select display corner # 0-3 ";
extern ENUM_BASE_CORNER Display_corner = CORNER_LEFT_UPPER;
extern int OffsetX = 0;
extern int OffsetY = 15;
extern int WindowNo = 1;

int FontSize = 10;
int FontSizeArrows = 12;

//---- Variables
int time_array[7] = {0, 0, 0, 0, 0, 0, 0};
int calculation_array[7] = {2, 4, 7, 10, 12, 15, 20};
int up_force_total;
int down_force_total;
int display_total_count;
int x_display_1;
int x_display_2;
int x_display_3;
int x_display_4;
int x_display_5;
int x_display_6;
int x_display_7;
int x_display_8;
int x_display_9;
int x_display_10;
int x_display_11;
int x_display_12;
int x_display_13;
int y_display_1;//Logo 1
int y_display_2;//Logo 2
int y_display_3;//Logo 3
int y_display_4;//Logo 4
int y_display_5;//Header
int y_display_6;//line
int y_display_7;//ma
int y_display_8;//ma arrows
int y_display_9;//macd
int y_display_10;//macd arrows
int y_display_11;//stoch
int y_display_12;//stoch arrows
int y_display_13;//total


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
   if (Display_corner == 2 || Display_corner == 3)// x axis (time) adjustment
      {
//      x_display_1 = 265;//Logo 1
//      x_display_2 = 251;//Logo 2
//      x_display_3 = 236;//Logo 3
//      x_display_4 = 226;//Logo 4
      
      x_display_5 = 155;//Header
      x_display_6 = 145;//line
      x_display_7 = 125;//ma
      x_display_8 = 105;//ma arrows
      x_display_9 = 85;//macd
      x_display_10 = 65;//macd arrows
      x_display_11 = 45;//stoch
      x_display_12 = 25;//stoch arrows
      x_display_13 = 5;//total
      }
   else
      {
//      x_display_1 = 1;//Logo 1
//      x_display_2 = 17;//Logo 2
//      x_display_3 = 35;//Logo 3
//      x_display_4 = 45;//Logo 4

      x_display_5 = 0+OffsetY;//Header
      x_display_6 = 5+OffsetY;//line
      x_display_7 = 25+OffsetY;//ma
      x_display_8 = 45+OffsetY;//ma arrows
      x_display_9 = 65+OffsetY;//macd
      x_display_10 = 85+OffsetY;//macd arrows
      x_display_11 = 105+OffsetY;//stoch
      x_display_12 = 125+OffsetY;//stoch arrows
      x_display_13 = 145+OffsetY;//total
      }
      
      if (Display_corner == 0 || Display_corner == 2)// y axis (price) adjustment
      {
//      y_display_1 = 20;//Logo 1
//      y_display_2 = 60;//Logo 2
//      y_display_3 = 15;//Logo 3
//      y_display_4 = 20;//Logo 4

      y_display_5 = 6+OffsetX;//Header
      y_display_6 = 6+OffsetX;//line
      y_display_7 = 12+OffsetX;//ma
      y_display_8 = 10+OffsetX;//ma arrows
      y_display_9 = 12+OffsetX;//macd
      y_display_10 = 10+OffsetX;//macd arrows
      y_display_11 = 12+OffsetX;//stoch
      y_display_12 = 10+OffsetX;//stoch arrows
      y_display_13 = 12+OffsetX;//total
      }
   else
      {
//      y_display_1 = 20+OffsetX;//Logo 1
//      y_display_2 = 60+OffsetX;//Logo 2
//      y_display_3 = 15+OffsetX;//Logo 3
//      y_display_4 = 20+OffsetX;//Logo 4
      
      y_display_5 = 1+OffsetX;//Header
      y_display_6 = 1+OffsetX;//line
      y_display_7 = 10+OffsetX;//ma
      y_display_8 = 15+OffsetX;//ma arrows
      y_display_9 = 10+OffsetX;//macd
      y_display_10 = 15+OffsetX;//macd arrows
      y_display_11 = 10+OffsetX;//stoch
      y_display_12 = 15+OffsetX;//stoch arrows
      y_display_13 = 10+OffsetX;//total
      }
      
   ArrayInitialize(time_array, 0);
   display_total_count = 0;
   string column_header = " ";
   string column_underline = "";
   string column_spacing = "";
   if (ShowM1) {
      time_array[0] = 1;
      column_header = column_header + "M1   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   if (ShowM5) {
      time_array[1] = 5;
      column_header = column_header + "M5   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   if (ShowM15) {
      time_array[2] = 15;
      column_header = column_header + "M15   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   if (ShowM30) {
      time_array[3] = 30;
      column_header = column_header + "M30   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   if (ShowH1) {
      time_array[4] = 60;
      column_header = column_header + "H1   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   if (ShowH4) {
      time_array[5] = 240;
      column_header = column_header + "H4   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   if (ShowD1) {
      time_array[6] = 1440;
      column_header = column_header + "D1   ";
      column_underline = column_underline + "____";
      column_spacing = column_spacing + " ";
      display_total_count++;
   }
   for (int row_count = 0; row_count < display_total_count * 2 / 3; row_count++) {
      column_underline = column_underline + "_";
      column_spacing = column_spacing + " ";
   }
   column_underline = column_underline + "  ";
//   objectCreate("TCTF_Logo1", y_display_1, x_display_1, "=================", 12, "Verdana", TextColor); // x = time (10), y = price (1)
//   objectCreate("TCTF_Logo2", y_display_2, x_display_2, "  Trend BOLT    ", 12, "Verdana", TextColor);
//   objectCreate("TCTF_Logo3", y_display_3, x_display_3, "www.worldclasstradingstars.com ", 10, "Verdana", TextColor);
///   objectCreate("TCTF_Logo4", y_display_4, x_display_4, "=================", 12, "Verdana", TextColor);

   
   CreateLabel("TCTF_Header",column_header,y_display_5, x_display_5, "", 0, 0);
   CreateLabel("TCTF_line",column_underline,y_display_6, x_display_6, "", 0, 0);
   CreateLabel("TCTF_ma","MovAvg (" + FastMA + " vs " + SlowMA + ")",y_display_7, x_display_7, "", 0, 0);
   CreateLabel("TCTF_macd","MACD (" + MACDFastEma + "," + MACDSlowEma + "," + MACDSMA + ")",y_display_9, x_display_9, "", 0, 0);
   CreateLabel("TCTF_stoch","Stochastic (" + KPeriod + "," + DPeriod + "," + Slowing + ")",y_display_11, x_display_11, "", 0, 0);
   CreateLabel("TCTF_total","00 % Trend ",y_display_13, x_display_13, "", 0, 0);

//   objectCreate("TCTF_Header", y_display_5, x_display_5, column_header, FontSize, "Verdana", TextColor);
//   objectCreate("TCTF_line", y_display_6, x_display_6, column_underline, FontSize, "Verdana", TextColor);
//   objectCreate("TCTF_ma", y_display_7, x_display_7, "MovAvg (" + FastMA + " vs " + SlowMA + ")", FontSize, "Verdana", TextColor);
//   objectCreate("TCTF_macd", y_display_9, x_display_9, "MACD (" + MACDFastEma + "," + MACDSlowEma + "," + MACDSMA + ")", FontSize, "Verdana", TextColor);
//   objectCreate("TCTF_stoch", y_display_11, x_display_11, "Stochastic (" + KPeriod + "," + DPeriod + "," + Slowing + ")", FontSize, "Verdana", TextColor);
//   objectCreate("TCTF_total", y_display_13, x_display_13, "00 % Trend ", FontSize+1, "Verdana", TextColor);
   int column_count = 0;
   for (int columns = 1; columns <= 7; columns++) {
      if (time_array[columns - 1] != 0) {
         column_count++;
         CreateLabel("TCTFMA_" + columns,CharToStr(236),38 * (display_total_count - column_count) + y_display_8, x_display_8, "Wingdings", FontSizeArrows, TextColor);
         CreateLabel("TCTFMACD_" + columns,CharToStr(236),38 * (display_total_count - column_count) + y_display_10, x_display_10, "Wingdings", FontSizeArrows, TextColor);
         CreateLabel("TCTFS_" + columns,CharToStr(236),38 * (display_total_count - column_count) + y_display_12, x_display_12, "Wingdings", FontSizeArrows, TextColor);
  
//         objectCreate("TCTFMA_" + columns, 38 * (display_total_count - column_count) + y_display_8, x_display_8, CharToStr(236), FontSizeArrows, "Wingdings", DownTrendColor);
//         objectCreate("TCTFMACD_" + columns, 38 * (display_total_count - column_count) + y_display_10, x_display_10, CharToStr(236), FontSizeArrows, "Wingdings", DownTrendColor);
//         objectCreate("TCTFS_" + columns, 38 * (display_total_count - column_count) + y_display_12, x_display_12, CharToStr(236), FontSizeArrows, "Wingdings", DownTrendColor);
      }
   }
   return (0);
}


void CreateLabel(string aLabelName, string aLabelText, int aXDISTANCE, int aYDISTANCE, string aFontName, int aFontSize, color aColor)
{
  if (aFontName=="") aFontName="Verdana";
  if (aFontSize==0) aFontSize=FontSize;
  if (aColor==0) aColor=TextColor;

   ObjectDelete(aLabelName);
   ObjectCreate(aLabelName, OBJ_LABEL, WindowNo, 0, 1.0);
   ObjectSet(aLabelName, OBJPROP_CORNER, Display_corner);
   ObjectSet(aLabelName, OBJPROP_XDISTANCE, aXDISTANCE);
   ObjectSet(aLabelName, OBJPROP_YDISTANCE, aYDISTANCE);
   ObjectSetText(aLabelName, aLabelText, aFontSize, "Verdana", aColor);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
   int objects_total;
   string objects_name = "";
   bool objects_delete = TRUE;
   while (objects_delete) {
      objects_delete = FALSE;
      objects_total = ObjectsTotal();
      for (int i = 0; i < objects_total; i++) {
         objects_name = ObjectName(i);
         if (StringFind(objects_name, "TCTF") != -1) {
            ObjectDelete(objects_name);
            objects_delete = TRUE;
         }
      }
   }
   return (0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   up_force_total = 0;
   down_force_total = 0;
   for (int column_count = 1; column_count <= 7; column_count++)
      if (time_array[column_count - 1] != 0) update_all(time_array[column_count - 1], column_count);
   if (up_force_total > down_force_total) ObjectSetText("TCTF_total", DoubleToStr(100 * up_force_total / (up_force_total + down_force_total), 0) + "% UpTrend ", FontSize+1, "Verdana", UpTrendColor);
   else ObjectSetText("TCTF_total", DoubleToStr(100 * down_force_total / (up_force_total + down_force_total), 0) + "% DownTrend ", FontSize+1, "Verdana", DownTrendColor);
   return (0);
}

//+------------------------------------------------------------------+
//| objectCreate function                                            |
//+------------------------------------------------------------------+
void objectCreate(string name_value, int x_value, int y_value, string text_value = "", int font_size = 12, string font_name = "Arial", color passed_color = -1) {
   ObjectCreate(name_value, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name_value, OBJPROP_CORNER, Display_corner);
   ObjectSet(name_value, OBJPROP_COLOR, passed_color);
   ObjectSet(name_value, OBJPROP_XDISTANCE, x_value);
   ObjectSet(name_value, OBJPROP_YDISTANCE, y_value);
   ObjectSetText(name_value, text_value, font_size, font_name, passed_color);
}

//+------------------------------------------------------------------+
//| update_all function                                              |
//+------------------------------------------------------------------+
void update_all(int calc_timeframe, int column_number) {
   double MA_fast = iMA(Symbol(), calc_timeframe, FastMA, 0, MovAvgType, PRICE_CLOSE, 0);
   double MA_slow = iMA(Symbol(), calc_timeframe, SlowMA, 0, MovAvgType, PRICE_CLOSE, 0);
   if (MA_fast > MA_slow) {
      ObjectSetText("TCTFMA_" + column_number, CharToStr(236), FontSizeArrows, "Wingdings", UpTrendColor);
      up_force_total += calculation_array[column_number - 1];
   } else {
      ObjectSetText("TCTFMA_" + column_number, CharToStr(238), FontSizeArrows, "Wingdings", DownTrendColor);
      down_force_total += calculation_array[column_number - 1];
   }
   double macd_main = iMACD(Symbol(), calc_timeframe, MACDFastEma, MACDSlowEma, MACDSMA, PRICE_CLOSE, MODE_MAIN, 0);
   double macd_signal = iMACD(Symbol(), calc_timeframe, MACDFastEma, MACDSlowEma, MACDSMA, PRICE_CLOSE, MODE_SIGNAL, 0);
   if (macd_main > macd_signal) {
      ObjectSetText("TCTFMACD_" + column_number, CharToStr(236), FontSizeArrows, "Wingdings", UpTrendColor);
      up_force_total += calculation_array[column_number - 1];
   } else {
      ObjectSetText("TCTFMACD_" + column_number, CharToStr(238), FontSizeArrows, "Wingdings", DownTrendColor);
      down_force_total += calculation_array[column_number - 1];
   }
   double stochastic_main = iStochastic(Symbol(), calc_timeframe, KPeriod, DPeriod, Slowing, MODE_SMA, 0, MODE_MAIN, 0);
   double stochastic_signal = iStochastic(Symbol(), calc_timeframe, KPeriod, DPeriod, Slowing, MODE_SMA, 0, MODE_SIGNAL, 0);
   if (stochastic_main > stochastic_signal) {
      ObjectSetText("TCTFS_" + column_number, CharToStr(236), FontSizeArrows, "Wingdings", UpTrendColor);
      up_force_total += calculation_array[column_number - 1];
      return;
   }
   ObjectSetText("TCTFS_" + column_number, CharToStr(238), FontSizeArrows, "Wingdings", DownTrendColor);
   down_force_total += calculation_array[column_number - 1];
}

//+------------------------------------------------------------------+
//|                           THE END                                |
//+------------------------------------------------------------------+