HTFBands█ OVERVIEW
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: ( ) 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 . 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 (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 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)
Bollingersband
LibIndicadoresUteisLibrary "LibIndicadoresUteis"
Collection of useful indicators. This collection does not do any type of plotting on the graph, as the methods implemented can and should be used to get the return of mathematical formulas, in a way that speeds up the development of new scripts. The current version contains methods for stochastic return, slow stochastic, IFR, leverage calculation for B3 futures market, leverage calculation for B3 stock market, bollinger bands and the range of change.
estocastico(PeriodoEstocastico)
Returns the value of stochastic
Parameters:
PeriodoEstocastico : Period for calculation basis
Returns: Float with the stochastic value of the period
estocasticoLento(PeriodoEstocastico, PeriodoMedia)
Returns the value of slow stochastic
Parameters:
PeriodoEstocastico : Stochastic period for calculation basis
PeriodoMedia : Average period for calculation basis
Returns: Float with the value of the slow stochastic of the period
ifrInvenenado(PeriodoIFR, OrigemIFR)
Returns the value of the RSI/IFR Poisoned of Guima
Parameters:
PeriodoIFR : RSI/IFR period for calculation basis
OrigemIFR : Source of RSI/IFR for calculation basis
Returns: Float with the RSI/IFR value for the period
calculoAlavancagemFuturos(margem, alavancagemMaxima)
Returns the number of contracts to work based on margin
Parameters:
margem : Margin for contract unit
alavancagemMaxima : Maximum number of contracts to work
Returns: Integer with the number of contracts suggested for trading
calculoAlavancagemAcoes(alavancagemMaxima)
Returns the number of batches to work based on the margin
Parameters:
alavancagemMaxima : Maximum number of batches to work
Returns: Integer with the amount of lots suggested for trading
bandasBollinger(periodoBB, origemBB, desvioPadrao)
Returns the value of bollinger bands
Parameters:
periodoBB : Period of bollinger bands for calculation basis
origemBB : Origin of bollinger bands for calculation basis
desvioPadrao : Standard Deviation of bollinger bands for calculation basis
Returns: Two-position array with upper and lower band values respectively
theRoc(periodoROC, origemROC)
Returns the value of Rate Of Change
Parameters:
periodoROC : Period for calculation basis
origemROC : Source of calculation basis
Returns: Float with the value of Rate Of Change
McNichollBandsLibrary "McNichollBands"
This is a library which only functions to make the McNicholl's Bollinger Bands modifications. It's also my first library, so I'll probably screw some things up.
mcNichollBands(alpha, useLogScale, widthMultiplier)
Calculates the McNicholl's Bollinger Bands modifications.
Parameters:
alpha : The alpha constant to be used on the EMA calculations.
useLogScale : Whether to use the log version of the prices or not.
widthMultiplier : The number that shall be multiplied by the volatility to form the bands.
Returns: A tuple containing the lower band, the center line, and the upper band.