A_Traders_Edge

ATE_Common_Functions_Library

Library "ATE_Common_Functions_Library"
- ATE_Common_Functions_Library was created to assist in constructing CCOMET Scanners

RCI(_rciLength, _source, _interval)
  You will see me using this a lot. DEFINITELY my favorite oscillator to utilize for SO many different things from
timing entries/exits to determining trends.Calculation of this indicator based on Spearmans Correlation.
  Parameters:
    _rciLength (int): (int)
Amount of bars back to use in RCI calculations.

    _source (float): (float)
Source to use in RCI calculations (can use ANY source series. Ie, open,close,high,low,etc).

    _interval (int): (int)
Optional (if parameter not included, it defaults to 3). RCI calculation groups bars by this amount and then will.
rank these groups of bars.

  Returns: (float)
Returns a single RCI value that will oscillates between -100 and +100.

RCIAVG(_rciSMAlen, _source, _interval, firstLength, lastLength)
  20 RCI's are averaged together to get this RCI Avg (Rank Correlation Index Average). Each RCI (of the 20 total RCI)
has a progressively LARGER Lookback Length. Rather than having ALL of the RCI Lengths be individually adjustable (because of too many inputs),
I have made the FIRST Length used (smallest Length value in the set) and the LAST Length used (largest length value in the set) be adjustable
and all other 18 Lengths are equally spread out between the 'firstLength' and the 'lastLength'.
  Parameters:
    _rciSMAlen (int): (int)
Unlike the Single RCI Function, this function smooths out the end result using an SMA with a length value that is this parameter.

    _source (float): (float)
Source to use in RCI calculations (can use ANY source series. Ie, open,close,high,low,etc).

    _interval (int): (int)
Optional (if parameter not included, it defaults to 3). Within the RCI calculation, bars next to each other are grouped together
and then these groups are Ranked against each other. This parameter is the number of adjacent bars that are grouped together.

    firstLength (int): (int)
Optional (if parameter is not included when the function is called on in the script, then it defaults to 200).
This parameter is the Lookback Length for the 1st RCI used (so the SMALLEST Length used) in the RCI Avg.

    lastLength (int): (int)
Optional (if parameter is not included when the function is called on in the script, then it defaults to 2500).
This parameter is the Lookback Length for the 20th(the LAST) RCI used (so the LARGEST Length used) in the RCI Avg.
***** BEWARE ***** The 'lastLength' must be less than (or possibly equal to) 5000 because Tradingview has capped it at 5000, causing an error.
***** BEWARE ***** If the script gives a compiler "time out" error then the 'lastLength' must be lowered until it no longer times out when compiling.

  Returns: (float)
Returns a single RCI value that is the Avg of many RCI values that will oscillate between -100 and +100.

PercentChange(_startingValue, _endingValue)
  This is a quick function to calculate how much % change has occurred between the '_startingValue' and the '_endingValue'
that you input into the function.
  Parameters:
    _startingValue (float): (float)
The source value to START the % change calculation from.

    _endingValue (float): (float)
The source value to END the % change caluclation from.

  Returns: Returns a single output being the % value between 0-100 (with trailing numbers behind a decimal). If you want only
a certain amount of numbers behind the decimal, this function needs to be put within a formatting function to do so.

Rescale(_source, _oldMin, _oldMax, _newMin, _newMax)
  Rescales series with a known '_oldMin' & '_oldMax'. Use this when the scale of the '_source' to
rescale is known (bounded).
  Parameters:
    _source (float): (float)
Source to be normalized.

    _oldMin (int): (float)
The known minimum of the '_source'.

    _oldMax (int): (float)
The known maximum of the '_source'.

    _newMin (int): (float)
What you want the NEW minimum of the '_source' to be.

    _newMax (int): (float)
What you want the NEW maximum of the '_source' to be.

  Returns: Outputs your previously bounded '_source', but now the value will only move between the '_newMin' and '_newMax'
values you set in the variables.

Normalize_Historical(_source, _minimumLvl, _maximumLvl)
  Normalizes '_source' that has a previously unknown min/max(unbounded) determining the max & min of the '_source'
FROM THE ENTIRE CHARTS HISTORY. ]
  Parameters:
    _source (float): (float)
Source to be normalized.

    _minimumLvl (int): (float)
The Lower Boundary Level.

    _maximumLvl (int): (float)
The Upper Boundary Level.

  Returns: Returns your same '_source', but now the value will MOSTLY stay between the minimum and maximum values you set in the
'_minimumLvl' and '_maximumLvl' variables (ie. if the source you input is an RSI...the output is the same RSI value but
instead of moving between 0-100 it will move between the maxand min you set).

Normailize_Local(_source, _length, _minimumLvl, _maximumLvl)
  Normalizes series with previously unknown min/max(unbounded). Much like the Normalize_Historical function above this one,
but rather than using the Highest/Lowest Values within the ENTIRE charts history, this on looks for the Highest/Lowest
values of '_source' within the last ___ bars (set by user as/in the '_length' parameter. ]
  Parameters:
    _source (float): (float)
Source to be normalized.

    _length (int): (float)
The amount of bars to look back to determine the highest/lowest '_source' value.

    _minimumLvl (int): (float)
The Lower Boundary Level.

    _maximumLvl (int): (float)
The Upper Boundary Level.

  Returns: Returns a single output variable being the previously unbounded '_source' that is now normalized and bound between
the values used for '_minimumLvl'/'_maximumLvl' of the '_source' within the user defined lookback period.

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

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this library?

Copy the following line and paste it in your script.