【发布时间】:2020-01-07 00:58:38
【问题描述】:
好的。因此,我正在尝试为绘图之间的填充进行切换。
这样一来,填充并不总是出现,而是仅在我需要时出现,并且仅在我想要的地块之间,而不是所有的地块之间。
我认为,第一步是对填充进行切换——真或假。之后再使用“if”,如下图。
//@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)
这会引发错误"Undeclared identifier p8;..." 等等......
我在这里做错了什么?
还有一个我在做的,它抛出了一个错误,说“fill cannot be used in local...”等,大意是这样。
编辑:9-4-19 根据 baris 的建议。但是他的想法完全打开/关闭了填充线图,所以我尝试为单个填充设置开关,但这也不起作用。
所以我仍然无法想出一个开关,让我: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)
理想情况下,线条可以单独关闭和打开,填充也可以单独关闭和打开。
这只是我的一些逻辑问题还是交易视图的限制?
【问题讨论】:
标签: if-statement plot switch-statement pine-script