Warm tip: This article is reproduced from serverfault.com, please click

其他-Pine-Script如何在RSI图形上发送有关颜色变化的警报

(其他 - Pine-script how to send alert on color change on RSI graph)

发布于 2020-12-09 20:47:37

我正在使用以下来自(https://in.tradingview.com/script/fH6e5TuN-RSI-Divergence/)的脚本

study(title="RSI Divergence", shorttitle="RSI Divergence")
src_fast = close, len_fast = input(5, minval=1, title="Length Fast RSI")
src_slow = close, len_slow = input(14,minval=1, title="Length Slow RSI")
up_fast = rma(max(change(src_fast), 0), len_fast)
down_fast = rma(-min(change(src_fast), 0), len_fast)
rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
up_slow = rma(max(change(src_slow), 0), len_slow)
down_slow = rma(-min(change(src_slow), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
divergence = rsi_fast - rsi_slow
plotdiv = plot(divergence, color = divergence > 0 ? lime:red, linewidth = 2)
band = hline(0)

// ALERT section that I added which does not work: -------------------------------
divlong = divergence < 0 and divergence >=0
divshort = divergence > 0 and divergence <=0

alertcondition(divlong, title='Div Long', message='Div Long')
alertcondition(divshort, title='Div Short', message='Div Short')

data1 = divlong
plotshape(data1, style=shape.triangleup,location=location.bottom, color=green , title="DivUp")

data2 = divshort
plotshape(data2, style=shape.triangledown, location=location.top, color=red,title="DivDown")

[Q]是否可以设置警报,使其在信号线更改颜色(从红色变为绿色/从绿色变为红色)时触发?


我想显示可以触发警报的点。

在此处输入图片说明

Questioner
alper
Viewed
0
1,489 2021-01-20 23:34:14

你的警报触发从来没有,因为价值观divlongdivshort总是假的:

divlong = divergence < 0 and divergence >=0
divshort = divergence > 0 and divergence <=0

这将起作用:

study(title="RSI Divergence", shorttitle="RSI Divergence")

src_fast = close, len_fast = input(5, minval=1, title="Length Fast RSI")
src_slow = close, len_slow = input(14,minval=1, title="Length Slow RSI")
up_fast = rma(max(change(src_fast), 0), len_fast)
down_fast = rma(-min(change(src_fast), 0), len_fast)
rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
up_slow = rma(max(change(src_slow), 0), len_slow)
down_slow = rma(-min(change(src_slow), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
divergence = rsi_fast - rsi_slow
plotdiv = plot(divergence, color = divergence > 0 ? lime:red, linewidth = 2)
band = hline(0)

// ALERT section that I added which does not work: -------------------------------
// divlong = divergence < 0 and divergence >=0
// divshort = divergence > 0 and divergence <=0
divergence_past = divergence[1]
divlong = divergence >=0 and divergence_past <= 0
divshort = divergence <=0 and divergence_past >= 0


alertcondition(divlong, title='Div Long', message='Div Long')
alertcondition(divshort, title='Div Short', message='Div Short')

data1 = divlong
plotshape(data1, style=shape.triangleup,location=location.bottom, color=green , title="DivUp")

data2 = divshort
plotshape(data2, style=shape.triangledown, location=location.top, color=red,title="DivDown")