-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmacd.go
56 lines (51 loc) · 2.55 KB
/
macd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package tart
// Developed by Gerald Appel in the late seventies, the
// Moving Average Convergence/Divergence oscillator (MACD)
// is one of the simplest and most effective momentum indicators
// available. The MACD turns two trend-following indicators,
// moving averages, into a momentum oscillator by subtracting
// the longer moving average from the shorter one. As a result,
// the MACD offers the best of both worlds: trend following and
// momentum. The MACD fluctuates above and below the zero line
// as the moving averages converge, cross and diverge. Traders
// can look for signal line crossovers, centerline crossovers
// and divergences to generate signals. Because the MACD is
// unbounded, it is not particularly useful for identifying
// overbought and oversold levels.
// https://school.stockcharts.com/doku.php?id=technical_indicators:moving_average_convergence_divergence_macd
// https://www.investopedia.com/terms/m/macd.asp
// https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/macd
type Macd struct {
*MacdExt
}
func NewMacd(fastN, slowN, signalN int64) *Macd {
return &Macd{
MacdExt: NewMacdExt(EMA, fastN, EMA, slowN, EMA, signalN),
}
}
// Developed by Gerald Appel in the late seventies, the
// Moving Average Convergence/Divergence oscillator (MACD)
// is one of the simplest and most effective momentum indicators
// available. The MACD turns two trend-following indicators,
// moving averages, into a momentum oscillator by subtracting
// the longer moving average from the shorter one. As a result,
// the MACD offers the best of both worlds: trend following and
// momentum. The MACD fluctuates above and below the zero line
// as the moving averages converge, cross and diverge. Traders
// can look for signal line crossovers, centerline crossovers
// and divergences to generate signals. Because the MACD is
// unbounded, it is not particularly useful for identifying
// overbought and oversold levels.
// https://school.stockcharts.com/doku.php?id=technical_indicators:moving_average_convergence_divergence_macd
// https://www.investopedia.com/terms/m/macd.asp
// https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/macd
func MacdArr(in []float64, fastN, slowN, signalN int64) ([]float64, []float64, []float64) {
macd := make([]float64, len(in))
signal := make([]float64, len(in))
hist := make([]float64, len(in))
m := NewMacd(fastN, slowN, signalN)
for i, v := range in {
macd[i], signal[i], hist[i] = m.Update(v)
}
return macd, signal, hist
}