//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Indigo
#property indicator_color5 Purple
#property indicator_color6 Maroon
//#property indicator_color7 Black
//#property indicator_color8 White
//#property indicator_width1 6
#property indicator_width1 7
#property indicator_width2 6
#property indicator_width3 5
#property indicator_width4 5
#property indicator_width5 4
#property indicator_width6 3
//#property indicator_width7 3
//#property indicator_width8 1
//---- indicator parameters
extern int MA_Period_1  =500;//47;//233;//1500;
extern int MA_Period_2  =290;//14;//144;//1500;
extern int MA_Period_3  =5;//3;//55;//800;
extern int MA_Period_4  =500;//47;//233;//800;
extern int MA_Period_5  =290;//14;//144;//272;
extern int MA_Period_6  =5;//3;//55;//272;
//extern int MA_Period_7  =120;
//extern int MA_Period_8  =120;
extern bool PriceText   =false;
extern bool EMAlinesOn  =false;
extern bool SteepMeterOn=false;
//---- indicator buffers
double ExtMapBuffer_1[];
double ExtMapBuffer_2[];
double ExtMapBuffer_3[];
double ExtMapBuffer_4[];
double ExtMapBuffer_5[];
double ExtMapBuffer_6[];
//double ExtMapBuffer_7[];
//double ExtMapBuffer_8[];
double MA_P1, MA_P2, MA_P3;
double MA_P1_, MA_P2_, MA_P3_;
double check;
int rat1, rat2, rat3;
//int bartab;
int Pos1T, Pos2T, Pos3T;
int Pos1T_, Pos2T_, Pos3T_;
int PosTag, BarTag;
int Shft1, Shft2, Bars1, Bars2;
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
/*  for(int i=1501; i>0; i--)
  {
  ExtMapBuffer_1[i]=0;
  ExtMapBuffer_2[i]=0;
  ExtMapBuffer_3[i]=0;
  ExtMapBuffer_4[i]=0;
  ExtMapBuffer_5[i]=0;
  ExtMapBuffer_6[i]=0;
  ExtMapBuffer_7[i]=0;
  ExtMapBuffer_8[i]=0;
  }
*/   IndicatorBuffers(8);
   SetIndexLabel(0,"(SMA"+")"+MA_Period_1+")");
   SetIndexLabel(1,"(SMA"+")"+MA_Period_2+")");
   SetIndexLabel(2,"(SMA"+")"+MA_Period_3+")");
   SetIndexLabel(3,"(SMA"+")"+MA_Period_4+")");
   SetIndexLabel(4,"(SMA"+")"+MA_Period_5+")");
   SetIndexLabel(5,"(SMA"+")"+MA_Period_6+")");
//   SetIndexLabel(6,"(SMA"+")"+MA_Period_7+")");
//   SetIndexLabel(7,"(SMA"+")"+MA_Period_8+")");
   SetIndexDrawBegin(0,0);//MA_Period_1);
   SetIndexDrawBegin(1,0);//MA_Period_2);
   SetIndexDrawBegin(2,0);//MA_Period_3);
   SetIndexDrawBegin(3,0);//MA_Period_4);
   SetIndexDrawBegin(4,0);//MA_Period_5);
   SetIndexDrawBegin(5,0);//MA_Period_6);
//   SetIndexDrawBegin(6,0);//MA_Period_7);
//   SetIndexDrawBegin(7,0);//MA_Period_8);
   SetIndexBuffer(0,ExtMapBuffer_1);
   SetIndexBuffer(1,ExtMapBuffer_2);
   SetIndexBuffer(2,ExtMapBuffer_3);
   SetIndexBuffer(3,ExtMapBuffer_4);
   SetIndexBuffer(4,ExtMapBuffer_5);
   SetIndexBuffer(5,ExtMapBuffer_6);
//   SetIndexBuffer(6,ExtMapBuffer_7);
//   SetIndexBuffer(7,ExtMapBuffer_8);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
//   SetIndexStyle(6,DRAW_LINE);
//   SetIndexStyle(7,DRAW_LINE);
   IndicatorDigits(4);
//---- initialization done

   return(0);
  }
  
