Reputation: 55
Is it possible hard code input templates into my pine script strategy?
I need to switch between input presets like this: e.g. The built in Trend Line Tool allows you to save and load input templates (Template1, Template2, Trendline):
I wasn't able to find anything about this in the documentation.
But I'd like to be able to hard code (or even just save) my own input templates, then switch between them at run time and tweak the values.
What I have already tried
Creating a drop down, then using the selection in if statements to:
// Defaults
defaultInput1 = 1
If (template1)
defaultInput1 := 999
If (template2)
defaultInput1 := 123
// Throws exception, defaultInput1 must be const
Input1 = input(defVal=defaultInput1, ...)
// Defaults
Input1 = 0
Input2 = 0
If (template1)
Input1 := input(defVal=1, ...)
Input2 := input(defVal=2, ...)
If (template2)
Input1 := input(defVal=500, ...)
Input2 := input(defVal=123, ...)
// ^ Ends up displaying all of the inputs on screen, regardless of which drop down option is selected.
Upvotes: 1
Views: 789
Reputation: 430
Workaround for option 1 Try using a bool like
temp = input(type = input.bool, text = "Use template 1", defval = true)
int default_input = na //declaring a global variable
if(temp == true)
default_input := 999
else
default_input := 123
or if you have multiple options to select from use this
check = (Title = "Select one", defval = "Template1", options["Template1","template2","template3"]
//and then use above method with nested ifs or if and elseif
Workaround for option 2 What I think the mistake is that you are giving it space to fulfil both conditions, change it to be something like this:
// Defaults
Input1 = 0
Input2 = 0
If (template1)
Input1 := input(defVal=1, ...)
Input2 := input(defVal=2, ...)
If (template2 == true and template1 == false) //if(template2 and ! template1) will also work just fine
Input1 := input(defVal=500, ...)
Input2 := input(defVal=123, ...)
Upvotes: 0