Documentation
¶
Index ¶
- func AccelerationBands(high, low, close []float64) ([]float64, []float64, []float64)
- func AccumulationDistribution(high, low, close []float64, volume []int64) []float64
- func Aroon(high, low []float64) ([]float64, []float64)
- func Atr(period int, high, low, close []float64) ([]float64, []float64)
- func AwesomeOscillator(low, high []float64) []float64
- func BollingerBandWidth(middleBand, upperBand, lowerBand []float64) ([]float64, []float64)
- func BollingerBands(close []float64) ([]float64, []float64, []float64)
- func ChandelierExit(high, low, close []float64) ([]float64, []float64)
- func Ema(period int, values []float64) []float64
- func IchimokuCloud(high, low, close []float64) ([]float64, []float64, []float64, []float64, []float64)
- func Macd(close []float64) ([]float64, []float64)
- func Max(period int, values []float64) []float64
- func Min(period int, values []float64) []float64
- func Obv(close []float64, volume []int64) []int64
- func Rsi(close []float64) ([]float64, []float64)
- func Since(values []float64) []int
- func Sma(period int, values []float64) []float64
- func Std(period int, values []float64) []float64
- func StochasticOscillator(high, low, close []float64) ([]float64, []float64)
- func TypicalPrice(low, high, close []float64) ([]float64, []float64)
- func Vortex(high, low, close []float64) ([]float64, []float64)
- func WilliamsR(low, high, close []float64) []float64
- type Action
- func AwesomeOscillatorStrategy(asset Asset) []Action
- func BollingerBandsStrategy(asset Asset) []Action
- func BuyAndHoldStrategy(asset Asset) []Action
- func DefaultRsiStrategy(asset Asset) []Action
- func MacdAndRsiStrategy(asset Asset) []Action
- func MacdStrategy(asset Asset) []Action
- func RsiStrategy(asset Asset, sellAt, buyAt float64) []Action
- func TrendStrategy(asset Asset, count int) []Action
- func WilliamsRStrategy(asset Asset) []Action
- type Asset
- type StrategyFunction
- type Trend
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccelerationBands ¶ added in v1.2.0
Acceleration Bands. Plots upper and lower envelope bands around a simple moving average.
Upper Band = SMA(High * (1 + 4 * (High - Low) / (High + Low))) Middle Band = SMA(Close) Lower Band = SMA(Low * (1 + 4 * (High - Low) / (High + Low)))
Returns upper band, middle band, lower band.
func AccumulationDistribution ¶ added in v1.2.0
Accumulation/Distribution Indicator (A/D). Cumulative indicator that uses volume and price to assess whether a stock is being accumulated or distributed.
MFM = ((Close - Low) - (High - Close)) / (High - Low) MFV = MFM * Period Volume AD = Previous AD + CMFV
Returns ad.
func Aroon ¶
Aroon Indicator. It is a technical indicator that is used to identify trend changes in the price of a stock, as well as the strength of that trend. It consists of two lines, Arron Up, and Aroon Down. The Aroon Up line measures the strength of the uptrend, and the Aroon Down measures the strength of the downtrend. When Aroon Up is above Aroon Down, it indicates bullish price, and when Aroon Down is above Aroon Up, it indicates bearish price.
Aroon Up = ((25 - Period Since Last 25 Period High) / 25) * 100 Aroon Down = ((25 - Period Since Last 25 Period Low) / 25) * 100
Returns aroonUp, aroonDown
func Atr ¶
Average True Range (ATR). It is a technical analysis indicator that measures market volatility by decomposing the entire range of stock prices for that period.
TR = Max((High - Low), (High - Close), (Close - Low)) ATR = SMA TR
Returns tr, atr
func AwesomeOscillator ¶
Awesome Oscillator.
Median Price = ((Low + High) / 2). AO = 5-Period SMA - 34-Period SMA.
Returns ao.
func BollingerBandWidth ¶
Bollinger Band Width. It 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 volatity the band width widens, and during a period of low market volatity band width contracts.
Band Width = (Upper Band - Lower Band) / Middle Band
Returns bandWidth, bandWidthEma90
func BollingerBands ¶
Bollinger Bands.
Middle Band = 20-Period SMA. Upper Band = 20-Period SMA + 2 (20-Period Std) Lower Band = 20-Period SMA - 2 (20-Period Std)
Returns middle band, upper band, lower band.
func ChandelierExit ¶
Chandelier Exit. It 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
Returns chandelierExitLong, chandelierExitShort
func IchimokuCloud ¶
func IchimokuCloud(high, low, close []float64) ([]float64, []float64, []float64, []float64, []float64)
Ichimoku Cloud. Also known as Ichimoku Kinko Hyo, is a versatile indicator that defines support and resistence, identifies trend direction, gauges momentum, and provides trading signals.
Tenkan-sen (Conversion Line) = (9-Period High + 9-Period Low) / 2 Kijun-sen (Base Line) = (26-Period High + 26-Period Low) / 2 Senkou Span A (Leading Span A) = (Conversion Line + Base Line) / 2 Senkou Span B (Leading Span B) = (52-Period High + 52-Period Low) / 2 Chikou Span (Lagging Span) = Close plotted 26 days in the past.
Returns conversionLine, baseLine, leadingSpanA, leadingSpanB, laggingSpan
func Macd ¶
Moving Average Convergence Divergence (MACD).
MACD = 12-Period EMA - 26-Period EMA. Signal = 9-Period EMA of MACD.
Returns MACD, signal.
func Max ¶
Moving max for the given period. TODO: Not optimal. Needs to be done with a binary tree and a ring buffer.
func Min ¶
Moving min for the given period. TODO: Not optimal. Needs to be done with a binary tree and a ring buffer.
func Obv ¶
On-Balance Volume (OBV). It is a technical trading momentum indicator that uses volume flow to predict changes in stock price.
volume, if Close > Close-Prev
OBV = OBV-Prev + 0, if Close = Close-Prev
-volume, if Close < Close-Prev
Returns obv
func Rsi ¶
Relative Strength Index (RSI). It is a momentum indicator that measures the magnitude of recent price changes to evaluate overbought and oversold conditions.
RS = Average Gain / Average Loss RSI = 100 - (100 / (1 + RS))
Returns rs, rsi
func StochasticOscillator ¶
Stochastic Oscillator. It is a momentum indicator that shows the location of the close relative to high-low range over a set number of periods.
K = (Close - Lowest Low) / (Highest High - Lowest Low) * 100 D = 3-Period SMA of K
Returns k, d
func TypicalPrice ¶
Typical Price. It is another approximation of average price for each period and can be used as a filter for moving average systems.
Typical Price = (High + Low + Close) / 3
Returns typical price, 20-Period SMA.
func Vortex ¶
Vortex Indicator. It provides two oscillators that capture positive and negative trend movement. A bullish signal triggers when the positive trend indicator crosses above the negative trend indicator or a key level. A bearish signal triggers when the negative trend indicator crosses above the positive trend indicator or a key level.
+VM = Abs(Current High - Prior Low) -VM = Abd(Current Low - Prior High)
+VM14 = 14-Period Sum of +VM -VM14 = 14-Period Sum of -VM
TR = Max((High[i]-Low[i]), Abs(High[i]-Close[i-1]), Abs(Low[i]-Close[i-1])) TR14 = 14-Period Sum of TR
+VI14 = +VM14 / TR14 -VI14 = -VM14 / TR14
Based on https://school.stockcharts.com/doku.php?id=technical_indicators:vortex_indicator
Returns plusVi, minusVi
Types ¶
type Action ¶ added in v1.2.3
type Action int
Strategy action.
func AwesomeOscillatorStrategy ¶ added in v1.2.3
Awesome oscillator strategy function.
func BollingerBandsStrategy ¶ added in v1.2.3
Bollinger bands strategy function.
func BuyAndHoldStrategy ¶ added in v1.2.3
Buy and hold strategy. Buys at the beginning and holds.
func DefaultRsiStrategy ¶ added in v1.2.3
Default RSI strategy function. It buys below 30 and sells above 70.
func MacdAndRsiStrategy ¶ added in v1.2.3
MACD and RSI strategy.
func RsiStrategy ¶ added in v1.2.3
RSI strategy. Sells above sell at, buys below buy at.
func TrendStrategy ¶ added in v1.2.3
Trend strategy. Buy when trending up for count times, sell when trending down for count times.
func WilliamsRStrategy ¶ added in v1.2.3
Williams R strategy function.
type Asset ¶ added in v1.2.3
type Asset struct {
Date []time.Time
Open []float64
Close []float64
High []float64
Low []float64
Volume []int64
}
Asset values.
type StrategyFunction ¶ added in v1.2.3
Strategy function. It takes an Asset and returns actions for each row.
func MakeRsiStrategy ¶ added in v1.2.3
func MakeRsiStrategy(sellAt, buyAt float64) StrategyFunction
Make RSI strategy function.
func MakeTrendStrategy ¶ added in v1.2.3
func MakeTrendStrategy(count int) StrategyFunction
Make trend strategy function.
type Trend ¶
type Trend int
Trend indicator.
func ParabolicSar ¶
Parabolic SAR. It is a popular technical indicator for identifying the trend and as a trailing stop.
PSAR = PSAR[i - 1] - ((PSAR[i - 1] - EP) * AF)
If the trend is Falling:
- PSAR is the maximum of PSAR or the previous two high values.
- If the current high is greather than or equals to PSAR, use EP.
If the trend is Rising:
- PSAR is the minimum of PSAR or the previous two low values.
- If the current low is less than or equals to PSAR, use EP.
If PSAR is greater than the closing, trend is falling, and the EP is set to the minimum of EP or the low.
If PSAR is lower than or equals to the closing, trend is rising, and the EP is set to the maximum of EP or the high.
If the trend is the same, and AF is less than 0.20, increment it by 0.02. If the trend is not the same, set AF to 0.02.
Based on video https://www.youtube.com/watch?v=MuEpGBAH7pw&t=0s.
Returns psar, trend