If statement 仅当满足条件时,才打开曲线图之间的填充
嗯。所以我试图在两个图之间切换填充 这样一来,填充并不总是出现,但只有在我想要的时候,并且只有在我想要的绘图之间,而不是所有的绘图之间 我想,第一步是对填充进行切换——对还是错。然后稍后使用“if”,如下所示If statement 仅当满足条件时,才打开曲线图之间的填充,if-statement,plot,switch-statement,pine-script,If Statement,Plot,Switch Statement,Pine Script,嗯。所以我试图在两个图之间切换填充 这样一来,填充并不总是出现,但只有在我想要的时候,并且只有在我想要的绘图之间,而不是所有的绘图之间 我想,第一步是对填充进行切换——对还是错。然后稍后使用“if”,如下所示 //@version=3 study("fill ema test") //---input switches for the emas ei8 = input(true, title="ema 8") ei100 = input(true, title="ema 100") ei20
//@version=3
study("fill ema test")
//---input switches for the emas
ei8 = input(true, title="ema 8")
ei100 = input(true, title="ema 100")
ei200 = input(true, title="ema 200")
//---input switch attempts for the fills.
// ef8 = input(false, title= "fill e8/e100")
// ef100 = input(false, title= "fill e100/e200")
// ef200 = input(false, title="fill e8/e200")
efp= input(false, title="fill in the emas")
//----ema calc
e8 = ema(close, 8)
e100 = ema(close, 100)
e200 = ema(close, 200)
//----plots. checks if the switch for the emas are on and then plots.
ep8 = plot(ei8 and e8?e8:na, color= e8>=e100? green:red)
ep100 = plot(ei100 and e100?e100:na, color= e100>=e200? blue:purple)
ep200 = plot(ei200 and e200?e200:na, color= gray)
//---- now if i make this if statement here, then i can
if efp
ep8= p8
ep100=p100
ep200=p200
fill(p8, p100, color=teal)
fill(p100, p200, color=olive)
fill(p8, p200, color=green)
抛出错误“未声明的标识符p8;…”等
我做错了什么
还有一个是我做的,它抛出了一个错误,说“fill不能用在local…”等等,大意是这样的
谢谢你的建议
编辑:9-4-19根据巴里斯的建议。但是他的想法是完全用填充来打开/关闭线图,所以我试着为单个填充设置开关,但这也不起作用 所以,我仍然有一些问题,比如说,我不能想出一个开关,让我:1。绘制单个EMA,2。用另一个选择填充单个EMA
//@version=3
study("fill ema test")
//---input switches for the emas
ei8 = input(true, title="ema 8")
ei100 = input(true, title="ema 100")
ei200 = input(true, title="ema 200")
//----ema calc
e8 = ema(close, 8)
e100 = ema(close, 100)
e200 = ema(close, 200)
//---input switch attempts for the fills. this added to the plot will turn fills on or off but only along with the plots.
// ef8 = input(false, title= "fill e8/e100")
// ef100 = input(false, title= "fill e100/e200")
// ef200 = input(false, title="fill e8/e200")
efp= input(true, title="fill in the emas")
//----plots. checks if the switch for the emas are on and then plots.
ep8 = plot(ei8 and e8 and efp?e8:na, color= e8>=e100? green:red)
ep100 = plot(ei100 and e100 and efp?e100:na, color= e100>=e200? blue:purple)
ep200 = plot(ei200 and e200 and efp?e200:na, color= gray)
fill(ep8, ep100, color=teal)
fill(ep100, ep200, color=olive)
fill(ep8, ep200, color=green)
执行以下操作将打印所有直线和填充,但同时分别禁用它们
ef8 = input(true, title= "fill e8/e100")
ef100 = input(true, title= "fill e100/e200")
ef200 = input(true, title="fill e8/e200")
// efp= input(true, title="fill in the emas")
//----plots. checks if the switch for the emas are on and then plots.
// ep8 = plot(ei8 and e8 and efp?e8:na, color= e8>=e100? green:red)
// ep100 = plot(ei100 and e100 and efp?e100:na, color= e100>=e200? blue:purple)
// ep200 = plot(ei200 and e200 and efp?e200:na, color= gray)
ep8 = plot(ei8 and e8 and ef8?e8:na, color= e8>=e100? green:red)
ep100 = plot(ei100 and e100 and ef100?e100:na, color= e100>=e200? blue:purple)
ep200 = plot(ei200 and e200 and ef200?e200:na, color= gray)
fill(ep8, ep100, color=teal)
fill(ep100, ep200, color=olive)
fill(ep8, ep200, color=green)
理想情况下,可以单独关闭和打开线条,也可以单独关闭和打开填充
这只是我遇到的一些逻辑问题还是tradingview的局限性?错误消息清楚地告诉您做错了什么。您尚未声明这些变量:
p8
、p100
和p200
。通过查看代码,您不需要这些变量,只需分别使用ep8
、ep100
和ep200
if efp
fill(ep8, ep100, color=teal)
fill(ep100, ep200, color=olive)
fill(ep8, ep200, color=green)
如果执行此操作,将出现以下错误:
line 31: Cannot use 'fill' in local scope.;
line 32: Cannot use 'fill'in local scope.;
line 33: Cannot use 'fill' in local scope.
您不能在本地作用域中调用fill()
(以及一些其他函数)(如果此处为块)
只需将条件添加到plot()
函数的series
参数中即可
ep8 = plot(ei8 and e8 and efp?e8:na, color= e8>=e100? green:red)
ep100 = plot(ei100 and e100 and efp?e100:na, color= e100>=e200? blue:purple)
ep200 = plot(ei200 and e200 and efp?e200:na, color= gray)
注意和efp
条件
因此,两者结合起来:
//----plots. checks if the switch for the emas are on and then plots.
ep8 = plot(ei8 and e8 and efp?e8:na, color= e8>=e100? green:red)
ep100 = plot(ei100 and e100 and efp?e100:na, color= e100>=e200? blue:purple)
ep200 = plot(ei200 and e200 and efp?e200:na, color= gray)
//---- now if i make this if statement here, then i can
fill(ep8, ep100, color=teal)
fill(ep100, ep200, color=olive)
fill(ep8, ep200, color=green)
但是我确实在if语句中定义了它们,我猜“if”中的定义不起作用?好吧,我尝试了一些不同的方法来实现它,但这会关闭整个绘图,而不填充。如果我打开填充,它将绘制它们,但你不能关闭填充。我将在我编辑的帖子中展示我所做的。