You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
835 B

package indicator
import "sig-pub/pkg/types"
// WOBV 波动加权 OBV
// 1. 状态:WOBV_{t-1}。
// 2. 更新:WOBV_t = WOBV_{t-1} + [ (Close - Open) / (High - Low) × Volume_t ]。
// https://www.95sca.cn/archives/76688
// WOBV小策略: https://zhuanlan.zhihu.com/p/422341694
type WOBV struct {
}
func (c *WOBV) Meta() IndicatorMeta {
return IndicatorMeta{
Name: "wobv",
Input: []types.InputArg{}, // todo 无参指标tsdb存储
}
}
func (c *WOBV) CandlePeriods(ctx IIndicatorContext) int16 {
return 2
}
func (c *WOBV) Calculate(ctx IIndicatorContext) (vector float64) {
wobvPrev, ok := ctx.State().Get("wobv", 1)
if !ok {
wobvPrev = 0
}
k := ctx.Get(0)
wf := (k.CloseF64() - k.OpenF64()) / (k.HighF64() - k.LowF64())
wobv := wobvPrev + wf*k.VolF64()
ctx.State().Set("wobv", wobv)
vector = wobv
return
}