As an example, here's this basic script that plots the difference between a stock closing in green, or in red.
Code: Select all
//@version=5
indicator("My Script")
var n = 0
if (close > close[1])
n += 1
else
n -= 1
plot (n)
To make this script plot a line that is always fixed in a 0 to 100 range, you first need to find the low and the high of the 'n' series variable, and then apply some basic math to all the values of the series. In return, this will make the plotted line preserve its original shape, but also keep it bound into the same range, no matter what stock symbol you choose to check. As it is now, its high-low range differs wildly from one stock symbol to another.
My problem wasn't the math, but the fact that I could not find a solution to change the values of PAST bars and plot NEW ones. That was the problem. As you may know, past values of series variables are non-editable ('n [ 1 ] := x' does not work!), and I could not find any workaround for this issue.
Any solutions, please?
Alex