![](/img/trans.png)
[英]PineScript: Plotshape when two conditions are met one after the other
[英]Pine Script: Paint label when two conditions are met one after the other
一旦在多个条上一个接一个满足两个条件,我就会尝试绘制标签。
首先,4K-sma 与5K-sma 交叉,然后在下一次oneK-sma 与oneD-sma 交叉时,它会绘制一个标签。
ATM 脚本保存得很好,但没有绘制标签,而且我已经没有关于如何解决这个问题的想法。
oneK=sma(stoch(close, high, low, 11), 10)
oneD=sma(oneK, 4)
fourK=sma(stoch(close, high, low, 176), 160)
fiveK=sma(stoch(close, high, low, 352), 320)
test=bool(na)
fir=bool(na)
if (crossover(fourK,fiveK))
test:=true
if (test==true) and crossover(oneK,oneD)
fir:=true
test:=false
plotshape(fir, style = shape.arrowup, location = location.belowbar, color=#ff4545, size=size.small)
问题是:
var
关键字的情况下声明变量,因此它们在每个条形上都被初始化。fir
设置为 true,您就再也不会将其重置为 false。这将起作用:
//@version=4
study("SO 64706821", overlay=true, shorttitle="SO")
oneK = sma(stoch(close, high, low, 11), 10)
oneD = sma(oneK, 4)
fourK = sma(stoch(close, high, low, 176), 160)
fiveK = sma(stoch(close, high, low, 352), 320)
var bool test = na // Initializion occurs once, on first bar
bool fir = false // Initializion occurs on every bar
if crossover(fourK,fiveK)
test := true
if test and crossover(oneK,oneD)
fir := true
test := false
plotshape(fir, style = shape.arrowup, location = location.belowbar, color=color.red, size=size.small)
// Background color to make it more clear where the signals occur, because there are so few.
bgcolor(fir ? color.yellow : na, transp=80)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.