PINE LIBRARY

HTFMAs

█ OVERVIEW

Contains a type HTFMA used to return data on six moving averages from a higher timeframe.
Several types of MA's are supported.

█ HOW TO USE

Please see instructions in the code (in library description). (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

method getMaType(this)
  Enumerator function, given a key returns `enum MaTypes` value
  Namespace types: series string, simple string, input string, const string
  Parameters:
    this (string)

method init(this, enableAll, ma1Enabled, ma1MaType, ma1Src, ma1Prd, ma2Enabled, ma2MaType, ma2Src, ma2Prd, ma3Enabled, ma3MaType, ma3Src, ma3Prd, ma4Enabled, ma4MaType, ma4Src, ma4Prd, ma5Enabled, ma5MaType, ma5Src, ma5Prd, ma6Enabled, ma6MaType, ma6Src, ma6Prd)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs)
    enableAll (simple MaEnable)
    ma1Enabled (bool)
    ma1MaType (series MaTypes)
    ma1Src (string)
    ma1Prd (int)
    ma2Enabled (bool)
    ma2MaType (series MaTypes)
    ma2Src (string)
    ma2Prd (int)
    ma3Enabled (bool)
    ma3MaType (series MaTypes)
    ma3Src (string)
    ma3Prd (int)
    ma4Enabled (bool)
    ma4MaType (series MaTypes)
    ma4Src (string)
    ma4Prd (int)
    ma5Enabled (bool)
    ma5MaType (series MaTypes)
    ma5Src (string)
    ma5Prd (int)
    ma6Enabled (bool)
    ma6MaType (series MaTypes)
    ma6Src (string)
    ma6Prd (int)

method init(this, enableAll, tf, rngAtrQ, showRecentBars, lblsOffset, lblsShow, lnOffset, lblSize, lblStyle, smoothen, ma1lnClr, ma1lnWidth, ma1lnStyle, ma2lnClr, ma2lnWidth, ma2lnStyle, ma3lnClr, ma3lnWidth, ma3lnStyle, ma4lnClr, ma4lnWidth, ma4lnStyle, ma5lnClr, ma5lnWidth, ma5lnStyle, ma6lnClr, ma6lnWidth, ma6lnStyle, ma1ShowHistory, ma2ShowHistory, ma3ShowHistory, ma4ShowHistory, ma5ShowHistory, ma6ShowHistory, ma1ShowLabel, ma2ShowLabel, ma3ShowLabel, ma4ShowLabel, ma5ShowLabel, ma6ShowLabel)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    enableAll (series MaEnable)
    tf (string)
    rngAtrQ (int)
    showRecentBars (int)
    lblsOffset (int)
    lblsShow (bool)
    lnOffset (int)
    lblSize (string)
    lblStyle (string)
    smoothen (bool)
    ma1lnClr (color)
    ma1lnWidth (int)
    ma1lnStyle (string)
    ma2lnClr (color)
    ma2lnWidth (int)
    ma2lnStyle (string)
    ma3lnClr (color)
    ma3lnWidth (int)
    ma3lnStyle (string)
    ma4lnClr (color)
    ma4lnWidth (int)
    ma4lnStyle (string)
    ma5lnClr (color)
    ma5lnWidth (int)
    ma5lnStyle (string)
    ma6lnClr (color)
    ma6lnWidth (int)
    ma6lnStyle (string)
    ma1ShowHistory (bool)
    ma2ShowHistory (bool)
    ma3ShowHistory (bool)
    ma4ShowHistory (bool)
    ma5ShowHistory (bool)
    ma6ShowHistory (bool)
    ma1ShowLabel (bool)
    ma2ShowLabel (bool)
    ma3ShowLabel (bool)
    ma4ShowLabel (bool)
    ma5ShowLabel (bool)
    ma6ShowLabel (bool)

method get(this, id)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs)
    id (int)

method set(this, id, prop, val)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs)
    id (int)
    prop (string)
    val (string)

method set(this, id, prop, val)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    id (int)
    prop (string)
    val (string)

method htfUpdateTuple(rsParams, repaint)
  Namespace types: RsParamsMAs
  Parameters:
    rsParams (RsParamsMAs)
    repaint (bool)

method clear(this)
  Namespace types: MaDrawing
  Parameters:
    this (MaDrawing)

method importRsRetTuple(this, htfBi, ma1, ma2, ma3, ma4, ma5, ma6)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    htfBi (int)
    ma1 (float)
    ma2 (float)
    ma3 (float)
    ma4 (float)
    ma5 (float)
    ma6 (float)

method getDrw(this, id)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    id (int)

method setDrwProp(this, id, prop, val)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    id (int)
    prop (string)
    val (string)

method initDrawings(this, rsPrms, dispBandWidth)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    rsPrms (RsParamsMAs)
    dispBandWidth (float)

method updateDrawings(this, rsPrms, dispBandWidth)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    rsPrms (RsParamsMAs)
    dispBandWidth (float)

