//+------------------------------------------------------------------+
//|                                     OpenPriceLine_TRO_DAY.mq4    +
//+------------------------------------------------------------------+
#property copyright "AHGDP"
#property link      "TRO_CandleOpen_1440M"

#property indicator_chart_window

extern int    TF              = 1440 ;
extern int    CountPeriods    = 5 ;
extern color  Open_colorB     = clrYellow;
extern int    Open_LineStyleB = 0;
extern int    Open_WidthB     = 3;
extern int    WIN_NUM         = 0;

extern int  LineShift_LR       = 0;

extern  bool   ShowCamRight                  = true;
extern int     LevSize                       = 8;
 
string ObjDeslev    = "[LEVDO]";
bool   Deinitialized;  
int    Gap, Chart_Scale;
int    AutShift4;

   datetime time1B;
   datetime time2B;
   double openB,closeB,highB,lowB;
   double valueB ;
   int shift, num ;
//==============================================   
 int init()
  {  
//---------------CANDLE AUTO OR NOT-----------------
     Deinitialized = false; 
  Chart_Scale = ChartScaleGet();
                  
        if(Chart_Scale == 0) {Gap = 125 + LineShift_LR;   AutShift4 = 150; }
  else {if(Chart_Scale == 1) {Gap = 70  + LineShift_LR;   AutShift4 = 85;  }      
  else {if(Chart_Scale == 2) {Gap = 33  + LineShift_LR;   AutShift4 = 40;  } 
  else {if(Chart_Scale == 3) {Gap = 18  + LineShift_LR;   AutShift4 = 22;  }
  else {if(Chart_Scale == 4) {Gap = 9   + LineShift_LR;   AutShift4 = 11;  }
                        else {Gap = 5   + LineShift_LR;   AutShift4 = 6;   }
   }}}}
//-----------------------------------------------      
   return(0);
  }
//===============================================   
int deinit()
{  int obj_total = ObjectsTotal(); 
   for (int i= obj_total; i>=0; i--)
   {   string name = ObjectName(i);   
      if (  (StringSubstr(name,0,7) == ObjDeslev)  ) ObjectDelete(name);
         ObjDel();
   }    
   return(0);
} 
//==============================================
int start()
  {
     int i=0;
     ObjDel();
     num=0;
     
     datetime   levRTime   = 0;
  
  for (shift=CountPeriods;shift>=0;shift--)//CountPeriods-1
  {          
       time1B = iTime(NULL,TF,shift);
          i = shift-1;
    if (i<0) 
         time2B = Time[0]+Period()*60*Gap;
         
   else
        time2B = iTime(NULL,TF,i)-Period()*60;
        //  time2B = time1B + TF*60;
  
         openB = iOpen(NULL,TF,shift);
 
          valueB = openB;

          num = shift;
  
//  if(Show_Open==true)
   {   PlotLine("OpenB["+num+"]",valueB,Open_colorB,Open_LineStyleB,Open_WidthB); 
   }
//=============================================================================== 
levRTime = Time[0]+Period()*60*AutShift4;
  
   if (ShowCamRight == true) 
  {    LevelRight("AWO", "WO",  valueB,   Open_colorB,      levRTime,  LevSize) ;   
  }
//===============================================================================       
  }
   return(0);
  }
//+-------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------+
  void ObjDel()
    {    for (;num<=CountPeriods;num++)
      {  ObjectDelete("OpenC["+num+"]");// ObjectDelete("OpenB["+num+"]"
        
      }
   }
//+-------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------+
    void PlotLine(string nameC,double valueBZ,double line_colorB,double styleB,double widthB)
        {
            ObjectCreate(nameC,OBJ_TREND,WIN_NUM,time1B,valueBZ,time2B,valueBZ);
            ObjectSet(nameC, OBJPROP_WIDTH, widthB);
            ObjectSet(nameC, OBJPROP_STYLE, styleB);
            ObjectSet(nameC, OBJPROP_RAY, false);
          //  ObjectSet(nameC, OBJPROP_BACK, true);
            ObjectSet(nameC, OBJPROP_COLOR, line_colorB);
        }
//+-------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)                                                    
  {
  Chart_Scale = ChartScaleGet();
  init();  
  }
//+-------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------+
int ChartScaleGet()
  {
  long result = -1;
  ChartGetInteger(0,CHART_SCALE,0,result);
  return((int)result);
  }
//+-------------------------------------------------------------------------------------------+
//+-------------------------------------------------------------------------------------------+         
void LevelRight(string labelname4, string des4,  double level4,   color col4,   datetime startlabel4, int Size4)
  {
   string name4= "[LEVDO]" + labelname4; 
    if (      ObjectFind   (name4) == -1      )
          {   ObjectCreate (name4,OBJ_TEXT,0,0,0);
              ObjectSetText(name4, des4,LevSize,"Arial Black",col4);
              ObjectSet    (name4,OBJPROP_TIME1,startlabel4); 
              ObjectSet    (name4,OBJPROP_PRICE1, level4);
             
              ObjectSet    (name4,OBJPROP_ANCHOR,ANCHOR_RIGHT);
              ObjectSet    (name4,OBJPROP_SELECTABLE,false);
          }
  else    {   ObjectCreate (name4,OBJ_TEXT,0,0,0);
              ObjectSetText(name4, des4,LevSize,"Arial Black",col4);
              ObjectSet    (name4,OBJPROP_TIME1,startlabel4);
              ObjectSet    (name4,OBJPROP_PRICE1, level4);
             
              ObjectSet    (name4,OBJPROP_ANCHOR,ANCHOR_RIGHT);
              ObjectSet    (name4,OBJPROP_SELECTABLE,false);
  }      }
//+-------------------------------------------------------------------------------------------+                           
//+------------------------line description-------------------------------------------------+             
