In a Weekly Timeframe, I need to calculate how many trading days there are betweem two date. example from 20200320 to 20231030 how many daily bars (trading days) there was?
Period are only in the past.
May you help me? Any ideas?
Just count the weekly bars in that interval and multiply them by 5 days (or 6 days if you want to include Sundays).
All,
I would like to share this below indicator which calculates the trading days between two dates. It works on a daily timeframe. For weekly, just divide by five.
//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
You can’t count days in a weekly timeframe.