[英]PineScript: Plotshape when two conditions are met one after the other
[英]How to reset Pinescript valuewhen() after conditions are met?
我正在尝试创建一个脚本,以突出显示 SMMA 交叉发生时以及之后绘制威廉姆斯分形。
我正在使用 valuewhen() 来捕获交叉。 当分形打印并且 RSI 高于/低于 50 时,我使用存储的 valuewhen() 来验证是否满足交叉条件并可以突出显示该背景。
问题是,我不知道在满足条件后如何重置 valuewhen() 。
提供的屏幕截图显示了运行红色短裤和蓝色多头的脚本。 白色背景条是发生交叉的地方,我只希望它旁边的红色条突出显示(在 Fractal 打印之后),它表示一个条目。
这是我第一次写 Pinescript,所以对任何菜鸟错误表示歉意。
谢谢!
// @version=5
indicator(title = "3 SMMA Cross Strategy", shorttitle="3SMMA", overlay=true)
// smma
len1 = input.int(60, minval=1, title="Length")
src1 = input(close, title="Source")
_sma1 = ta.sma(src1, len1)
smma_21 = 0.0
smma_21 := na(smma_21[1]) ? _sma1 : (smma_21[1] * (len1 - 1) + src1) / len1
len2 = input.int(100, minval=1, title="Length")
src2 = input(close, title="Source")
_sma2 = ta.sma(src2, len2)
smma_50 = 0.0
smma_50 := na(smma_50[1]) ? _sma2 : (smma_50[1] * (len2 - 1) + src2) / len2
len3 = input.int(200, minval=1, title="Length")
src3 = input(close, title="Source")
_sma3 = ta.sma(src3, len3)
smma_200 = 0.0
smma_200 := na(smma_200[1]) ? _sma3 : (smma_200[1] * (len3 - 1) + src3) / len3
smma_cross_21_200 = ta.cross(smma_21,smma_200)
smma_cross_50_200 = ta.cross(smma_50,smma_200)
// rsi
_rsi = ta.rsi(close, 14)
// williams fractals
n = input.int(title="Periods", defval=2, minval=2)
dnFractal = (high[n-2] < high[n]) and (high[n-1] < high[n]) and (high[n+1] < high[n]) and (high[n+2] < high[n])
upFractal = (low[n-2] > low[n]) and (low[n-1] > low[n]) and (low[n+1] > low[n]) and (low[n+2] > low[n])
// begin conditionals
check_shorts = ta.valuewhen((smma_cross_21_200 or smma_cross_50_200) and ((smma_200 > smma_50 and smma_21) and ( smma_50 > smma_21 )), close, 1)
check_longs = ta.valuewhen((smma_cross_21_200 or smma_cross_50_200) and ((smma_200 < smma_50 and smma_21) and ( smma_50 < smma_21 )), close, 1)
TRANSP = 90
bgcolor( dnFractal and check_shorts and _rsi < 50 ? color.new(color.red, TRANSP) : na )
bgcolor( upFractal and check_longs and _rsi < 50 ? color.new(color.blue, TRANSP) : na )
_when(_cond, _update, _reset, _default)=> // {
varip _output = _default
_output := _reset ? _default : _cond ? _update : _output
_output
应该做。。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.