INVITE-ONLY SCRIPT

GKD-V Volatility Ratio [Loxx]

Updated
Giga Kaleidoscope Volatility Ratio is a Volatility/Volume module included in Loxx's "Giga Kaleidoscope Modularized Trading System".

What is Loxx's "Giga Kaleidoscope Modularized Trading System"?

The Giga Kaleidoscope Modularized Trading System is a trading system built on the philosophy of the NNFX (No Nonsense Forex) algorithmic trading.

What is an NNFX algorithmic trading strategy?

The NNFX algorithm is built on the principles of trend, momentum, and volatility. There are six core components in the NNFX trading algorithm:

1. Volatility - price volatility; e.g., Average True Range, True Range Double, Close-to-Close, etc.
2. Baseline - a moving average to identify price trend (such as "Baseline" shown on the chart above)
3. Confirmation 1 - a technical indicator used to identify trends. This should agree with the "Baseline"
4. Confirmation 2 - a technical indicator used to identify trends. This filters/verifies the trend identified by "Baseline" and "Confirmation 1"
5. Volatility/Volume - a technical indicator used to identify volatility/volume breakouts/breakdown.
6. Exit - a technical indicator used to determine when a trend is exhausted.

How does Loxx's GKD (Giga Kaleidoscope Modularized Trading System) implement the NNFX algorithm outlined above?

Loxx's GKD v1.0 system has five types of modules (indicators/strategies). These modules are:

1. GKD-BT - Backtesting module (Volatility, Number 1 in the NNFX algorithm)
2. GKD-B - Baseline module (Baseline and Volatility/Volume, Numbers 1 and 2 in the NNFX algorithm)
3. GKD-C - Confirmation 1/2 module (Confirmation 1/2, Numbers 3 and 4 in the NNFX algorithm)
4. GKD-V - Volatility/Volume module (Confirmation 1/2, Number 5 in the NNFX algorithm)
5. GKD-E - Exit module (Exit, Number 6 in the NNFX algorithm)

(additional module types will added in future releases)

Each module interacts with every module by passing data between modules. Data is passed between each module as described below:

GKD-B => GKD-V => GKD-C(1) => GKD-C(2) => GKD-E => GKD-BT

That is, the Baseline indicator passes its data to Volatility/Volume. The Volatility/Volume indicator passes its values to the Confirmation 1 indicator. The Confirmation 1 indicator passes its values to the Confirmation 2 indicator. The Confirmation 2 indicator passes its values to the Exit indicator, and finally, the Exit indicator passes its values to the Backtest strategy.

This chaining of indicators requires that each module conform to Loxx's GKD protocol, therefore allowing for the testing of every possible combination of technical indicators that make up the six components of the NNFX algorithm.

What does the application of the GKD trading system look like?

Example trading system:

  • Backtest: Strategy with 1-3 take profits, trailing stop loss, multiple types of PnL volatility, and 2 backtesting styles
  • Baseline: Hull Moving Average
  • Volatility/Volume: Volatility Ratio as shown on the chart above
  • Confirmation 1: Vortex
  • Confirmation 2: Fisher Transform
  • Exit: Rex Oscillator


Each GKD indicator is denoted with a module identifier of either: GKD-BT, GKD-B, GKD-C, GKD-V, or GKD-E. This allows traders to understand to which module each indicator belongs and where each indicator fits into the GKD protocol chain.

Now that you have a general understanding of the NNFX algorithm and the GKD trading system. Let's go over what's inside the GKD-V Volatility Ratio itself.

What is Volatility Ratio?

Volatility Ratio is a comparison between volatility and its moving average. This indicator includes 11 different types of volatility as well as 63 different moving averages.

You can read about the moving average types here:
GKD-B Baseline [Loxx]


Volatility Types Included
v1.0 Included Volatility

Close-to-Close
Close-to-Close volatility is a classic and most commonly used volatility measure, sometimes referred to as historical volatility .

Volatility is an indicator of the speed of a stock price change. A stock with high volatility is one where the price changes rapidly and with a bigger amplitude. The more volatile a stock is, the riskier it is.

