Moving Average StackTwo groups of moving averages.
Each group can have up to 3 three different moving averages.
You can choose between SMA, EMA, WMA, VWMA, or HMA for each group.
Integrated time locked capabilities so you can have long term moving averages shown on short timeframes.
Enjoy :)
Jbroadway
Glassnode BTC SOPR ToolkitSOPR stand for Spent Output Profit Ratio. It’s a Bitcoin on-chain metric that shows whether Bitcoin spent outputs (UTXO’s) are being realized in profit or loss. It’s calculated by dividing realized value by the value at creation (price sold / price paid).
The SOPR metric traditionally uses a baseline of 1 instead of 0. For the purposes of the script, I've changed the baseline to 0.
SOPR signals > 0 show the overall market is transaction at a profit.
SOPR signals < 0 show the overall market is transacting at a loss.
SOPR servers as a great short/mid-term indicator.
SOPR Toolkit Features
- Smoothed SOPR
- SOPR Spikes
Smoothed SOPR
By default, ‘Smoothed SOPR’ is shown which applies a smoothing function to SOPR. This helps to visualize the broader SOPR trend.
Smoothed SOPR is calculated by taking the difference between positive and negative SOPR values.
SOPR is split into separate arrays based on if it's above or below the baseline A moving average is then applied to each array, then subtracted to get the difference.
You can also change whether or not a SMA, EMA, or Volume Weighted Simple/Exponential moving average is used. The VWMA is calculated using Glassnode’s BTC Total Transfer Volume metric.
SOPR Spikes
Shows relevant SOPR spikes.
SOPR spikes is calculated by applying a Bollinger Band to SOPR. Only values spike outside the bands are shown.
Adjust the StdDev to show more/less relevant spikes.
Enjoy :)
Time Locked Moving AverageSuccinct Description
Generates moving average that stays locked to users desired time preference.
Verbose Description
The default moving average indicator does not stay locked to the chart timeframe. Meaning, if you want to see a 1 day SMA on a 15 minute chart, you have to do math and adjust the moving average length to 96.
Needing to do this constantly (especially while flipping through multiple time frames) was really annoying, so I codded up this script to do it for me... and now it can for you too!
Error Handling
If you receive a 'study error' that says, "function sma references too many candles in history".
Go to the Time Locked Moving Average settings and increase the timeframe interval until error goes away.
Furthermore, UNCHECK gaps, to show real-time approximated moving average values.
Enjoy :)
TimeLockedMALibrary "TimeLockedMA"
Library & function(s) which generates a moving average that stays locked to users desired time preference.
TODO - Add functionality for more moving average types. IE: smooth, weighted etc...
Example:
time_locked_ma(close, length=1, timeframe='days', type='ema')
Will generate a 1 day exponential moving average that will stay consistent across all chart intervals.
Error Handling
On small time frames with large moving averages (IE: 1min chart with a 50 week moving average), you'll get a study error that says "(function "sma") references too many candles in history" .
To fix this, make sure you have timeframe="" as an indicator() header. Next, in the indicator settings, increase the timeframe from to a higher interval until the error goes away.
By default, it's set to "Chart". Bringing the interval up to 1hr will usually solve the issue.
Furthermore, adding timeframe_gaps=false to your indicator() header will give you an approximation of real-time values.
Misc Info
For time_lock_ma() setting type='na' will return the relative length value that adjusts dynamically to user's chart time interval.
This is good for plugging into other functions where a lookback or length is required. (IE: Bollinger Bands)
time_locked_ma(source, length, timeframe, type) Creates a moving average that is locked to a desired timeframe
Parameters:
source : float, Moving average source
length : int, Moving average length
timeframe : string, Desired timeframe. Use: "minutes", "hours", "days", "weeks", "months", "chart"
type : string, string Moving average type. Use "SMA" (default) or "EMA". Value of "NA" will return relative lookback length.
Returns: moving average that is locked to desired timeframe.
timeframe_convert(t, a, b) Converts timeframe to desired timeframe. From a --> b
Parameters:
t : int, Time interval
a : string, Time period
b : string, Time period to convert to
Returns: Converted timeframe value
chart_time(timeframe_period, timeframe_multiplier) Separates timeframe.period function and returns chart interval and period
Parameters:
timeframe_period : string, timeframe.period
timeframe_multiplier : int, timeframe.multiplier
Enjoy :)