HTFBands

Contains type and methods for drawing higher-timeframe bands of several types:
- Bollinger bands
- Parabolic SAR
- Supertrend
- VWAP
By copy pasting ready made code sections to your script you can add as many multi-timeframe bands as necessary.
█ HOW TO USE
Please see instructions in the code. (Important: first fold all sections of the script: press Cmd + K then Cmd + - (for Windows Ctrl + K then Ctrl + -)
█ FULL LIST OF FUNCTIONS AND PARAMETERS
atr2(length)
An alternate ATR function to the `ta.atr()` built-in, which allows a "series float"
`length` argument.
Parameters:
length (float): (series int/float) Length for the smoothing parameter calculation.
Returns: (float) The ATR value.
pine_supertrend2(factor, atrLength, wicks)
An alternate SuperTrend function to `supertrend()`, which allows a "series float"
`atrLength` argument.
Parameters:
factor (float): (series int/float) Multiplier for the ATR value.
atrLength (float): (series int/float) Length for the ATR smoothing parameter calculation.
wicks (simple bool): (simple bool) Condition to determine whether to take candle wicks into account when
reversing trend, or to use the close price. Optional. Default is false.
Returns: ([float, int]) A tuple of the superTrend value and trend direction.
method getDefaultBandQ1(bandType)
For a given BandType returns its default Q1
Namespace types: series BandTypes
Parameters:
bandType (series BandTypes)
method getDefaultBandQ2(bandType)
For a given BandType returns its default Q2
Namespace types: series BandTypes
Parameters:
bandType (series BandTypes)
method getDefaultBandQ3(bandType)
For a given BandType returns its default Q3
Namespace types: series BandTypes
Parameters:
bandType (series BandTypes)
method init(this, bandsType, q1, q2, q3, vwapAnchor)
Initiates RsParamsBands for each band (used in htfUpdate() withi req.sec())
Namespace types: RsParamsBands
Parameters:
this (RsParamsBands)
bandsType (series BandTypes)
q1 (float): (float) Depending on type: BB - length, SAR - AF start, ST - ATR's prd
q2 (float): (float) Depending on type: BB - StdDev mult, SAR - AF step, ST - mult
q3 (float): (float) Depending on type: BB - not used, SAR - AF max, ST - not used
vwapAnchor (series VwapAnchors): (VwapAnchors) VWAP ahcnor
method init(this, bandsType, tf, showRecentBars, lblsShow, lblsMaxLabels, lblSize, lnMidClr, lnUpClr, lnLoClr, fill, fillClr, lnWidth, lnSmoothen)
Initialises object with params (incl. input). Creates arrays if any.
Namespace types: HtfBands
Parameters:
this (HtfBands)
bandsType (series BandTypes): (BandTypes) Just used to enable/disable - if BandTypes.none then disable )
tf (string): (string) Timeframe
showRecentBars (int): (int) Only show over this number of recent bars
lblsShow (bool): (bool) Show labels
lblsMaxLabels (int): (int) Max labels to show
lblSize (string): (string) Size of the labels
lnMidClr (color): (color) Middle band color
lnUpClr (color): (color) Upper band color
lnLoClr (color): (color) Lower band color
fill (bool)
fillClr (color): (color) Fill color
lnWidth (int): (int) Line width
lnSmoothen (bool): (bool) Smoothen the bands
method htfUpdateTuple(rsPrms, repaint)
(HTF) Calculates Bands within request.security(). Returns tuple [middleBand, upperBand, lowerBand]. If any or all of the bands are not available returns na as their value.
Namespace types: RsParamsBands
Parameters:
rsPrms (RsParamsBands): (RsParamsBands) Parameters of the band.
repaint (bool): (bool) If true does not update on realtime bars.
Returns: A tuple [HTF bar_index, middle, upper, lower, direction] (corresponds to fields in RsReturnBands)
method importRsRetTuple(this, htfBi, mid, up, lo, dir)
Imports a tuple returned from req.sec() into an HtfBands object
Namespace types: HtfBands
Parameters:
this (HtfBands): (HtfBands) Object to import to
htfBi (int): (float) Higher timeframe's bar index (Default = na)
mid (float)
up (float): (float) Value of upper band (Default = na)
lo (float): (float) Value of lower band (Default = na)
dir (int): (int) Direction (for bands like Parabolic SAR) (Default = na)
method addUpdDrawings(this, rsPrms)
Draws band's labels
Namespace types: HtfBands
Parameters:
this (HtfBands)
rsPrms (RsParamsBands)
method update(this)
Sets band's values to na on intrabars if `smoothen` is set.
Namespace types: HtfBands
Parameters:
this (HtfBands)
method newRsParamsBands(this)
A wraper for RsParamsBands.new()
Namespace types: LO_A
Parameters:
this (LO_A)
method newHtfBands(this)
A wraper for HtfBands.new()
Namespace types: LO_B
Parameters:
this (LO_B)
RsParamsBands
Used to pass bands' params to req.sec()
Fields:
bandsType (series BandTypes): (enum BandTypes) Type of the band (BB, SAR etc.)
q1 (series float): (float) Depending on type: BB - length, SAR - AF start, ST - ATR's prd
q2 (series float): (float) Depending on type: BB - StdDev mult, SAR - AF step, ST - mult
q3 (series float): (float) Depending on type: BB - not used, SAR - AF max, ST - not used
vwapAnchor (series VwapAnchors)
RsReturnBands
Used to return bands' data from req.sec(). Params of the bands are in RsParamsBands
Fields:
htfBi (series float): (float) Higher timeframe's bar index (Default = na)
upBand (series float): (float) Value of upper band (Default = na)
loBand (series float): (float) Value of lower band (Default = na)
midBand (series float): (float) Value of middle band (Default = na)
dir (series int): (float) Direction (for bands like Parabolic SAR) (Default = na)
BandsDrawing
Contains plot visualization parameters and stores and keeps track of lines, labels and other visual objects (not plots)
Fields:
lnMidClr (series color): (color) Middle band color
lnLoClr (series color): (color) Lower band color
lnUpClr (series color): (color) Upper band color
fillUpClr (series color)
fillLoClr (series color)
lnWidth (series int): (int) Line width
lnSmoothen (series bool): (bool) Smoothen the bands
showHistory (series bool): (bool) If true show bands lines, otherwise only current level
showRecentBars (series int): (int) Only show over this number of recent bars
arLbl (array<label>): (label Labels
lblsMaxLabels (series int): (int) Max labels to show
lblsShow (series bool): (bool) Show labels
lblSize (series string): (string) Size of the labels
HtfBands
Calcs and draws HTF bands
Fields:
rsRet (RsReturnBands): (RsReturnBands) Bands' values
rsRetNaObj (RsReturnBands): (RsReturnBands) Dummy na obj for returning from request.security()
rsPrms (RsParamsBands): (RsParamsBands) Band parameters (for htfUpdate() called in req.sec() )
drw (BandsDrawing): (BandsDrawing) Contains plot visualization parameters and stores and keeps track of lines, labels and other visual objects (not plots)
enabled (series bool): (bool) Toggles bands on/off
tf (series string): (string) Timeframe
LO_A
LO Library object, whose only purpose is to serve as a shorthand for library name in script code.
Fields:
dummy (series string)
LO_B
LO Library object, whose only purpose is to serve as a shorthand for library name in script code.
Fields:
dummy (series string)
Perpustakaan Pine
Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda juga boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod ini dalam penerbitan adalah tertakluk kepada Peraturan Dalaman.
Penafian
Perpustakaan Pine
Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda juga boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod ini dalam penerbitan adalah tertakluk kepada Peraturan Dalaman.