Close-to-close historical volatility calculated using only stock's closing prices. It is the simplest volatility estimator. But in many cases, it is not precise enough. Stock prices could jump considerably during a trading session, and return to the open value at the end. That means that a big amount of price information is not taken into account by close-to-close volatility .

Despite its drawbacks, Close-to-Close volatility is still useful in cases where the instrument doesn't have intraday prices. For example, mutual funds calculate their net asset values daily or weekly, and thus their prices are not suitable for more sophisticated volatility estimators.

Parkinson
Parkinson volatility is a volatility measure that uses the stock’s high and low price of the day.

The main difference between regular volatility and Parkinson volatility is that the latter uses high and low prices for a day, rather than only the closing price. That is useful as close to close prices could show little difference while large price movements could have happened during the day. Thus Parkinson's volatility is considered to be more precise and requires less data for calculation than the close-close volatility .

One drawback of this estimator is that it doesn't take into account price movements after market close. Hence it systematically undervalues volatility . That drawback is taken into account in the Garman-Klass's volatility estimator.

Garman-Klass
Garman Klass is a volatility estimator that incorporates open, low, high, and close prices of a security.

Garman-Klass volatility extends Parkinson's volatility by taking into account the opening and closing price. As markets are most active during the opening and closing of a trading session, it makes volatility estimation more accurate.

Garman and Klass also assumed that the process of price change is a process of continuous diffusion (Geometric Brownian motion). However, this assumption has several drawbacks. The method is not robust for opening jumps in price and trend movements.

Despite its drawbacks, the Garman-Klass estimator is still more effective than the basic formula since it takes into account not only the price at the beginning and end of the time interval but also intraday price extremums.

Researchers Rogers and Satchel have proposed a more efficient method for assessing historical volatility that takes into account price trends. See Rogers-Satchell Volatility for more detail.

Rogers-Satchell
Rogers-Satchell is an estimator for measuring the volatility of securities with an average return not equal to zero.

Unlike Parkinson and Garman-Klass estimators, Rogers-Satchell incorporates drift term (mean return not equal to zero). As a result, it provides a better volatility estimation when the underlying is trending.

The main disadvantage of this method is that it does not take into account price movements between trading sessions. It means an underestimation of volatility since price jumps periodically occur in the market precisely at the moments between sessions.

A more comprehensive estimator that also considers the gaps between sessions was developed based on the Rogers-Satchel formula in the 2000s by Yang-Zhang. See Yang Zhang Volatility for more detail.

Yang-Zhang
Yang Zhang is a historical volatility estimator that handles both opening jumps and the drift and has a minimum estimation error.

We can think of the Yang-Zhang volatility as the combination of the overnight (close-to-open volatility ) and a weighted average of the Rogers-Satchell volatility and the day’s open-to-close volatility . It considered being 14 times more efficient than the close-to-close estimator.

Garman-Klass-Yang-Zhang
Garman-Klass-Yang-Zhang (GKYZ) volatility estimator consists of using the returns of open, high, low, and closing prices in its calculation.

GKYZ volatility estimator takes into account overnight jumps but not the trend, i.e. it assumes that the underlying asset follows a GBM process with zero drift. Therefore the GKYZ volatility estimator tends to overestimate the volatility when the drift is different from zero. However, for a GBM process, this estimator is eight times more efficient than the close-to-close volatility estimator.

Exponential Weighted Moving Average
The Exponentially Weighted Moving Average (EWMA) is a quantitative or statistical measure used to model or describe a time series. The EWMA is widely used in finance, the main applications being technical analysis and volatility modeling.

The moving average is designed as such that older observations are given lower weights. The weights fall exponentially as the data point gets older – hence the name exponentially weighted.

The only decision a user of the EWMA must make is the parameter lambda. The parameter decides how important the current observation is in the calculation of the EWMA. The higher the value of lambda, the more closely the EWMA tracks the original time series.

Standard Deviation of Log Returns
This is the simplest calculation of volatility . It's the standard deviation of ln(close/close(1))

Pseudo GARCH(2,2)
This is calculated using a short- and long-run mean of variance multiplied by θ.

