2023-07-10 08:54:22 +00:00
|
|
|
package indicatorv2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
2023-06-01 00:28:49 +00:00
|
|
|
|
|
|
|
type MACDStream struct {
|
|
|
|
*SubtractStream
|
|
|
|
|
|
|
|
shortWindow, longWindow, signalWindow int
|
|
|
|
|
2023-06-04 06:08:20 +00:00
|
|
|
FastEWMA, SlowEWMA, Signal *EWMAStream
|
|
|
|
Histogram *SubtractStream
|
2023-06-01 00:28:49 +00:00
|
|
|
}
|
|
|
|
|
2023-07-10 08:54:22 +00:00
|
|
|
func MACD2(source types.Float64Source, shortWindow, longWindow, signalWindow int) *MACDStream {
|
2023-06-01 00:28:49 +00:00
|
|
|
// bind and calculate these first
|
|
|
|
fastEWMA := EWMA2(source, shortWindow)
|
|
|
|
slowEWMA := EWMA2(source, longWindow)
|
|
|
|
macd := Subtract(fastEWMA, slowEWMA)
|
|
|
|
signal := EWMA2(macd, signalWindow)
|
|
|
|
histogram := Subtract(macd, signal)
|
|
|
|
return &MACDStream{
|
|
|
|
SubtractStream: macd,
|
|
|
|
shortWindow: shortWindow,
|
|
|
|
longWindow: longWindow,
|
|
|
|
signalWindow: signalWindow,
|
2023-06-04 06:08:20 +00:00
|
|
|
FastEWMA: fastEWMA,
|
|
|
|
SlowEWMA: slowEWMA,
|
|
|
|
Signal: signal,
|
|
|
|
Histogram: histogram,
|
2023-06-01 00:28:49 +00:00
|
|
|
}
|
|
|
|
}
|