如果满足条件如何停止脚本?

How to stop the script if a condition is met?

(P.S。我有一个类似的问题,但我删除了它并写了这个简化的)

脚本有一个开始搜索条件的起点,从这一点开始,当首先满足这 3 个条件中的任何一个时,我需要停止从该点开始绘制任何东西,如果满足相同的条件,则包括在内以后再来。

对于虚拟脚本,我对这 3 个条件中的每一个都使用了 3 个 EMA 交叉,因此如果 close 将首先穿过 ema50,那么将来应该不会再有任何交叉图他们,基本上脚本应该就此停止。

这是我能达到的最远距离,我的做法是不绘制任何东西。

编辑:我根据 LucF 的回答更新了脚本,效果很好(满足这 3 个条件之一后没有绘图或 plotshapes 绘制,但我仍然需要第一个 condition/plotshape 绘制在图表。

//@version=4
study("My Script", overlay = true)

//time reset
ttt = input(title = "Date", defval = timestamp("25 Apr 2021 00:00 +0000"), type = input.time, inline = "time")
tz = input(0, title="TimeZone", type=input.integer, inline = "time")

timeadj = time + tz * 60 * 60 * 1000
t1 = timeadj >= ttt ? 1 : 0
bgcolor(t1 ? color.new(color.aqua, 95) :na)

//emas
ema50  = ema(close, 50)
ema100 = ema(close, 100)
ema200 = ema(close, 200)

//conditions
bool ema50_cross = crossover(close, ema50) and t1
bool ema100_cross = crossover(close, ema100) and t1
bool ema200_cross = crossover(close, ema200) and t1
var bool stopPlotting = false
stopPlotting := stopPlotting or ema50_cross or ema100_cross or ema200_cross

//plots
plot(not stopPlotting ? ema50  :na, color = color.yellow)
plot(not stopPlotting ? ema100 :na, color = color.purple)
plot(not stopPlotting ? ema200 :na, color = color.aqua)

//plotshapes
plotshape(not stopPlotting ? ema50_cross :na, color = color.yellow, size = size.small)
plotshape(not stopPlotting ? ema100_cross :na, color = color.purple, size = size.small)
plotshape(not stopPlotting ? ema200_cross :na, color = color.aqua, size = size.small)

每当您的一个十字出现时,这将停止绘图:

//@version=4
study("My Script", overlay = true)

ema50  = ema(close, 50)
ema100 = ema(close, 100)
ema200 = ema(close, 200)

bool ema50_cross = crossover(close, ema50)
bool ema100_cross = crossover(close, ema100)
bool ema200_cross = crossover(close, ema200)
var bool stopPlotting = false
stopPlotting := stopPlotting or ema50_cross or ema100_cross or ema200_cross

plot(not stopPlotting ? ema50  :na, color = color.yellow)
plot(not stopPlotting ? ema100 :na, color = color.purple)
plot(not stopPlotting ? ema200 :na, color = color.aqua)
    
plotshape(ema50_cross, color = color.yellow, size = size.small)
plotshape(ema100_cross, color = color.purple, size = size.small)
plotshape(ema200_cross, color = color.aqua, size = size.small)