PINE LIBRARY

RawCuts_01

Library "RawCuts_01"

A collection of functions by:
mutantdog

The majority of these are used within published projects, some useful variants have been included here aswell.
This is volume one consisting mainly of smaller functions, predominantly the filters and standard deviations from Weight Gain 4000.
Also included at the bottom are various snippets of related code for demonstration. These can be copied and adjusted according to your needs.

A full up-to-date table of contents is located at the top of the main script.


WEIGHT GAIN FILTERS

A collection of moving average type filters with adjustable volume weighting.
Based upon the two most common methods of volume weighting.
'Simple' uses the standard method in which a basic VWMA is analogous to SMA.
'Elastic' uses exponential method found in EVWMA which is analogous to RMA.

Volume weighting is applied according to an exponent multiplier of input volume.
0 >> volume^0 (unweighted), 1 >> volume^1 (fully weighted), use float values for intermediate weighting.
Additional volume filter switch for smoothing of outlier events.


DIVA MODULAR DEVIATIONS

A small collection of standard and absolute deviations.
Includes the weightgain functionality as above.

Basic modular functionality for more creative uses.
Optional input (ct) for external central tendency (aka: estimator).
Can be assigned to alternative filter or any float value. Will default to internal filter when no ct input is received.


Some other useful or related functions included at the bottom along with basic demonstration use.


weightgain_sma(src, len, xVol, fVol)
  Simple Moving Average (SMA): Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Standard Simple Moving Average with Simple Weight Gain applied.

weightgain_hsma(src, len, xVol, fVol)
  Harmonic Simple Moving Average (hSMA): Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Harmonic Simple Moving Average with Simple Weight Gain applied.

weightgain_gsma(src, len, xVol, fVol)
  Geometric Simple Moving Average (gSMA): Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Geometric Simple Moving Average with Simple Weight Gain applied.

weightgain_wma(src, len, xVol, fVol)
  Linear Weighted Moving Average (WMA): Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Basic Linear Weighted Moving Average with Simple Weight Gain applied.

weightgain_hma(src, len, xVol, fVol)
  Hull Moving Average (HMA): Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Basic Hull Moving Average with Simple Weight Gain applied.

diva_sd_sma(src, len, xVol, fVol, ct)
  Standard Deviation (SD SMA): Diva / Weight Gain (Simple Volume)
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_sma().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

diva_sd_wma(src, len, xVol, fVol, ct)
  Standard Deviation (SD WMA): Diva / Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_wma().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

diva_aad_sma(src, len, xVol, fVol, ct)
  Average Absolute Deviation (AAD SMA): Diva / Weight Gain (Simple Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_sma().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

diva_aad_wma(src, len, xVol, fVol, ct)
  Average Absolute Deviation (AAD WMA): Diva / Weight Gain (Simple Volume) .
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_wma().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

weightgain_ema(src, len, xVol, fVol)
  Exponential Moving Average (EMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Exponential Moving Average with Elastic Weight Gain applied.

weightgain_dema(src, len, xVol, fVol)
  Double Exponential Moving Average (DEMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Double Exponential Moving Average with Elastic Weight Gain applied.

weightgain_tema(src, len, xVol, fVol)
  Triple Exponential Moving Average (TEMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Triple Exponential Moving Average with Elastic Weight Gain applied.

weightgain_rma(src, len, xVol, fVol)
  Rolling Moving Average (RMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Rolling Moving Average with Elastic Weight Gain applied.

weightgain_drma(src, len, xVol, fVol)
  Double Rolling Moving Average (DRMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Double Rolling Moving Average with Elastic Weight Gain applied.

weightgain_trma(src, len, xVol, fVol)
  Triple Rolling Moving Average (TRMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: Triple Rolling Moving Average with Elastic Weight Gain applied.

diva_sd_ema(src, len, xVol, fVol, ct)
  Standard Deviation (SD EMA): Diva / Weight Gain: (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_ema().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

diva_sd_rma(src, len, xVol, fVol, ct)
  Standard Deviation (SD RMA): Diva / Weight Gain: (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_rma().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

weightgain_vidya_rma(src, len, xVol, fVol)
  VIDYA v1 RMA base (VIDYA-RMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: VIDYA v1, RMA base with Elastic Weight Gain applied.

weightgain_vidya_ema(src, len, xVol, fVol)
  VIDYA v1 EMA base (VIDYA-EMA): Weight Gain (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
  Returns: VIDYA v1, EMA base with Elastic Weight Gain applied.

diva_sd_vidya_rma(src, len, xVol, fVol, ct)
  Standard Deviation (SD VIDYA-RMA): Diva / Weight Gain: (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_vidya_rma().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

diva_sd_vidya_ema(src, len, xVol, fVol, ct)
  Standard Deviation (SD VIDYA-EMA): Diva / Weight Gain: (Elastic Volume).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    xVol (float): Volume exponent multiplier (0 = unweighted, 1 = fully weighted).
    fVol (bool): Volume smoothing filter.
    ct (float): Central tendency (optional, na = bypass). Internal: weightgain_vidya_ema().
  Returns: [Calculated Deviation value, Central Tendency (as used)]

weightgain_sema(src, len, xVol, fVol)
  Parameters:
    src (float)
    len (simple int)
    xVol (float)
    fVol (bool)

diva_sd_sema(src, len, xVol, fVol)
  Parameters:
    src (float)
    len (simple int)
    xVol (float)
    fVol (bool)

diva_mad_mm(src, len, ct)
  Median Absolute Deviation (MAD MM): Diva (no volume weighting).
  Parameters:
    src (float): Source input.
    len (int): Length (number of bars).
    ct (float): Central tendency (optional, na = bypass). Internal: ta.median()
  Returns: [Calculated Deviation value, Central Tendency (as used)]

source_switch(slct, aux1, aux2, aux3, aux4)
  Custom Source Selector/Switch function. Features standard & custom 'weighted' sources with additional aux inputs.
  Parameters:
    slct (string): Choose from custom set of string values.
    aux1 (float): Additional input for user-defined source, eg: standard input.source(). Optional, use na to bypass.
    aux2 (float): Additional input for user-defined source, eg: standard input.source(). Optional, use na to bypass.
    aux3 (float): Additional input for user-defined source, eg: standard input.source(). Optional, use na to bypass.
    aux4 (float): Additional input for user-defined source, eg: standard input.source(). Optional, use na to bypass.
  Returns: Float value, to be used as src input for other functions.

colour_gradient_ma_div(ma1, ma2, div, bull, bear, mid, mult)
  Colour Gradient for plot fill between two moving averages etc, with seperate bull/bear and divergence strength.
  Parameters:
    ma1 (float): Input for fast moving average (eg: bullish when above ma2).
    ma2 (float): Input for slow moving average (eg: bullish when below ma1).
    div (float): Input deviation/divergence value used to calculate strength of colour.
    bull (color): Colour when ma1 above ma2.
    bear (color): Colour when ma1 below ma2.
    mid (color): Neutral colour when ma1 = ma2.
    mult (int): Opacity multiplier. 100 = maximum, 0 = transparent.
  Returns: Colour with transparency (according to specified inputs)
inputsmovingavaragestandarddeviationstechindicatorvolumeweighted

ספריית Pine

ברוח TradingView אמיתית, המחבר פרסם קוד Pine זה כספריית קוד פתוח כדי שמתכנתי Pine אחרים מהקהילה שלנו יוכלו לעשות בו שימוש חוזר. כל הכבוד למחבר! אתה יכול להשתמש בספרייה זו באופן פרטי או בפרסומים אחרים בקוד פתוח, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית.

כתב ויתור