Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

Tell me how to make the result value appear positive even if it is negative in…

  1. User

    Tell me how to make the result value appear positive even if it is negative in pineScript V5.

  2. Assistant

    To make the result value appear positive even if it is negative in Pine Script V5, you can use the abs() function, which returns the absolute value of a number.

    Here's a simple example:

    //@version=5
    indicator("Positive Value", shorttitle="PV")
    
    value = close - open // This could be any value or calculation
    positive_value = abs(value)
    
    plot(positive_value, title="Positive Value", color=color.blue, linewidth=2)
    

    In this script, we calculate the difference between the close and open prices (value). Then, we use the abs() function to get the absolute value of that difference (positive_value). Finally, we plot the positive value on the chart.

    Using the abs() function will always give you a positive number, even if the result of the calculation is negative.