int deinit()
{
ObjectDelete("1500");
ObjectDelete("0800");
ObjectDelete("0272");
ObjectDelete("0120");
ObjectDelete("MA 1500");
ObjectDelete("MA 800");
ObjectDelete("MA 272");
ObjectDelete("MA 120");
ObjectDelete("StBox_rect1");
ObjectDelete("StBox_rect2");
ObjectDelete("StBox_rect3");
ObjectDelete("StBox_rect4");
ObjectDelete("StBox_rect5");
ObjectDelete("StBox_rect6");
ObjectDelete("StBox_mid1");
ObjectDelete("StBox_bar1");
ObjectDelete("StBox_bar2");
ObjectDelete("StBox_bar3");
ObjectDelete("StBox_bar4");
ObjectDelete("Pos1");
ObjectDelete("Pos2");
ObjectDelete("Pos3");
ObjectDelete("Pos4");
ObjectDelete("Pos1_");
ObjectDelete("Pos2_");
ObjectDelete("Pos3_");
ObjectDelete("Pos4_");
ObjectDelete("Hist1");
ObjectDelete("Hist2");
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
  if(BarTag!=Bars)
   {
    BarTag=Bars;
    PosTag=0;
   }
//   if(Bars<=MA_Period_1) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
//   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
//   if (ExtCountedBars>0) ExtCountedBars--;
//----
   ema1();
   ema2();
   ema3();
   ema4();
   ema5();
   ema6();
//   ema7();
//   ema8();

if(SteepMeterOn==true)
 {
  MA_P1_=ExtMapBuffer_1[100];
  MA_P2_ =ExtMapBuffer_3[100];
  MA_P3_ =ExtMapBuffer_5[100];

  MA_P1 =ExtMapBuffer_1[0];
  MA_P2  =ExtMapBuffer_3[0];
  MA_P3  =ExtMapBuffer_5[0];

   rat1= (MA_P3-MA_P3_)*10000;
   rat2= (MA_P2-MA_P2_)*10000;
   rat3= (MA_P1-MA_P1_)*10000;
   Steepness(rat1,rat2,rat3);
 }
if(EMAlinesOn==true)
{
  MA_P1_=ExtMapBuffer_1[100];
  MA_P1_ =ExtMapBuffer_2[100];
  MA_P1_ =ExtMapBuffer_3[100];

  MA_P1 =ExtMapBuffer_1[0];
  MA_P2  =ExtMapBuffer_3[0];
  MA_P3  =ExtMapBuffer_5[0];

/*  drawlineT("MA 1500",MA_1500_,MA_1500,RoyalBlue,4);
  drawlineT("MA 800",MA_800_,MA_800,Magenta,3);
  drawlineT("MA 272",MA_272_,MA_272,Orange,2);
  drawlineT("MA 120",MA_120_,MA_120,White,1);
*/}

if(PriceText==true)
 {
  placetext(ExtMapBuffer_1[0],"1500",DoubleToStr(ExtMapBuffer_1[0],Digits),indicator_color4);
  placetext(ExtMapBuffer_3[0],"0800",DoubleToStr(ExtMapBuffer_3[0],Digits),indicator_color5);
  placetext(ExtMapBuffer_5[0],"0272",DoubleToStr(ExtMapBuffer_5[0],Digits),indicator_color6);
 }
   return(0);
  }

//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
void ema1()
  {
   double pr=2.0/(MA_Period_1+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer_1[pos+1]=Close[pos+1];
      ExtMapBuffer_1[pos]=Close[pos]*pr+ExtMapBuffer_1[pos+1]*(1-pr);
 	   pos--;
     }
  }

//+------------------------------------------------------------------+
void ema2()
  {
   double pr=2.0/(MA_Period_2+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer_2[pos+1]=Close[pos+1];
      ExtMapBuffer_2[pos]=Close[pos]*pr+ExtMapBuffer_2[pos+1]*(1-pr);
 	   pos--;
     }
  }

//+------------------------------------------------------------------+
void ema3()
  {
   double pr=2.0/(MA_Period_3+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer_3[pos+1]=Close[pos+1];
      ExtMapBuffer_3[pos]=Close[pos]*pr+ExtMapBuffer_3[pos+1]*(1-pr);
 	   pos--;
     }
  }

