How To Make My indicator update remove drawings after moving my anchor line?

 

Hello,

I am creating a four anchored vwap for analysing tops and bottoms ,I made the indicator but the problem is that when I move the anchored line forwared than it's first position it doesn't remove the previous drawn line,But it keeps it with only calculations of the weighted average price for each bar..
is there any way to make the indicator update itself when I move the indicator forward to remove the previous drawn line..

I will attach a png for the problem and the code.

This is the code:

//+------------------------------------------------------------------+
//|                                                 AnchoredVwap.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property strict
#property indicator_buffers 4
#property indicator_chart_window


input color color1=clrDodgerBlue;
input color color2=clrRed;
input color color3=clrGray;
input color color4=clrGreen;

input int   Width1 =2;
input int   Width2 =2;
input int   Width3 =2;
input int   Width4 =2;


//+------------------------------------------------------------------+
//| Variables                                                        |
//+------------------------------------------------------------------+
double A[];
double B[];
double C[];
double D[];

string Vline1,
       Vline2,
       Vline3,
       Vline4;


double   VWAP1;
double   VWAP2;
double   VWAP3;
double   VWAP4;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Indicator buffers mapping
   SetIndexBuffer( 0, A );
   SetIndexBuffer( 1, B );
   SetIndexBuffer( 2, C );
   SetIndexBuffer( 3, D );

//--- Drawing settings
   SetIndexStyle(0,DRAW_LINE,0,Width1,color1);
   SetIndexStyle(1,DRAW_LINE,0,Width2,color2);
   SetIndexStyle(2,DRAW_LINE,0,Width3,color3);
   SetIndexStyle(3,DRAW_LINE,0,Width4,color4);
//---   
   EventSetMillisecondTimer(100);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
{
   EventKillTimer();

   ObjectDelete(0,Vline1);
   ObjectDelete(0,Vline2);
   ObjectDelete(0,Vline3);
   ObjectDelete(0,Vline4);
   return(0);

}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return( rates_total);
}
//+------------------------------------------------------------------+
void OnTimer()
{
   Vline1=ObjectName(0,0,0,OBJ_VLINE);
   Vline2=ObjectName(0,1,0,OBJ_VLINE);
   Vline3=ObjectName(0,2,0,OBJ_VLINE);
   Vline4=ObjectName(0,3,0,OBJ_VLINE);

   datetime Vline1date=(datetime)ObjectGet(Vline1,OBJPROP_TIME1);
   datetime Vline2date=(datetime)ObjectGet(Vline2,OBJPROP_TIME1);
   datetime Vline3date=(datetime)ObjectGet(Vline3,OBJPROP_TIME1);
   datetime Vline4date=(datetime)ObjectGet(Vline4,OBJPROP_TIME1);

   int count1=Bars(Symbol(),0,TimeCurrent(),Vline1date);
   int count2=Bars(Symbol(),0,TimeCurrent(),Vline2date);
   int count3=Bars(Symbol(),0,TimeCurrent(),Vline3date);
   int count4=Bars(Symbol(),0,TimeCurrent(),Vline4date);

   double totalavg=0;
   long totalvol=0;
   for(int i=count1-1; i>=0; i--)
   
   {
      long vol=Volume[i];
      double avg=(High[i]+Low[i]+Close[i]+Open[i])/4;
      totalavg+=avg*vol;
      totalvol+=vol;
      VWAP1=NormalizeDouble(totalavg/totalvol,Digits);
      A[i]=VWAP1;
   }
   double totalavg2=0;
   long totalvol2=0;

   for(int i2=count2-1; i2>=0; i2--)
   {
      long vol2=Volume[i2];
      double avg2=(High[i2]+Low[i2]+Close[i2]+Open[i2])/4;
      totalavg2+=avg2*vol2;
      totalvol2+=vol2;
      VWAP2=NormalizeDouble(totalavg2/totalvol2,Digits);
      B[i2]=VWAP2;
   }
   double totalavg3=0;
   long totalvol3=0;

   for(int i3=count3-1; i3>=0; i3--)
   {
      long vol3=Volume[i3];
      double avg3=(High[i3]+Low[i3]+Close[i3]+Open[i3])/4;
      totalavg3+=avg3*vol3;
      totalvol3+=vol3;
      VWAP3=NormalizeDouble(totalavg3/totalvol3,Digits);
      C[i3]=VWAP3;
   }
   double totalavg4=0;
   long totalvol4=0;

   for(int i4=count4-1; i4>=0; i4--)
   {
      long vol4=Volume[i4];
      double avg4=(High[i4]+Low[i4]+Close[i4]+Open[i4])/4;
      totalavg4+=avg4*vol4;
      totalvol4+=vol4;
      VWAP4=NormalizeDouble(totalavg4/totalvol4,Digits);
      D[i4]=VWAP4;
   }

}
//+------------------------------------------------------------------+
Files:
11.PNG  16 kb
22.PNG  20 kb