Skip to content

Latest commit

 

History

History
172 lines (120 loc) · 6.15 KB

volatility_indicators.md

File metadata and controls

172 lines (120 loc) · 6.15 KB

Volatility Indicators

Volatility indicators measure the rate of movement regardless of its direction.

Acceleration Bands

The AccelerationBands plots upper and lower envelope bands around a simple moving average.

Upper Band = SMA(High * (1 + 4 * (High - Low) / (High + Low)))
Middle Band = SMA(Closing)
Lower Band = SMA(Low * (1 + 4 * (High - Low) / (High + Low)))
upperBand, middleBand, lowerBand := indicator.AccelerationBands(high, low, closing)

Average True Range (ATR)

The Atr function calculates a technical analysis indicator that measures market volatility by decomposing the entire range of stock prices for that period.

TR = Max((High - Low), Abs(High - Previous Closing), Abs(Low - Previous Closing))
ATR = 14-Period SMA TR
tr, atr := indicator.Atr(14, high, low, closing)

Bollinger Bands

The BollingerBands function calculates the bollinger bands, middle band, upper band, lower band, provides identification of when a stock is oversold or overbought.

Middle Band = 20-Period SMA.
Upper Band = 20-Period SMA + 2 (20-Period Std)
Lower Band = 20-Period SMA - 2 (20-Period Std)
middleBand, upperBand, lowerBand := indicator.BollingerBands(closing)

Bollinger Band Width

The BollingerBandWidth function measures the percentage difference between the upper band and the lower band. It decreases as Bollinger Bands narrows and increases as Bollinger Bands widens.

During a period of rising price volatility the band width widens, and during a period of low market volatility band width contracts.

Band Width = (Upper Band - Lower Band) / Middle Band
bandWidth, bandWidthEma90 := indicator.BollingerBandWidth(middleBand, upperBand, lowerBand)

Chandelier Exit

The ChandelierExit function sets a trailing stop-loss based on the Average True Value (ATR).

Chandelier Exit Long = 22-Period SMA High - ATR(22) * 3
Chandelier Exit Short = 22-Period SMA Low + ATR(22) * 3
chandelierExitLong, chandelierExitShort := indicator.ChandelierExit(high, low, closing)

Donchian Channel (DC)

The DonchianChannel calculates three lines generated by moving average calculations that comprise an indicator formed by upper and lower bands around a midrange or median band. The upper band marks the highest price of an asset while the lower band marks the lowest price of an asset, and the area between the upper and lower bands represents the Donchian Channel.

Upper Channel = Mmax(period, closings)
Lower Channel = Mmin(period, closings)
Middle Channel = (Upper Channel + Lower Channel) / 2
upperChannel, middleChannel, lowerChannel := indicator.DonchianChannel(period, closing)

Keltner Channel (KC)

The KeltnerChannel provides volatility-based bands that are placed on either side of an asset's price and can aid in determining the direction of a trend.

Middle Line = EMA(period, closings)
Upper Band = EMA(period, closings) + 2 * ATR(period, highs, lows, closings)
Lower Band = EMA(period, closings) - 2 * ATR(period, highs, lows, closings)
upperBand, middleLine, lowerBand := indicator.KeltnerChannel(period, high, low, closing)

The DefaultKeltnerChannel calculates it with the default period of 20.

upperBand, middleLine, lowerBand := indicator.DefaultKeltnerChannel(high, low, closing)

Moving Standard Deviation (Std)

The Std function calculates the moving standard deviation for a given period.

result := indicator.Std(2, []float64{2, 4, 6, 8, 12, 14, 16, 18, 20})

Projection Oscillator (PO)

The ProjectionOscillator calculates the Projection Oscillator (PO). The PO uses the linear regression slope, along with highs and lows.

Period defines the moving window to calculates the PO, and the smooth period defines the moving windows to take EMA of PO.

PL = Min(period, (high + MLS(period, x, high)))
PU = Max(period, (low + MLS(period, x, low)))
PO = 100 * (Closing - PL) / (PU - PL)
SPO = EMA(smooth, PO)
po, spo := indicator.ProjectionOscillator(12, 4, high, low, closing)

Ulcer Index (UI)

The UlcerIndex measures downside risk. The index increases in value as the price moves farther away from a recent high and falls as the price rises to new highs.

High Closings = Max(period, Closings)
Percentage Drawdown = 100 * ((Closings - High Closings) / High Closings)
Squared Average = Sma(period, Percent Drawdown * Percent Drawdown)
Ulcer Index = Sqrt(Squared Average)
ui := indicator.UlcerIndex(period, closing)

The DefaultUlcerIndex measures the ulcer index with the default period of 14.

ui := indicator.DefaultUlcerIndex(closing)

Disclaimer

The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.

License

Copyright (c) 2021 Onur Cinar. All Rights Reserved.

The source code is provided under MIT License.