0

Pinescript question.

I have 4 variable, they are: -longA = DoWhatIwant -longB = DoWhatIwant2 -longC = DoWhatIwant3 -longD = DoWhatIwant4

I would like that, when a variable occurs, I could print a string, i.e. A or B or C etc. How could I meake it happen?

TIA

I tried every knowledge I have, more or less poor, but I cannot achieve the solution.

1 Answer 1

-1

In Pine Script, you can achieve this by using conditional statements to check the conditions for each variable and then printing the corresponding string. Here's an example based on your description:

//@version=5
indicator("Print String Based on Variable", overlay=true)

longA = input(true, title="Long A")
longB = input(true, title="Long B")
longC = input(true, title="Long C")
longD = input(true, title="Long D")

// Your conditions to trigger the print
if (longA)
    label.new(bar_index, high, text="A", color=color.green, style=label.style_labelup)
if (longB)
    label.new(bar_index, high, text="B", color=color.blue, style=label.style_labelup)
if (longC)
    label.new(bar_index, high, text="C", color=color.red, style=label.style_labelup)
if (longD)
    label.new(bar_index, high, text="D", color=color.purple, style=label.style_labelup)

In this script:

  1. input(true, title="Long A") defines a checkbox input for the variable longA. You can toggle it on or off in the settings.

  2. The if statements check if each variable is true, and if so, it uses label.new to display a label on the chart at the current bar's high with the corresponding text ("A", "B", "C", or "D").

You can customize the appearance of the labels (color, style) according to your preferences. This is a basic example, and you might need to adapt it based on your specific requirements and conditions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.