θavg(var ;M) + (1 − θ) avg (var ;N) = 2θvar/(M+1-(M-1)L) + 2(1-θ)var/(M+1-(M-1)L)

Solving for θ can be done by minimizing the mean squared error of estimation; that is, regressing L^-1var - avg (var; N) against avg (var; M) - avg (var; N) and using the resulting beta estimate as θ.

Average True Range
The average true range (ATR) is a technical analysis indicator, introduced by market technician J. Welles Wilder Jr. in his book New Concepts in Technical Trading Systems, that measures market volatility by decomposing the entire range of an asset price for that period.

The true range indicator is taken as the greatest of the following: current high less the current low; the absolute value of the current high less the previous close; and the absolute value of the current low less the previous close. The ATR is then a moving average, generally using 14 days, of the true ranges.

True Range Double
A special case of ATR that attempts to correct for volatility skew.

Signals
1. Traditional: The traditional signal is volatility is either high or low. This is non-directional. When the Volatility Ratio is above 1, then there is enough volatility to trade long or short. This signal type has a bar risings option that requires that the Volatility Ratio is not only above 1 but also rising for the last XX bars.
2. Crossing: This is experimental. When a cross-up above 1 or cross-down below one occurs then, and only then, is there enough volatility to trade long or short. This is also non-directional.
3. Both Traditional and Crossing

X-bar Rule
If a signal registers XX bars ago, then the signal is still valid. This is an optional feature.

Other things to note
The GKD trading system requires that a GKD-V indicator be present in the indicator chain, but the GKD-V indicator doesn't need to be active. You can turn on/off the Volatility Ratio as you wish so you can backtest your trading strategy with the filter on or off.

Additional features will be added in future releases.

This indicator is only available to ALGX Trading VIP group members . You can see the Author's Instructions below to get more information on how to get access.
Release Notes
Small update to Continuations. Removed Goldie Locks filtering for Continuations.
Release Notes
Input naming updates
Release Notes
Added ability to run solo backtests with just GKD-BT Backtest and this indicator alone
Release Notes
Small input update
Release Notes
Small input update
Release Notes
Added regular standard deviation
Release Notes
Added new Backtest type Baseline + Volatility/Volume

See here for details:
Release Notes
Added GKD Stacking Protocol. This allows any GKD-C, GKD-C, or GKD-C to be combined into a confluence stack of indicators. This stack can then be injected into a GKD-BT Backtest to test long and/or short signals.
Release Notes
Small error fix.
Release Notes
Updated to handle GKD-V stacks
Release Notes
Fixed small error
Release Notes
small fix
Release Notes
Added additional types of volatility added.

Standard Deviation
Standard deviation is a statistic that measures the dispersion of a dataset relative to its mean and is calculated as the square root of the variance. The standard deviation is calculated as the square root of variance by determining each data point's deviation relative to the mean. If the data points are further from the mean, there is a higher deviation within the data set; thus, the more spread out the data, the higher the standard deviation.

Adaptive Deviation
By definition, the Standard Deviation (STD, also represented by the Greek letter sigma σ or the Latin letter s) is a measure that is used to quantify the amount of variation or dispersion of a set of data values. In technical analysis we usually use it to measure the level of current volatility .

Standard Deviation is based on Simple Moving Average calculation for mean value. This version of standard deviation uses the properties of EMA to calculate what can be called a new type of deviation, and since it is based on EMA , we can call it EMA deviation. And added to that, Perry Kaufman's efficiency ratio is used to make it adaptive (since all EMA type calculations are nearly perfect for adapting).

The difference when compared to standard is significant--not just because of EMA usage, but the efficiency ratio makes it a "bit more logical" in very volatile market conditions.

See how this compares to Standard Devaition here:
Adaptive Deviation
Adaptive Deviation [Loxx]


Median Absolute Deviation
The median absolute deviation is a measure of statistical dispersion. Moreover, the MAD is a robust statistic, being more resilient to outliers in a data set than the standard deviation. In the standard deviation, the distances from the mean are squared, so large deviations are weighted more heavily, and thus outliers can heavily influence it. In the MAD, the deviations of a small number of outliers are irrelevant.

