Tradingview: предупреждение не работает, когда линия импульса меняет цвет с зеленого на красный. Он предупреждает каждые 15 минут, если установлен на 15-минутном временном интервале: Tradingview - PullRequest
0 голосов
/ 17 июня 2020

Его импульс сглаживается 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")

На этом изображении показаны красная и зеленая линии - пересечение не важно, переход с зеленого на красный имеет значение Image line change from green to red

1 Ответ

0 голосов
/ 04 июля 2020

глядя на logi c, который вы используете для рисования линии, ваше предупреждение должно выглядеть примерно так: alertcondition(AvgColor != AvgColor[1], "Line Color Change")

при необходимости вам может потребоваться добавить дополнительные условия для соответствия только тогда, когда вы на самом деле построить линию. имеет смысл?

...