我试图使我的指示器在穿过RSI上的高线(例如80度)时显示一个圆圈,但不会在80或以上的后续条/点上显示更多的圆圈,除非它首先越过较低的线(例如30度)。然后,我想让它在超过30的时候放一个圆圈,但不会再放在后面的柱子上(基本上和80的位置相反)。
我正在尝试使用“plotshape”,但如果不能将“plotshape”放入更复杂的IF语句/函数中,我就无法让它工作。但是“plotshape”不能在IF语句中使用,所以我完全被卡住了。在C++或类似的简单,但不是在松树脚本。
这段代码基本上是用来标记交叉点的,但我不知道如何停止它标记后面的条形图。
//@version=5
indicator(title='title', shorttitle='RSI', overlay=false)
green = color.new(color.green, 0)
red = color.new(color.red, 0)
yellow = color.new(color.yellow, 0)
top_line = input(title='Default bull-line', defval=80.0)
bot_line = input(title='Default bear-line', defval=30.0)
src = input(title='RSI Source', defval=close)
len = input(title='RSI Length', defval=13)
rsi = ta.rsi(src, len)
plot(rsi, color=yellow)
var int A = na
var int B = na
if rsi >= top_line and rsi[1] < top_line
A := 0
plotshape(rsi >= top_line and rsi[1] < top_line and A == 0, location=location.top, color=green, style=shape.circle, text='')
if rsi >= top_line and rsi[1] >= top_line
A := 1
if rsi <= bot_line and rsi[1] > bot_line
B := 0
plotshape(rsi <= bot_line and rsi[1] > bot_line and B == 0, location=location.bottom, color=red, style=shape.circle, text='')
if rsi >= bot_line and rsi[1] >= bot_line
B := 1
plot(top_line, title='bullish', color=green)
plot(bot_line, title='bearish', color=red)发布于 2021-11-13 14:35:06
我所需要做的就是向代码中添加一个计数器,而不是一个标志来使其工作。
if rsi >= top_line
A := A + 2
B := 0
if rsi <= bot_line
B := count2 + 2
A := 0然后,明显地对关联的表达式进行轻微的修改
发布于 2021-11-11 02:59:01
您可以使用ta.barssince()函数阻止它在交叉后标记以下条。
crossoverCondition = ...
crossover = ta.barssince(crossoverCondition) == 1
bgcolor(crossover ? color.green : na)而且,就像你说的,你不能在if语句下使用plotshape。你必须使用条件色。例如:
plot(close, color=close > ta.ema(close, 200) ? color.green : na)https://stackoverflow.com/questions/69921775
复制相似问题