繁体   English   中英

如何显示带开/关键的指示器(Pine 脚本)

[英]How to show an Indicator with key On/Off (Pine Script)

//code

//@version=4
study("Enable test indicator ")

// in setup panel, I can enable or disable with instruction below

habilitaRSI = input(true, "Enable", type = input.bool, group = "RSI", inline = "RSI Period")

rsiLength = input (14, "RSI Comprimento", type = input.integer, group="RSI", inline = "RSI Period")
rsiVal = rsi(close, rsiLength)

// below I need Plot with display.all ou display.none  - depends on (if check is enable or not in setup panel)

if habilitaRSI
plot(rsi(close,14),display=display.all)
else
plot(rsi(close,14),display=display.none)

但是我在“IF”命令上遇到了这个错误

错误:Processando 脚本...第 18 行:无法在本地 scope 中使用“绘图”。

那么,我怎样才能 Plot 使用“IF”?

我只需要一个脚本中的 Plot 多个指标,并在设置面板中使用“检查启用”或“检查禁用”

为此,我在 Plot 命令中使用了一个参数(选项)(display.all 和/或 display.none)

喜欢: plot(rsi(close,14),display=display.none)

这取决于(是否在设置面板中启用检查)

plot() function 只能在全局 scope 中调用,不能从本地块执行。 直接在plot()series=参数中使用三元?:运算符 function,简化版本:

//@version=4 
study("Enable test indicator", overlay = false)
habilitaRSI = input(true, "Enable", type = input.bool, group = "RSI", inline = "RSI Period")
rsiLength = input (14, "RSI Comprimento", type = input.integer, group="RSI", inline = "RSI Period") 
rsiVal = rsi(close, rsiLength)
plot(habilitaRSI ? rsiVal : na) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM