Pivot Points Object

 

Hi, ive taken this code from online but struggling to adapt it. In the backtest, the pivot points vanish once the week is over. Instead i want to see previous pivot points for it designated week, and for the lines to only be drawn during that week. How can i amend this code?

int OnInit()
{

   return(INIT_SUCCEEDED);
}


void OnDeinit(const int reason)
{


}

void OnTick()
{
   double high1 = iHigh(Symbol(), PERIOD_W1, 1);
   double low1 = iLow(Symbol(), PERIOD_W1, 1);
   double close1 = iClose(Symbol(), PERIOD_W1, 1);
   
   //Start time
   datetime time1 = iTime(Symbol(), PERIOD_W1, 0);
   //End time
   datetime time2 = time1 + (PeriodSeconds(PERIOD_W1)*4);
   
   double pivotPoint = (high1 + low1 + close1) / 3;
   string objName = "Pivot Point";
   CreateLine(objName, clrMediumBlue, time1, pivotPoint, time2, pivotPoint);
   
   double r1 = pivotPoint * 2 - low1;
   objName = "R1";
   CreateLine(objName, clrLightBlue, time1, r1, time2, r1);
      
   double r2 = pivotPoint + high1 - low1;
   objName = "R2";
   CreateLine(objName, clrLightBlue, time1, r2, time2, r2);

   double s1 = pivotPoint * 2 - high1;
   objName = "S1";
   CreateLine(objName, clrCoral, time1, s1, time2, s1);
      
   double s2 = pivotPoint - (high1 - low1);
   objName = "S2";
   CreateLine(objName, clrCoral, time1, s2, time2, s2);
   
}



void CreateLine(string objName, color clr, datetime time1, double price1, datetime time2, double price2){
ObjectDelete(0, objName);
ObjectCreate(0, objName, OBJ_TREND, 0, time1, price1, time2, price2);
ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, 5);