首页 > 解决方案 > Tradingview:当动量线从绿色变为红色时,警报不起作用。当设置为 15 分钟时间范围时,它每 15 分钟提醒一次:Tradingview

问题描述

当它的超卖或超买改变颜色时,它的动量有 4 种方式平滑

//@version=4
study("Momentum 4 Ways Smoothed [Salty]", shorttitle="Momentum4WaysSmoothed")
src = input(ohlc4, title="Source")

USE_VWAP = input(false, title="Use VWAP instead of price when calculating momentum")
a = input(true, title="Show Momentum 1")
b = input(false, title="Show Momentum 2")
c = input(false, title="Show Momentum 3")
d = input(false, title="Show Momentum 4")
e = input(true, title="Show Average of 4 Momentum Values")
f = input(true, title="Smooth Average of 4 Momentum Values")

// MA calculation
smoothinput = input(3, minval=1, maxval=4, title='Moving Average Calculation: (1 = SMA), (2 = EMA), (3 = WMA), (4 = Linear)')
smoothperiod = input(5, title="Smoothing Moving Average Length")

//Allow 1 to 4 momentum values to be used in the calculation of the average
NumberMomInput = input(4, minval=1, maxval=4, title='Number of Momentum Values to use in Average Calculation: (1-4)')

length1 = input(5, minval=1, title="Momentum Length 1")
length2 = input(10, minval=1, title="Momentum Length 2")
length3 = input(15, minval=1, title="Momentum Length 3")
length4 = input(20, minval=1, title="Momentum Length 4")

// This shows 4 different ways to calculate momentum
mom1 = USE_VWAP ? vwap - vwap[length1] : src - src[length1]
mom2 = USE_VWAP ? change(vwap, length2) : change(src, length2)
mom3 = USE_VWAP ? mom(vwap, length3) : mom(src, length3)
sma1 = USE_VWAP ? sma(vwap, length4) : sma(src, length4)
mom4 = (sma1 - sma1[1]) * length4

// This combines the 4 momentum values to highlight the effect of the fast momentum values on the slow momentum values
mom4avg = NumberMomInput == 1 ? mom1 : NumberMomInput == 2 ? (mom1 + mom2)/NumberMomInput : NumberMomInput == 3 ? (mom1 + mom2 + mom3)/NumberMomInput : (mom1 + mom2 + mom3 + mom4) / 4

sma_1 = sma(mom4avg, smoothperiod)
ema_1 = ema(mom4avg, smoothperiod)
wma_1 = wma(mom4avg, smoothperiod)
linreg_1 = linreg(mom4avg, smoothperiod, 0)
smoothed_mom4avg = smoothinput == 1 ? sma_1 : smoothinput == 2 ? ema_1 : 
   smoothinput == 3 ? wma_1 : smoothinput == 4 ? linreg_1 : na

AvgColor = smoothed_mom4avg >= smoothed_mom4avg[1]
AvgColor1 = smoothed_mom4avg <= smoothed_mom4avg[1]

plot(a and mom1 ? mom1 : na, title="M 1", color=color.lime, style=plot.style_stepline, linewidth=1)
plot(b and mom2 ? mom2 : na, title="M 2", color=color.green, style=plot.style_line, linewidth=1)
plot(c and mom3 ? mom3 : na, title="M 3", color=color.red, style=plot.style_histogram, linewidth=1)
plot(d and mom4 ? mom4 : na, title="M 4", color=color.maroon, style=plot.style_columns, linewidth=1)
plot(e and mom4avg ? mom4avg : na, title="4 M", style=plot.style_stepline, color=color.gray, linewidth=1)
plot(f and smoothed_mom4avg ? smoothed_mom4avg : na, title="S4 combined", style=plot.style_line, color= AvgColor ? color.lime : color.red, transp=0, linewidth=2)
zeroline = hline(0, title="Zero Line", color=color.black, linestyle=hline.style_dotted, linewidth=1)
//AvgColor = falling(smoothed_mom4avg,1)
//Alert

// 警报不起作用它应该在从绿色变为红色或从红色变为绿色时发出警报

alertcondition (condition = (smoothed_mom4avg > smoothed_mom4avg[1]) or (smoothed_mom4avg < smoothed_mom4avg[1] ) ,message="{{ticker}} : {{close}} Momentum Color Change")

此图像显示红线和绿线 - 交叉并不重要,从绿色变为红色很重要 图像线从绿色变为红色

标签: alertpine-script

解决方案


看看你用来画线的逻辑,你的警报应该是这样的: alertcondition(AvgColor != AvgColor[1], "Line Color Change")

如果需要,您可能需要添加其他条件以仅在实际绘制线时进行匹配。说得通?


推荐阅读