Reputation: 1886
When defining a TradingView study, we have the following supported settings
study(title, shorttitle, overlay, format, precision, scale, max_bars_back, max_lines_count, max_labels_count, resolution, resolution_gaps, max_boxes_count) → void
where I am interested into the overlay
property
overlay (const bool) - default is false.
- if true, the study will be added as an overlay for the main series.
- if false, it would be added on a separate chart pane.
What I am interested into is, can this property be set dynamically?
For example, in the indicator settings, I can add an input field from where the user should be able to choose either the current indicator to be shown in the main series overlay or either to be shown in a separate chart pane.
study_overlay = input(defval = "true", title = "Study Overlay", options = ["true", "false"])
When user is going to change the selected options there, the indicator should change the pane that is using, based on the selected option.
Is this feasible? I tried something like
study_overlay_string = input(defval = "true", title = "Study Overlay", options = ["true", "false"])
study_overlay_bool = true
if study_overlay_string == "false"
study_overlay_bool = false
study("My Script", overlay = study_overlay_bool)
This study can be added to the chart, but when changing the setting, nothing happens!
Upvotes: 0
Views: 931
Reputation: 1699
No, the overlay
argument is of the const bool
type so you cannot use an input to pass a value to it. All input-based variables have an input
type form; input is more narrow than const
and cannot be converted into const
.
Your script works because you use =
instead of :=
in your if
-block. Instead of assigning a value to the global scope study_overlay_bool
variable, you create a separate local scope variable with the same name (note the compiler warning that should appear in the console). If you use :=
there instead, you'll get the expected type error.
Upvotes: 1