跨时间周期Supertrend指标信号反向问题求助
问题解决思路
- 核心问题:你搞反了Pine Script v6中
ta.supertrend()返回的direction值定义 - 正确逻辑:
ta.supertrend()的第二个返回值direction,当周期处于多头趋势(价格在Supertrend指标上方)时,值为-1;空头趋势(价格在指标下方)时,值为1。你之前用direction > 0判断的是空头信号,所以才会和预期反向。
修改后的代码如下:
//@version=6 indicator("Z-Score Indikator", overlay=true) // Eingabeparameter supertrendFactor = input.int(3, "Supertrend Faktor") supertrendATR = input.int(10, "Supertrend ATR Perioden") // 3. H1 Supertrend Richtung [h1Supertrend, h1Direction] = request.security(syminfo.tickerid, "60", ta.supertrend(supertrendFactor, supertrendATR)) // 修改判断条件,用direction < 0识别多头信号 condition3 = h1Direction < 0 bgcolor(condition3 ? color.new(color.blue, 85) : na)
如果需要验证方向是否正确,可以额外把60分钟的Supertrend指标画在当前图表上对比:
// 新增:在当前周期画出60分钟的Supertrend线 plot(h1Supertrend, color=h1Direction < 0 ? color.green : color.red, linewidth=2)
这样就能直观看到60分钟Supertrend的位置和方向,确认背景色触发逻辑是否正确。
内容的提问来源于stack exchange,提问作者Werner
相关产品推荐
相关产品推荐

