Search code examples
pine-scriptpine-script-v5pine-script-v4

quarterly equivalent for year != year[1]


In order to work with extended hours (I am aware the extended hours session details only become available on on intraday charts) in pine, I need to get the quarterly open but, what is the equivalent to year != year[1] for the current/previous quarter in pine?

e.g.

hasSessionExtended = syminfo.session == session.extended
newYear    = hasSessionExtended ? year != year[1] : timeframe.change('12M')
newQuarter =  // I got no clue please help me bridging the (mind)gap

Note: I am not interested in the FQ but calendar year quarter in order to get the e.g. first trading day open price of a given quarter.


Solution

  • Try this:

    newQuarter = month != month[1] and (month - 1) % 3 == 0
    

    Although timeframe.change("3M") seems to be doing the same job just fine, including on intraday with Extended hours on.