//+------------------------------------------------------------------+
void ema4()
  {
   double pr=2.0/(MA_Period_4+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer_4[pos+1]=Close[pos+1];
      ExtMapBuffer_4[pos]=Close[pos]*pr+ExtMapBuffer_4[pos+1]*(1-pr);
 	   pos--;
     }
  }

//+------------------------------------------------------------------+
void ema5()
  {
   double pr=2.0/(MA_Period_5+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer_5[pos+1]=Close[pos+1];
      ExtMapBuffer_5[pos]=Close[pos]*pr+ExtMapBuffer_5[pos+1]*(1-pr);
 	   pos--;
     }
  }

//+------------------------------------------------------------------+
void ema6()
  {
   double pr=2.0/(MA_Period_6+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer_6[pos+1]=Close[pos+1];
      ExtMapBuffer_6[pos]=Close[pos]*pr+ExtMapBuffer_6[pos+1]*(1-pr);
 	   pos--;
     }
  }


//+-----------------------------------------------------------------------+
//+-----------------------------------------------------------------------+
void placetext(double price1, string text, string text2, color tcolor)
{
 if(ObjectFind(text)!=0)
  {
   ObjectCreate(text,OBJ_TEXT,0,Time[0],price1);
   ObjectSetText(text,text2, 10, "Times New Roman", tcolor);
  }
 else
   ObjectMove(text,0,Time[0],price1);
   ObjectSetText(text,text2, 10, "Times New Roman", tcolor);
}