method update(this)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps0 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps1 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps2 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps3 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps4 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps5 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (RsParamsMAs) Target object to import prop values to.
    oCfg (objProps6 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs)
    oCfg (objProps7 type from moebius1977/CSVParser/1)
    maCount (int)

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: RsParamsMAs
  Parameters:
    this (RsParamsMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps8 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps0 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps1 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps2 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps3 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps4 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps5 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs): (HTFMAs) Target object to import prop values to.
    oCfg (objProps6 type from moebius1977/CSVParser/1): (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
    maCount (int): (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
  Returns: this

method importConfig(this, oCfg, maCount)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    oCfg (objProps7 type from moebius1977/CSVParser/1)
    maCount (int)

method importConfig(this, oCfg, maCount)
  Namespace types: HTFMAs
  Parameters:
    this (HTFMAs)
    oCfg (objProps8 type from moebius1977/CSVParser/1)
    maCount (int)

method newRsParamsMAs(this)
  Namespace types: LO
  Parameters:
    this (LO)

method newHTFMAs(this)
  Namespace types: LO
  Parameters:
    this (LO)

RsMaCalcParams
  Parameters of one MA (only calculation params needed within req.sec(), visual parameters are within htfMAs type)
  Fields:
    enabled (series bool)
    maType (series MaTypes): MA type options: SMA / EMA / WMA / ...
    src (series string)
    prd (series int): MA period

RsParamsMAs
  Collection of parameters of 6 MAs. Used to pass params to req.sec()
  Fields:
    ma1CalcParams (RsMaCalcParams)
    ma2CalcParams (RsMaCalcParams)
    ma3CalcParams (RsMaCalcParams)
    ma4CalcParams (RsMaCalcParams)
    ma5CalcParams (RsMaCalcParams)
    ma6CalcParams (RsMaCalcParams)

RsReturnMAs
  Used to return data from req.sec().
  Fields:
    htfBi (series int)
    ma1 (series float)
    ma2 (series float)
    ma3 (series float)
    ma4 (series float)
    ma5 (series float)
    ma6 (series float)

MaDrawing
  MA's plot parameters plus drawing objects for MA's current level (line and label).
  Fields:
    lnClr (series color): (color) MA plot line color (like in plot())
    lnWidth (series int): (int) MA plot line width (like in plot())
    lnStyle (series string): (string) MA plot line style (like in plot())
    showHistory (series bool): (bool) Whether to plot the MA on historical bars or only show current level to the right of the latest bar.
    showLabel (series bool): (bool) Whether to show the name of the MA to the right of the MA's level
    ln (series line): (line) line to show MA"s current level
    lbl (series label): (label) label showing MA's name

HTFMAs
  Contains data and drawing parameters for MA's of one timeframe (MA calculation parameters for MA's of one timeframe are in a separate object RsParamsMAs)
  Fields:
    rsRet (RsReturnMAs): (RsReturnMAs) Contains data returned from req.sec(). Is set to na in between HTF bar changes if smoothing is enabled.
    rsRetLast (RsReturnMAs): (RsReturnMAs) Contains a copy of data returned from req.sec() in case rsRet is set to na for smoothing.
    rsRetNaObj (RsReturnMAs): (RsReturnMAs) An empty object as `na` placeholder
    ma1Drawing (MaDrawing): (MaDrawing) MA drawing properties
    ma2Drawing (MaDrawing): (MaDrawing) MA drawing properties
    ma3Drawing (MaDrawing): (MaDrawing) MA drawing properties
    ma4Drawing (MaDrawing): (MaDrawing) MA drawing properties
    ma5Drawing (MaDrawing): (MaDrawing) MA drawing properties
    ma6Drawing (MaDrawing): (MaDrawing) MA drawing properties
    enabled (series bool): (bool ) Enables/disables all of the MAs of one timeframe.
    tf (series string): (string) Timeframe
    showHistory (series bool): (bool ) Plot MA line on historical bars
    rngAtrQ (series int): (int ) A multiplier for atr(14). Determines a range within which the MA's will be plotted. MA's too far away will not be plotted.
    showRecentBars (series int): (int ) Only plot MA on these recent bars
    smoothen (series bool): (bool ) Smoothen MA plot. If false the same HTF value is returned on all chart bars within a HTF bar (intrabars), so the plot looks like steps.
    lblsOffset (series int): (int ) Show MA name this number of bars to the right off last bar.
    lblsShow (series bool): (bool ) Show MA name
    lnOffset (series int): (int ) Start line showing current level of the MA this number of bars to the right off the last bar.
    lblSize (series string): (string) Label size
    lblStyle (series string): (string) Label style
    lblTxtAlign (series string): (string) Label text align
    bPopupLabel (series bool): (bool ) Show current MA value as a tooltip to MA's name.

LO
  LO Library object, whose only purpose is to serve as a shorthand for library name in script code.
  Fields:
    dummy (series string)
moving_averagetechindicator

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.

Disclaimer