//By Quino october 10, 2023
//Indicator to be inserted in the price one
//Date1 : Date in the past (integer yyyymmdd)
//Date2 : Date in the past (integer yyyymmdd) or current, but earlier than Date 1
//----------------- Date 1 Elapsed Periods calculation ----------------------
MaxDays=352 // Number of periodes maximum for calculation - It allows dates error management
Nbrdays1=MaxDays
for j =1 to Nbrdays1 do
if date[j]=Date1 then
ReferencePeriods1=j
break
endif
next
drawvline(datetobarindex(Date1))
//----------------- Date 2 Elapsed Periods calculation ----------------------
Nbrdays2=MaxDays
for k =1 to Nbrdays2 do
if date[k]=Date2 then
ReferencePeriods2=k
break
endif
next
drawvline(datetobarindex(Date2))
DifferentialPeriods=j-k
//----------------- Dates error management ----------------------
if j=Nbrdays1+1 or k=Nbrdays2+1 or Date2 < Date1 then
Error=1
else
Error=0
endif
//---------------------------- Data Display ---------------------------------------------------------------
if islastbarupdate then
if error=0 then
drawtext("Date 1 Elapsed Periods = #ReferencePeriods1#", -120,-30) anchor(topright)coloured (0,0,0)
drawtext("Date 2 Elapsed Periods = #ReferencePeriods2#", -120,-45) anchor(topright)coloured (0,0,0)
drawtext("Differential Periods = #DifferentialPeriods#", -120,-60) anchor(topright)coloured (0,0,0)
else
drawtext("Dates Error", -120,-30) anchor(topright)coloured (255,0,0)
endif
endif
return