[英]Automatic checkbox 1 unchecking when 2nd is checked (like switch) - Pine script V5
I'm trying to make a switch for 2 different value sets, for RSI strategy(just for example bullish and bearish) Can't figure out how to implement automatic checkbox unchecking when checked another in pine script, even if the logic is working, I still need uncheck 1st and check 2nd checkbox我正在尝试为 2 个不同的值集进行切换,用于 RSI 策略(例如看涨和看跌)无法弄清楚如何在 pine 脚本中检查另一个时实现自动复选框取消选中,即使逻辑正在运行,我仍然需要取消选中第一个并选中第二个复选框
here is a script这是一个脚本
`//Switches
switchBull = input.bool(defval = true, title = "Bullish", group = "Bullish/Bearish Market Settings")
switchBear = input.bool(defval = false, title = "Bearish", group = "Bullish/Bearish Market Settings")
// RSI Bullish Inputs
bull_rsilength = input.int(defval = 12, title = "RSI Length", minval = 0, group = "RSI Bullish Settings")
bull_buyLevel = input.float(defval = 30, title = "RSI Buy Level", minval = 0, maxval = 100, step = 0.1, group = "RSI Bullish Settings")
bull_sellLevel = input.float(defval = 70, title = "RSI Sell Level", minval = 0, maxval = 100, step = 0.1, group = "RSI Bullish Settings")
bull_rsiOffset = input.int(defval = 0, title = "RSI Offset", minval = 0, group = "RSI Bullish Settings")
bull_rsi_src = input.source(defval = close, title = "Price Source", group = "RSI Bullish Settings")
// RSI Bearish Inputs
bear_rsilength = input.int(defval = 12, title = "RSI Length", minval = 0, group = "RSI Bearish Settings")
bear_buyLevel = input.float(defval = 30, title = "RSI Buy Level", minval = 0, maxval = 100, step = 0.1, group = "RSI Bearish Settings")
bear_sellLevel = input.float(defval = 70, title = "RSI Sell Level", minval = 0, maxval = 100, step = 0.1, group = "RSI Bearish Settings")
bear_rsiOffset = input.int(defval = 0, title = "RSI Offset", minval = 0, group = "RSI Bearish Settings")
bear_rsi_src = input.source(defval = close, title = "Price Source", group = "RSI Bearish Settings")
//Switching variables
var int rsilength = na
var float buyLevel = na
var float sellLevel = na
var float rsiOffset = na
var float rsi_src = na
//Switching Logic
if switchBull == true and switchBear == false
rsilength := bull_rsilength
buyLevel := bull_buyLevel
sellLevel := bull_sellLevel
rsiOffset := bull_rsiOffset
rsi_src := bull_rsi_src
else if switchBull == false and switchBear == true
rsilength := bear_rsilength
buyLevel := bear_buyLevel
sellLevel:= bear_sellLevel
rsiOffset := bear_rsiOffset
rsi_src := bear_rsi_src`
Unfortunately you can't do that.不幸的是你不能那样做。 As a workaround, you can through a runtime error message when they are both
true
or false
:作为解决方法,您可以在它们都为
true
或false
时通过运行时错误消息:
if switchBull and switchBear
runtime.error("They can't be both 'true'")
if not switchBull and not switchBear
runtime.error("They can't be both 'false'")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.