
#property copyright "Copyright © 2008"
#property link      "www.freedom.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Lime
#property indicator_width1 2

extern bool Show_Price = true;
extern bool Show_Text  = true;

double buf_0[];
int TimeFrame = PERIOD_D1;

int init() {
   SetIndexBuffer(0, buf_0);
   SetIndexStyle(0, DRAW_LINE);
   return (0);
}

int deinit() {
//----
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringFind(label, "D1_Open", 0) < 0)
           continue;
       ObjectDelete(label);
     }   
//----
   return (0);
}

int start()
{
   int shift;
   double O;
   double D1_Open;
   int counted_bars= IndicatorCounted();
   if (counted_bars< 0) return (-1);
   if (counted_bars> 0) counted_bars--;
   int limit = Bars - counted_bars;
   for (int i = limit - 1; i >= 0; i--) 
   {
      shift   = iBarShift(Symbol(), TimeFrame, Time[i], FALSE);
      O       = iOpen(NULL, TimeFrame,shift);
      D1_Open = O;
      
      buf_0[i] = D1_Open;
      if(Show_Price) SetPrice("SD D1_Open", Time[i], D1_Open, DimGray);
      if(Show_Text)  SetText("txtSD D1_Open", "Daily Open", Time[i], D1_Open, indicator_color1);
   }
   return (0);
}

void SetPrice(string name, int datetime_0, double price_0, color color_0) {
   if (ObjectFind(name) == -1) {
      ObjectCreate(name, OBJ_ARROW, 0, datetime_0, price_0);
      ObjectSet(name, OBJPROP_COLOR, color_0);
      ObjectSet(name, OBJPROP_WIDTH, 1);
      ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
      return;
   }
   ObjectSet(name, OBJPROP_TIME1, datetime_0);
   ObjectSet(name, OBJPROP_PRICE1, price_0);
   ObjectSet(name, OBJPROP_COLOR, color_0);
   ObjectSet(name, OBJPROP_WIDTH, 1);
   ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
}

void SetText(string name, string text, int datetime_1, double price_1, color color_1) {
   if (ObjectFind(name) == -1) {
      ObjectCreate(name, OBJ_TEXT, 0, datetime_1, price_1);
      ObjectSetText(name, text, 7, " Tahoma", color_1);
      return;
   }
   ObjectSet(name, OBJPROP_TIME1, datetime_1);
   ObjectSet(name, OBJPROP_PRICE1, price_1);
   ObjectSetText(name, text, 6, "Tahoma", color_1);
}