//+------------------------------------------------------------------+
void drawlineT(string name, double price1, double price2, color linecolor, int width)
{
  if(ObjectFind(name)!=0)
  {
   ObjectCreate(name, OBJ_TREND, 0, Time[100],price1,Time[0],price2);
   ObjectSet(name, OBJPROP_RAY,0);
   ObjectSet(name, OBJPROP_COLOR,linecolor);
   ObjectSet(name, OBJPROP_WIDTH,width);
   ObjectSet(name, OBJPROP_BACK,0);
  }
  else
  {
   ObjectDelete(name);
   ObjectCreate(name, OBJ_TREND, 0, Time[100],price1,Time[0],price2);
   ObjectSet(name, OBJPROP_RAY,0);
   ObjectSet(name, OBJPROP_COLOR,linecolor);
   ObjectSet(name, OBJPROP_WIDTH,width);
  }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
void Steepness(int rat1, int rat2, int rat3)
{
  int barcount;
  double highest=0, lowest=10000;
  int left, right;
  int mid1;
  int left1, right1;
  int left2, right2;
  int left3, right3;
  int bwidth;
  double bar1, bar2, bar3;
  int bar1i, bar2i, bar3i;
  double top, bottom;
  double top1, bottom1;
  double top2, bottom2;
  double top3, bottom3;
  barcount=WindowFirstVisibleBar();
  for(int pos=0;pos<barcount;pos++)
  {
   highest=MathMax(High[pos],highest);
   lowest=MathMin(Low[pos],lowest);
  }
  top=highest;
  bottom=highest-(highest-lowest)/5;
  left=MathAbs(barcount/4);
  right=MathAbs(left/5);

  top1=(top-(top-bottom)*0.03);
  bottom1=(top-(top-bottom)*0.235); // 100-6=94  96/4=24  24-1=23

  top2=(bottom1-(top-bottom)*0.03);
  bottom2=(top2-(top1-bottom1));

  top3=(bottom2-(top-bottom)*0.03);
  bottom3=(top3-(top1-bottom1));

  left1=MathAbs(left-(left-right)*0.02);
  right1=MathAbs(right+(left-right)*0.02);
  while((left-left1)>(right1-right))
   left1++;
  if((left1-right1)==(left-right))
   {
    left1--;
    right1++;
   }
  if(MathMod((left1-right1),2)!=0)
   {
    left++;
    left1++;
   }
   while((top-top1)<(bottom3-bottom))
    {
     bottom+=(bottom3-bottom)*0.0001;
    }
   mid1=( right1+(left1-right1)/2 );
   bwidth=(left1-right1)/2;
double calc=100;
int xit=0;
int stop=0;
while (xit==0)
 {
stop++;
   bar1=(bwidth*rat1);
   bar1=bar1/calc;
   bar1i=mid1-MathCeil(bar1);

   bar2=(bwidth*rat2);
   bar2=bar2/calc;
   bar2i=mid1-MathCeil(bar2);

   bar3=(bwidth*rat3);
   bar3=bar3/calc;
   bar3i=mid1-MathCeil(bar3);

   if(bar1i>left1 || bar2i>left1 ||
      bar3i>left1 ||
      bar1i<right1 || bar2i<right1 ||
      bar3i<right1
     )
    calc*=1.0001;
   else 
    xit=1;
if(stop==25000)break;
 }

//Comment("Bars ",Bars,"   FirstVisibleBar ",WindowFirstVisibleBar(),"   Rat1 ",rat1,
//        "   Pos1T ",Pos1T,"   Pos1T_ ",Pos1T_,"   Top ",top,"   Bottom ",bottom);


  if(ObjectFind("StBox_bar1")!=0)
  {
   ObjectCreate("StBox_rect2",OBJ_RECTANGLE,0,Time[left],top,Time[right],bottom);
   ObjectSet("StBox_rect2", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect2", OBJPROP_BACK,1);

   ObjectCreate("StBox_bar1",OBJ_RECTANGLE,0,Time[mid1],top1,Time[bar1i],bottom1);
   ObjectSet("StBox_bar1", OBJPROP_COLOR,White);
   ObjectSet("StBox_bar1", OBJPROP_BACK,1);

   ObjectCreate("StBox_bar2",OBJ_RECTANGLE,0,Time[mid1],top2,Time[bar2i],bottom2);
   ObjectSet("StBox_bar2", OBJPROP_COLOR,Orange);
   ObjectSet("StBox_bar2", OBJPROP_BACK,1);

   ObjectCreate("StBox_bar3",OBJ_RECTANGLE,0,Time[mid1],top3,Time[bar3i],bottom3);
   ObjectSet("StBox_bar3", OBJPROP_COLOR,Magenta);
   ObjectSet("StBox_bar3", OBJPROP_BACK,1);

   ObjectCreate("StBox_rect3",OBJ_RECTANGLE,0,Time[left1],top1,Time[right1],bottom1);
   ObjectSet("StBox_rect3", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect3", OBJPROP_BACK,1);

   ObjectCreate("StBox_rect4",OBJ_RECTANGLE,0,Time[left1],top2,Time[right1],bottom2);
   ObjectSet("StBox_rect4", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect4", OBJPROP_BACK,1);

   ObjectCreate("StBox_rect5",OBJ_RECTANGLE,0,Time[left1],top3,Time[right1],bottom3);
   ObjectSet("StBox_rect5", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect5", OBJPROP_BACK,1);

   ObjectCreate("StBox_mid1",OBJ_TREND,0,Time[mid1],top1,Time[mid1],bottom3);
   ObjectSet("StBox_mid1", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_mid1", OBJPROP_BACK,1);
   ObjectSet("StBox_mid1", OBJPROP_WIDTH,2);
   ObjectSet("StBox_mid1", OBJPROP_RAY,0);
   
   if(MathMod(Bars,50)==0 && PosTag==0)
    {
if(Pos3T_>=Pos3T){Shft1=left;Shft2=right;} else{Shft1=right;Shft2=left;}
     Bars1=Bars2;
     Bars2=Bars;
     Pos1T_=Pos1T;
     Pos1T=bar1i;
     Pos2T_=Pos2T;
     Pos2T=bar2i;
     Pos3T_=Pos3T;
     Pos3T=bar3i;
     PosTag=5;
}   
   ObjectCreate("Hist2",OBJ_TEXT,0,Time[Shft2],top1+top1-bottom1);
   ObjectSetText("Hist2",DoubleToStr(Bars2,0), 10, "Times New Roman", Black);
   ObjectCreate("Hist1",OBJ_TEXT,0,Time[Shft1],top1+top1-bottom1);
   ObjectSetText("Hist1",DoubleToStr(Bars1,0), 10, "Times New Roman", Gray);

   ObjectCreate("Hist2",OBJ_TEXT,0,Time[Shft2],top1+top1-bottom1);
   ObjectSetText("Hist2",DoubleToStr(Bars2,0), 10, "Times New Roman", White);
if(Bars1==0 && Bars2==0){Pos1T_=mid1;Pos2T_=mid1;Pos3T_=mid1;
                         Pos1T=mid1;Pos2T=mid1;Pos3T=mid1;}
     ObjectCreate("Pos1_",OBJ_TREND,0,Time[Pos1T_],top1,Time[Pos1T_],bottom1);
     ObjectSet("Pos1_",OBJPROP_COLOR,Gray);
     ObjectSet("Pos1_",OBJPROP_RAY,0);
     ObjectSet("Pos1_",OBJPROP_WIDTH,2);
     ObjectCreate("Pos2_",OBJ_TREND,0,Time[Pos2T_],top2,Time[Pos2T_],bottom2);
     ObjectSet("Pos2_",OBJPROP_COLOR,Gray);
     ObjectSet("Pos2_",OBJPROP_RAY,0);
     ObjectSet("Pos2_",OBJPROP_WIDTH,2);

     ObjectCreate("Pos3_",OBJ_TREND,0,Time[Pos3T_],top3,Time[Pos3T_],bottom3);
     ObjectSet("Pos3_",OBJPROP_COLOR,Gray);
     ObjectSet("Pos3_",OBJPROP_RAY,0);
     ObjectSet("Pos3_",OBJPROP_WIDTH,2);

     ObjectCreate("Pos1",OBJ_TREND,0,Time[Pos1T],top1,Time[Pos1T],bottom1);
     ObjectSet("Pos1",OBJPROP_COLOR,Black);
     ObjectSet("Pos1",OBJPROP_RAY,0);
     ObjectSet("Pos1",OBJPROP_WIDTH,3);

     ObjectCreate("Pos2",OBJ_TREND,0,Time[Pos2T],top2,Time[Pos2T],bottom2);
     ObjectSet("Pos2",OBJPROP_COLOR,Black);
     ObjectSet("Pos2",OBJPROP_RAY,0);
     ObjectSet("Pos2",OBJPROP_WIDTH,3);

     ObjectCreate("Pos3",OBJ_TREND,0,Time[Pos3T],top3,Time[Pos3T],bottom3);
     ObjectSet("Pos3",OBJPROP_COLOR,Black);
     ObjectSet("Pos3",OBJPROP_RAY,0);
     ObjectSet("Pos3",OBJPROP_WIDTH,3);

  }
  else
  {
   ObjectDelete("StBox_rect2");
   ObjectCreate("StBox_rect2",OBJ_RECTANGLE,0,Time[left],top,Time[right],bottom);
   ObjectSet("StBox_rect2", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect2", OBJPROP_BACK,1);
   
   ObjectDelete("StBox_bar1");
   ObjectCreate("StBox_bar1",OBJ_RECTANGLE,0,Time[mid1],top1,Time[bar1i],bottom1);
   ObjectSet("StBox_bar1", OBJPROP_COLOR,White);
   ObjectSet("StBox_bar1", OBJPROP_BACK,1);

   ObjectDelete("StBox_bar2");
   ObjectCreate("StBox_bar2",OBJ_RECTANGLE,0,Time[mid1],top2,Time[bar2i],bottom2);
   ObjectSet("StBox_bar2", OBJPROP_COLOR,Orange);
   ObjectSet("StBox_bar2", OBJPROP_BACK,1);

   ObjectDelete("StBox_bar3");
   ObjectCreate("StBox_bar3",OBJ_RECTANGLE,0,Time[mid1],top3,Time[bar3i],bottom3);
   ObjectSet("StBox_bar3", OBJPROP_COLOR,Magenta);
   ObjectSet("StBox_bar3", OBJPROP_BACK,1);

   ObjectDelete("StBox_rect3");
   ObjectCreate("StBox_rect3",OBJ_RECTANGLE,0,Time[left1],top1,Time[right1],bottom1);
   ObjectSet("StBox_rect3", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect3", OBJPROP_BACK,1);

   ObjectDelete("StBox_rect4");
   ObjectCreate("StBox_rect4",OBJ_RECTANGLE,0,Time[left1],top2,Time[right1],bottom2);
   ObjectSet("StBox_rect4", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect4", OBJPROP_BACK,1);

   ObjectDelete("StBox_rect5");
   ObjectCreate("StBox_rect5",OBJ_RECTANGLE,0,Time[left1],top3,Time[right1],bottom3);
   ObjectSet("StBox_rect5", OBJPROP_COLOR,LightGray);
   ObjectSet("StBox_rect5", OBJPROP_BACK,1);

   if(MathMod(Bars,50)==0 && PosTag==0)
    {
if(Pos3T_>=Pos3T){Shft1=left;Shft2=right;} else{Shft1=right;Shft2=left;}
     Bars1=Bars2;
     Bars2=Bars;
     Pos1T_=Pos1T;
     Pos1T=bar1i;
     Pos2T_=Pos2T;
     Pos2T=bar2i;
     Pos3T_=Pos3T;
     Pos3T=bar3i;
     PosTag=5;
    }
   ObjectDelete("Hist1");
   ObjectCreate("Hist1",OBJ_TEXT,0,Time[Shft1],top1+top1-bottom1);
   ObjectSetText("Hist1",DoubleToStr(Bars1,0), 10, "Times New Roman", Gray);

   ObjectDelete("Hist2");
   ObjectCreate("Hist2",OBJ_TEXT,0,Time[Shft2],top1+top1-bottom1);
   ObjectSetText("Hist2",DoubleToStr(Bars2,0), 10, "Times New Roman", Black);
//     ObjectSet("Hist1",OBJPROP_TIME1,Time[Shft1]);
//     ObjectSet("Hist2",OBJPROP_TIME1,Time[Shft2]);
     ObjectDelete("Pos1_");
     ObjectCreate("Pos1_",OBJ_TREND,0,Time[Pos1T_],top1,Time[Pos1T_],bottom1);
     ObjectSet("Pos1_",OBJPROP_COLOR,Gray);
     ObjectSet("Pos1_",OBJPROP_RAY,0);
     ObjectSet("Pos1_",OBJPROP_WIDTH,2);

     ObjectDelete("Pos2_");
     ObjectCreate("Pos2_",OBJ_TREND,0,Time[Pos2T_],top2,Time[Pos2T_],bottom2);
     ObjectSet("Pos2_",OBJPROP_COLOR,Gray);
     ObjectSet("Pos2_",OBJPROP_RAY,0);
     ObjectSet("Pos2_",OBJPROP_WIDTH,2);

     ObjectDelete("Pos3_");
     ObjectCreate("Pos3_",OBJ_TREND,0,Time[Pos3T_],top3,Time[Pos3T_],bottom3);
     ObjectSet("Pos3_",OBJPROP_COLOR,Gray);
     ObjectSet("Pos3_",OBJPROP_RAY,0);
     ObjectSet("Pos3_",OBJPROP_WIDTH,2);

     ObjectDelete("Pos1");
     ObjectCreate("Pos1",OBJ_TREND,0,Time[Pos1T],top1,Time[Pos1T],bottom1);
     ObjectSet("Pos1",OBJPROP_COLOR,Black);
     ObjectSet("Pos1",OBJPROP_RAY,0);
     ObjectSet("Pos1",OBJPROP_WIDTH,3);

     ObjectDelete("Pos2");
     ObjectCreate("Pos2",OBJ_TREND,0,Time[Pos2T],top2,Time[Pos2T],bottom2);
     ObjectSet("Pos2",OBJPROP_COLOR,Black);
     ObjectSet("Pos2",OBJPROP_RAY,0);
     ObjectSet("Pos2",OBJPROP_WIDTH,3);

     ObjectDelete("Pos3");
     ObjectCreate("Pos3",OBJ_TREND,0,Time[Pos3T],top3,Time[Pos3T],bottom3);
     ObjectSet("Pos3",OBJPROP_COLOR,Black);
     ObjectSet("Pos3",OBJPROP_RAY,0);
     ObjectSet("Pos3",OBJPROP_WIDTH,3);

  }
}
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+