
#property copyright " "
#property link      ""

#property indicator_chart_window

extern int CountDays = 1;
extern bool Plot_pivots = TRUE;
extern bool Plot_middle = TRUE;
extern bool Plot_camarilla = FALSE;
int g_datetime_92;
int g_datetime_96;
double g_iopen_100;
double g_iclose_108;
double g_ihigh_116;
double g_ilow_124;
double gd_132;
double gd_140;
double gd_148;
double gd_156;
double gd_164;
double gd_172;
double gd_180;
double gd_188;
double gd_196;
double gd_204;
double gd_212;
double gd_220;
double gd_228;
double gd_236;
double gd_244;
double gd_252;
double gd_260;
double gd_268;
double gd_276;
double gd_284;
double gd_292;
double gd_300;
double gd_308;
double gd_316;
double gd_324;
int gi_332;
int g_count_336;

void ObjDel() {
   while (g_count_336 <= CountDays) {
      ObjectDelete("PP[" + g_count_336 + "]");
      ObjectDelete("R1[" + g_count_336 + "]");
      ObjectDelete("R2[" + g_count_336 + "]");
      ObjectDelete("R3[" + g_count_336 + "]");
      ObjectDelete("S1[" + g_count_336 + "]");
      ObjectDelete("S2[" + g_count_336 + "]");
      ObjectDelete("S3[" + g_count_336 + "]");
      ObjectDelete("M0[" + g_count_336 + "]");
      ObjectDelete("M1[" + g_count_336 + "]");
      ObjectDelete("M2[" + g_count_336 + "]");
      ObjectDelete("M3[" + g_count_336 + "]");
      ObjectDelete("M4[" + g_count_336 + "]");
      ObjectDelete("M5[" + g_count_336 + "]");
      ObjectDelete("H1[" + g_count_336 + "]");
      ObjectDelete("H2[" + g_count_336 + "]");
      ObjectDelete("H3[" + g_count_336 + "]");
      ObjectDelete("H4[" + g_count_336 + "]");
      ObjectDelete("L1[" + g_count_336 + "]");
      ObjectDelete("L2[" + g_count_336 + "]");
      ObjectDelete("L3[" + g_count_336 + "]");
      ObjectDelete("L4[" + g_count_336 + "]");
      g_count_336++;
   }
}

void PlotLine(string a_name_0, double a_price_8, double a_color_16, double a_style_24) {
   ObjectCreate(a_name_0, OBJ_TREND, 0, g_datetime_92, a_price_8, g_datetime_96, a_price_8);
   ObjectSet(a_name_0, OBJPROP_WIDTH, 1);
   ObjectSet(a_name_0, OBJPROP_STYLE, a_style_24);
   ObjectSet(a_name_0, OBJPROP_RAY, FALSE);
   ObjectSet(a_name_0, OBJPROP_BACK, TRUE);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_16);
}

int init() {
   return (0);
}

int deinit() {
   ObjDel();
   Comment("");
   return (0);
}

