我正在尝试在指定条件下绘制标识符;但是,在找到指定条件的第一个匹配项(H2_RG-如下)之后,我无法停止脚本。
//@version=4
study("Optimus Prime", overlay=true, scale=scale.none)
//H0_RG conditions and declarations
H0_RG = open > close
//H1_RG conditions and declarations
H1_RG = H0_RG[1] and open < close
//H2_RG conditions and declarations
H2_RG = high[barssince(H1_RG)] < high and low[barssince(H1_RG)] <= low
plotshape(H1_RG, color=color.red, style=shape.arrowdown)
plotshape(H2_RG, color=color.yellow, style=shape.arrowdown)
使用此脚本,我绘制了多个H2_RG事件,但只希望在H1_RG之后的第一个事件发生。任何帮助将不胜感激。
答案 0 :(得分:2)
使用一个变量来指示条件是否以前发生过。然后在您的H2_RG条件下检查该变量的值。
以下代码只会绘制一次H2_RG。
//@version=4
study("Optimus Prime", overlay=true, scale=scale.none)
var isH2occured = false
//H0_RG conditions and declarations
H0_RG = open > close
//H1_RG conditions and declarations
H1_RG = H0_RG[1] and open < close
//H2_RG conditions and declarations
H2_RG = not isH2occured and high[barssince(H1_RG)] < high and low[barssince(H1_RG)] <= low
if (H2_RG)
isH2occured := true
plotshape(H1_RG, color=color.red, style=shape.triangledown, size=size.small)
plotshape(H2_RG, color=color.yellow, style=shape.triangledown, size=size.small)