Calculate trading day between two date

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #223082 quote
    robocop
    Participant
    Average

    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?

    #223093 quote
    robertogozzi
    Moderator
    Master

    Just count the weekly bars in that interval and multiply them by 5 days (or 6 days if you want to include Sundays).

    #223096 quote
    Quino
    Participant
    Average

    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
     
    
    #223105 quote
    robocop
    Participant
    Average
    These are too approximate calculation methods, they do not take into account the trading days closed during the week. I would really like, in the W timeframe, to be able to count the daily bars that actually occurred.

    calculates the trading days between two dates. It works on a daily timeframe. For weekly, just divide by five.

    Just count the weekly bars in that interval and multiply them by 5 days (or 6 days if you want to include Sundays).

    
    
    #223178 quote
    robertogozzi
    Moderator
    Master

    You can’t count days in a weekly timeframe.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Calculate trading day between two date


ProBuilder support

New Reply
Author
author-avatar
robocop @robocop Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by robertogozzi
2 years, 3 months ago.

Topic Details
Forum: ProBuilder support
Language: English
Started: 10/31/2023
Status: Active
Attachments: No files
Logo Logo
Loading...