Because the MAD is a more robust estimator of scale than the sample variance or standard deviation, it works better with distributions without a mean or variance, such as the Cauchy distribution.

For this indicator, I used a manual recreation of the quantile function in Pine Script. This is so users have a full inside view into how this is calculated.

Efficiency-Ratio Adaptive ATR
Average True Range (ATR) is widely used indicator in many occasions for technical analysis . It is calculated as the RMA of true range. This version adds a "twist": it uses Perry Kaufman's Efficiency Ratio to calculate adaptive true range

See how this compares to ATR here:
ER-Adaptive ATR
ER-Adaptive ATR [Loxx]


Mean Absolute Deviation
The mean absolute deviation (MAD) is a measure of variability that indicates the average distance between observations and their mean. MAD uses the original units of the data, which simplifies interpretation. Larger values signify that the data points spread out further from the average. Conversely, lower values correspond to data points bunching closer to it. The mean absolute deviation is also known as the mean deviation and average absolute deviation.

This definition of the mean absolute deviation sounds similar to the standard deviation ( SD ). While both measure variability, they have different calculations. In recent years, some proponents of MAD have suggested that it replace the SD as the primary measure because it is a simpler concept that better fits real life.

For Pine Coders, this is equivalent of using ta.dev()

Weighted Deviation
This weighted deviation is a sort of all linear weighted deviation. It uses linear weighting in all the steps calculated (which makes it different from the built in deviation in a case when linear weighted ma is used in the ma method). It is more responsive than the standard deviation.

Read here:
Weighted Deviation Bands [Loxx]


Momentum Deviation
Momentum Deviation uses a variation of standard deviation. Instead of using price to calculate standard deviation, this uses momentum.

Read here:
Momentum Deviation Bands [Loxx]
Release Notes
input error fix
Release Notes
Library update
Release Notes
Updated for new GKD backtesting modules
Release Notes
small update
Release Notes
Additions and Subtractions:

-All signal logic has been transferred to the new GKD-BT Backtests. You can access these backtests using the links provided below:

GKD-BT Giga Confirmation Stack Backtest:
GKD-BT Giga Confirmation Stack Backtest [Loxx]


GKD-BT Giga Stacks Backtest:
GKD-BT Giga Stacks Backtest [Loxx]


GKD-BT Full Giga Kaleidoscope Backtest:
GKD-BT Full Giga Kaleidoscope Backtest [Loxx]


GKD-BT Solo Confirmation Super Complex Backtest:
GKD-BT Solo Confirmation Super Complex Backtest [Loxx]


GKD-BT Solo Confirmation Complex Backtest:
GKD-BT Solo Confirmation Complex Backtest [Loxx]


GKD-BT Solo Confirmation Simple Backtest:
GKD-BT Solo Confirmation Simple Backtest [Loxx]


-Removed all Volatility/Volume types except for Traditional. To backtest a GKD-V Volatility/Volume indicator you use the GKD-BT Giga Stacks Backtest without needing to change to crossing Volatility/Volume type.

-Implemented code optimizations to enhance the rendering speed of signals.

-Streamlined the export process by generating only a single value for export to other indicators or backtests. This exported value is named "Input into NEW GKD-BT Backtest."
Release Notes
Updated for multi-ticker GKD.
Release Notes
Added Optimizer functions.
gigakaleidoscopeGKDgkdvHistorical VolatilitykaleidoscopeloxxnnfxVolatilityvolatilityratio

Invite-only script

Access to this script is restricted to users authorized by the author and usually requires payment. You can add it to your favorites, but you will only be able to use it after requesting permission and obtaining it from its author. Contact loxx for more information, or follow the author's instructions below.

TradingView does not suggest paying for a script and using it unless you 100% trust its author and understand how the script works. In many cases, you can find a good open-source alternative for free in our Community Scripts.

Author's instructions

For instructions on how to access, send me a private message here on TradingView or message me using the contact information listed in my TradingView profile.

Want to use this script on a chart?

Warning: please read before requesting access.

Public Telegram Group, t.me/algxtrading_public

VIP Membership Info: patreon.com/algxtrading/membership
Also on:

Disclaimer