PegLeg
Pine Script Scholar
Pine Script Scholar
Posts: 4
Joined: December 7th, 2022
Contact: TradingView Profile

Please help with bool and user input values

Need help with conditional operator for changing operator settings.

If the below bool is marked true, I want to change the defval / step for the following user input from 0.00010 / 0.000005 to 0.001 / 0.00005.

Everything I tried throws some kind of error.

JPYpairs = input.bool(title="Will this indicator be for JPY pairs?", defval=false, tooltip="If trading JPY pairs the decimal \n for consolidation moves.", group="STEP 1: GENERAL SETTINGS")

i_conlevelHighLMACD = input.float(0.00010, title="Consolidation Channel", minval=0,step=0.000005, group="STEP 3: CONSOLIDATE HIGH", tooltip="These levels define consolidation on Long-MACD.")

purplemint22
Pine Script Rookie
Pine Script Rookie
Posts: 17
Joined: October 14th, 2022

Re: Please help with bool and user input values

The only thing that I can think of would be to use a variable for the default value that can be changed. I tried this and I get an error saying

10:47:11 AM — Compilation error. Line 10: Syntax error: Arguments of input function must be of constant type, or 'source' builtin variables

So it looks like you have to either use a hardcoded string or one of source built in variables like colors.

You could change the decimal place on the backend by using syminfo.description

So it would look something like this

symbol = syminfo.description

if str.contains(symbol, "Yen")
i_conlevelHighLMACD := i_conlevelHighLMACD * 10

It won't help make it easier for the user to enter the value, but it will convert the value for them if they are not familiar with the difference this will make.

The only other thing I can think of is creating a separate input for JPY pairs and using the boolean as a way of knowing when to use this second input or ignore it.

PegLeg
Pine Script Scholar
Pine Script Scholar
Posts: 4
Joined: December 7th, 2022
Contact: TradingView Profile

Re: Please help with bool and user input values

Thanks much, Purple. I've tried everything. At this point I'm just "tooltipping" and "grouping" to try and mitigate the situation.

I'm hoping our illustrious leader will take a moment to shed some light. (unless you are actually him in disquise.) :wink: :zen: :time:

Return to “Pine Script Q&A”