#property copyright "Copyright © 2010, sangmane"
#property link      "http://www.forexfactory.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Tomato
#property indicator_color3 Aqua
#property indicator_color4 Gold

extern string Desc="M5:5, M15:15, M30:30, H1:60, H4:240, D1:1440, W1:10080, MN1:43200";
extern int TimeFrame = PERIOD_D1;
extern int LookBack = 0;
extern string Desc2="OHLC: Open High Low Close";
extern string LineList = "HLC";
extern int    extShift = 1;
extern bool   DisplayLabel = True;
double HiLine[],LoLine[],OpLine[],ClLine[];
string TFPrefix;
bool bHigh, bLow, bOpen, bClose;

int init()
{   
  IndicatorBuffers(4);
  SetIndexStyle(0,DRAW_LINE);
  SetIndexStyle(1,DRAW_LINE);
  SetIndexStyle(2,DRAW_LINE);
  SetIndexStyle(3,DRAW_LINE);  
  SetIndexBuffer(0,HiLine);  
  SetIndexBuffer(1,LoLine);
  SetIndexBuffer(2,OpLine);  
  SetIndexBuffer(3,ClLine);  
  TimeFrame = MathMax(Period(),TimeFrame);  
  int Ascii;
  for(int i = 0; i<StringLen(LineList); i++)
  {
    Ascii = StringGetChar(LineList,i);
    if(Ascii>=0x61 && Ascii<=0x7A)
      LineList = StringSetChar(LineList,i,Ascii-0x20);
  }
  bOpen  = StringFind(LineList,"O",0)>=0;
  bHigh  = StringFind(LineList,"H",0)>=0;
  bLow   = StringFind(LineList,"L",0)>=0;
  bClose = StringFind(LineList,"C",0)>=0;
  switch(TimeFrame)
  {
    case PERIOD_M15: TFPrefix = "M15"; break;
    case PERIOD_M30: TFPrefix = "M30"; break;
    case PERIOD_H1: TFPrefix = "H1"; break;
    case PERIOD_H4: TFPrefix = "H4"; break;
    case PERIOD_D1: TFPrefix = "D1"; break;
    case PERIOD_W1: TFPrefix = "W1"; break;
    case PERIOD_MN1: TFPrefix = "MN1"; break;
    default: TFPrefix = "";
  }
  return(0);
}

int deinit()
{
   string LbName;
   for(int i = ObjectsTotal(); i>=0; i--)
   {
     LbName = ObjectName(i);
     if(StringFind(LbName,WindowExpertName()+TFPrefix,0)>=0)
       ObjectDelete(LbName);
   }
}

int start()
{
  if(TFPrefix=="") return(-1);
  int    counted_bars=IndicatorCounted();
  if(counted_bars>0) counted_bars--;
  int i, limit = Bars-counted_bars;
  if(LookBack>0)
    limit = MathMin(LookBack,Bars-counted_bars);
  for(i=limit; i>=0; i--)
  {
    int shift = iBarShift(NULL,TimeFrame,Time[i]);
    if(bHigh)
      HiLine[i] = iHigh(NULL,TimeFrame,shift+extShift);
    if(bLow)
      LoLine[i] = iLow(NULL,TimeFrame,shift+extShift);
    if(bOpen)
      OpLine[i] = iOpen(NULL,TimeFrame,shift+extShift);
    if(bClose)
      ClLine[i] = iClose(NULL,TimeFrame,shift+extShift);    
  }
  if(!DisplayLabel)
    return(0);
  if(bHigh)
    DrawLabel("HIGH",Time[0]+Period()*4*60,HiLine[0]);
  if(bLow)
    DrawLabel("LOW",Time[0]+Period()*4*60,LoLine[0]);    
  if(bOpen)
    DrawLabel("OPEN",Time[0]+Period()*4*60,OpLine[0]);    
  if(bClose)
    DrawLabel("CLOSE",Time[0]+Period()*4*60,ClLine[0]);    
    
  return(0);
}
//+------------------------------------------------------------------+
void DrawLabel(string LineName, datetime time, double level)
{
   string LbName = WindowExpertName()+TFPrefix+LineName;
   if(ObjectFind(LbName)<0)   
     ObjectCreate(LbName,OBJ_TEXT,0,time,level);
   else
     ObjectMove(LbName,0,time,level);   
   ObjectSetText(LbName,TFPrefix+" "+LineName+"="+DoubleToStr(level,Digits),9,"Arial",White);   
}

