diff --git a/pkg/indicator/super_trend.go b/pkg/indicator/super_trend.go index c221066..c5a9248 100644 --- a/pkg/indicator/super_trend.go +++ b/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 }