
#property indicator_separate_window

#property indicator_levelcolor Indigo
#property indicator_levelstyle 0
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_level1 8.0
#property indicator_level2 6
#property indicator_level3 -6
#property indicator_level4 -8.0

extern int NumBars = 5;
extern color actual = Black;
extern color up =Green;
extern color down = Red;
extern int Mèches=1;
extern int Corps=3;

double HH[];
double OO[];
double CC[];
double LL[];

int init() {

   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, HH);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, LL);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexBuffer(2, OO);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(3, CC);
   IndicatorShortName("Value Chart");
   return (0);
}

int deinit() {
   Comment("");
   return (0);
}

int start() {
   double ld_12;
   double ld_20;
   double ld_28;
   string Meches;
   string Coprs;
   string ls_0 = "Value Chart";
   int li_8 = WindowFind(ls_0);
   for (int i = 0; i < Bars; i++) {
      ld_12 = 0;
      for (int k = i; k < NumBars + i; k++) ld_12 += (High[k] + Low[k]) / 2.0;
      ld_20 = ld_12 / NumBars;
      ld_12 = 0;
      for (k = i; k < NumBars + i; k++) ld_12 += High[k] - Low[k];
      ld_28 = 0.2 * (ld_12 / NumBars);
      HH[i] = (High[i] - ld_20) / ld_28;
      LL[i] = (Low[i] - ld_20) / ld_28;
      OO[i] = (Open[i] - ld_20) / ld_28;
      CC[i] = (Close[i] - ld_20) / ld_28;
   }
   Sleep(1000);
   ObjectsDeleteAll(li_8);
   for (k = 0; k <= Bars; k++) {
      Meches = "TimingHL" + k;
      ObjectCreate(Meches, OBJ_TREND, li_8, Time[k], HH[k], Time[k], LL[k]);
      ObjectSet(Meches, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(Meches, OBJPROP_RAY, FALSE);
      ObjectSet(Meches, OBJPROP_WIDTH, Mèches);
      Coprs = "TimingOC" + k;
      ObjectCreate(Coprs, OBJ_TREND, li_8, Time[k], OO[k], Time[k], CC[k]);
      ObjectSet(Coprs, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(Coprs, OBJPROP_RAY, FALSE);
      ObjectSet(Coprs, OBJPROP_WIDTH, Corps);
      if (Open[k] <= Close[k]) {
         ObjectSet(Meches, OBJPROP_COLOR, up);
         ObjectSet(Coprs, OBJPROP_COLOR, up);
      } else {
         ObjectSet(Meches, OBJPROP_COLOR, down);
         ObjectSet(Coprs, OBJPROP_COLOR, down);
      }
   }
   ObjectCreate("actual_VCharte", OBJ_HLINE, li_8, 0, CC[0]);
   ObjectSet("actual_Vcharte", OBJPROP_COLOR, actual);
  
   return (0);
}