int start() {
   int li_0;
   ObjDel();
   g_count_336 = 0;
   for (gi_332 = CountDays - 1; gi_332 >= 0; gi_332--) {
      g_datetime_92 = iTime(NULL, PERIOD_D1, gi_332);
      li_0 = gi_332 - 1;
      if (li_0 < 0) g_datetime_96 = Time[0];
      else g_datetime_96 = iTime(NULL, PERIOD_D1, li_0) - 60 * Period();
      g_ihigh_116 = iHigh(NULL, PERIOD_D1, gi_332 + 1);
      g_ilow_124 = iLow(NULL, PERIOD_D1, gi_332 + 1);
      g_iopen_100 = iOpen(NULL, PERIOD_D1, gi_332 + 1);
      g_iclose_108 = iClose(NULL, PERIOD_D1, gi_332 + 1);
      gd_132 = (g_ihigh_116 + g_ilow_124 + g_iclose_108) / 3.0;
      gd_140 = 2.0 * gd_132 - g_ilow_124;
      gd_148 = gd_132 + (g_ihigh_116 - g_ilow_124);
      gd_156 = 2.0 * gd_132 + (g_ihigh_116 - 2.0 * g_ilow_124);
      gd_164 = 2.0 * gd_132 - g_ihigh_116;
      gd_172 = gd_132 - (g_ihigh_116 - g_ilow_124);
      gd_180 = 2.0 * gd_132 - (2.0 * g_ihigh_116 - g_ilow_124);
      gd_188 = (gd_172 + gd_180) / 2.0;
      gd_196 = (gd_164 + gd_172) / 2.0;
      gd_204 = (gd_132 + gd_164) / 2.0;
      gd_212 = (gd_132 + gd_140) / 2.0;
      gd_220 = (gd_140 + gd_148) / 2.0;
      gd_228 = (gd_148 + gd_156) / 2.0;
      gd_300 = g_ihigh_116 - g_ilow_124;
      gd_260 = g_iclose_108 + 1.1 * gd_300 / 2.0;
      gd_252 = g_iclose_108 + 1.1 * gd_300 / 4.0;
      gd_244 = g_iclose_108 + 1.1 * gd_300 / 6.0;
      gd_236 = g_iclose_108 + 1.1 * gd_300 / 12.0;
      gd_268 = g_iclose_108 - 1.1 * gd_300 / 12.0;
      gd_276 = g_iclose_108 - 1.1 * gd_300 / 6.0;
      gd_284 = g_iclose_108 - 1.1 * gd_300 / 4.0;
      gd_292 = g_iclose_108 - 1.1 * gd_300 / 2.0;
      g_datetime_96 = g_datetime_92 + 86400;
      gd_308 = 0;
      gd_316 = 3;
      gd_324 = 1;
      g_count_336 = gi_332;
      PlotLine("PP[" + g_count_336 + "]", gd_132, Yellow, gd_308);
      if (Plot_pivots) {
         PlotLine("R1[" + g_count_336 + "]", gd_140, RoyalBlue, gd_308);
         PlotLine("R2[" + g_count_336 + "]", gd_148, RoyalBlue, gd_308);
         PlotLine("R3[" + g_count_336 + "]", gd_156, RoyalBlue, gd_308);
         PlotLine("S1[" + g_count_336 + "]", gd_164, Maroon, gd_308);
         PlotLine("S2[" + g_count_336 + "]", gd_172, Maroon, gd_308);
         PlotLine("S3[" + g_count_336 + "]", gd_180, Maroon, gd_308);
      }
      if (Plot_middle) {
         PlotLine("M0[" + g_count_336 + "]", gd_188, LightGray, gd_316);
         PlotLine("M1[" + g_count_336 + "]", gd_196, LightGray, gd_316);
         PlotLine("M2[" + g_count_336 + "]", gd_204, LightGray, gd_316);
         PlotLine("M3[" + g_count_336 + "]", gd_212, LightGray, gd_316);
         PlotLine("M4[" + g_count_336 + "]", gd_220, LightGray, gd_316);
         PlotLine("M5[" + g_count_336 + "]", gd_228, LightGray, gd_316);
      }
      if (Plot_camarilla) {
         PlotLine("H4[" + g_count_336 + "]", gd_260, LightBlue, gd_324);
         PlotLine("H3[" + g_count_336 + "]", gd_252, DeepSkyBlue, gd_324);
         PlotLine("H2[" + g_count_336 + "]", gd_244, MediumSlateBlue, gd_324);
         PlotLine("H1[" + g_count_336 + "]", gd_236, RoyalBlue, gd_324);
         PlotLine("L1[" + g_count_336 + "]", gd_268, Chocolate, gd_324);
         PlotLine("L2[" + g_count_336 + "]", gd_276, Orange, gd_324);
         PlotLine("L3[" + g_count_336 + "]", gd_284, Goldenrod, gd_324);
         PlotLine("L4[" + g_count_336 + "]", gd_292, Yellow, gd_324);
      }
   }
   return (0);
}