1 Star 2 Fork 7

王布衣/ta-lib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
wave.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-04-26 17:53 +08:00 . 拟增加新的波浪推导方式
package waves
import "gitee.com/quant1x/num"
type Waves struct {
Trends []Trend
DataLength int
State Kind
LastHigh num.DataPoint
LastLow num.DataPoint
}
func (w *Waves) Len() int {
return len(w.Trends)
}
func (w *Waves) Push(data Data) {
high := num.DataPoint{X: data.Index, Y: data.High}
low := num.DataPoint{X: data.Index, Y: data.Low}
if w.DataLength == 0 {
t := Trend{
State: Unknown,
Peak: high,
Valley: low,
Periods: 1,
}
w.Trends = append(w.Trends, t)
} else {
n := w.Len()
lastTrend := &w.Trends[n-1]
diffHigh := high.Y - w.LastHigh.Y
diffLow := low.Y - w.LastLow.Y
switch w.State {
case Unknown: // 初始状态
if diffHigh > 0 {
w.State = Drive
} else if diffLow < 0 {
w.State = Adjust
}
case Drive: // 升高
if diffHigh > 0 {
lastTrend.Peak = high
} else {
// 趋势改变
w.State = Adjust
lastTrend.Valley = low
t := Trend{
State: Adjust,
Peak: high,
Valley: low,
Periods: 1,
}
w.Trends = append(w.Trends, t)
}
case Adjust: // 降低
if diffLow < 0 {
lastTrend.Valley = low
} else {
// 趋势改变
w.State = Drive
lastTrend.Peak = high
t := Trend{
State: Drive,
Peak: high,
Valley: low,
Periods: 1,
}
w.Trends = append(w.Trends, t)
}
}
}
w.LastHigh = high
w.LastLow = low
w.DataLength++
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/ta-lib.git
git@gitee.com:quant1x/ta-lib.git
quant1x
ta-lib
ta-lib
v0.8.15

搜索帮助