Browse Source

super_trend shadow plot

main
strange 7 months ago
parent
commit
6a4f76fda6
  1. 19
      pkg/indicator/super_trend.go

19
pkg/indicator/super_trend.go

@ -13,12 +13,15 @@ func (c SuperTrend) Meta() IndicatorMeta {
{Name: "window", Type: types.InputTypeUInt, Desc: "ATR周期(7/14)"},
{Name: "mul", Type: types.InputTypeUInt, Desc: "乘数(建议2-4)"},
},
State: []string{"direction"},
State: []string{"direction", "edge"},
Plots: []Plot{
{State: "vector", Type: PlotLine, Props: PlotProps{"color": ColorGreen, "lineWidth": 2}, Exps: []PlotExp{
{State: "vector", Type: PlotLine, Props: PlotProps{"color": ColorGreen, "lineWidth": 1}, Exps: []PlotExp{
{Exp: "direction == -1", Props: PlotProps{"color": ColorRed2}},
{Exp: "direction == 1", Props: PlotProps{"color": ColorGreen2}},
}},
{State: "vector,edge", Type: PlotShadow, Props: PlotProps{"shadowColor": "rgba(220, 66, 66, 0.15)"}, Exps: []PlotExp{
{Exp: "direction == 1", Props: PlotProps{"shadowColor": "rgba(146, 210, 204, 0.15)"}},
}},
},
}
}
@ -33,7 +36,8 @@ func (c SuperTrend) Calculate(ctx IIndicatorContext) (vector float64) {
atr := ctx.Indicator("ATR", window).Get(0)
hl2 := ctx.Get(0).HL2()
closeP := ctx.Get(0).CloseF64()
k := ctx.Get(0)
closeP := k.CloseF64()
upper := hl2 + mul*atr // 潛在上漲時的阻力位
lower := hl2 - mul*atr // 潛在下跌時的支撐位
@ -74,5 +78,14 @@ func (c SuperTrend) Calculate(ctx IIndicatorContext) (vector float64) {
}
ctx.State().Set("_trend", trend)
ctx.State().Set("direction", direction)
openP := k.OpenF64()
var edge float64
if direction == 1 {
edge = min(openP, closeP)
} else {
edge = max(openP, closeP)
}
ctx.State().Set("edge", edge)
return trend
}

Loading…
Cancel
Save