plot the close
plot’s color argument has a default and we have not passed one yet.color it
plot takes a color, and the color may differ on every bar, so the test goes inside the argument. The conditional expression
condition ? a : b produces a when the condition holds and b when it does not.close[1] is the close one bar back.name the condition
The plot call does two jobs. Move the test to its own line.The chart is identical; the script reads better.
soften the colors
color.new(color, alpha) returns the same color at a different opacity. Opacity runs from 0 to 1: 1 is solid and 0 is fully
transparent. Read it as how much of the color you want.color.new(color.red, 50) warns opacity 50 is outside 0–1; 1 is solid. Write 0.5.color by a value
color.from_gradient(value, bottom_value, top_value, bottom_color, top_color) returns a color that blends from bottom_color to
top_color as value goes from bottom_value to top_value. A value below the bottom gives the bottom color and a value above
the top gives the top color; between them each channel, opacity included, is blended in proportion. The RSI runs from 0 to 100, so
30 and 70 make good ends.bottom_value equals top_value, or any argument is na, the result is na (no color).The mistake to avoid
The compiler says:plot() must be called in the global scope. The plot family has to be called at the top level of the script, so
the condition belongs in an argument, as in steps 2 to 5.
What we built
An indicator that answers a question per bar in the color of the line. The shape to reuse: compute abool or a number, then use it
inside plot’s color argument. The same shape colors the bars with barcolor and the background with bgcolor (see
How to color bars by a condition).
Next
Color and transparency
the color constants,
color.rgb and #RRGGBBAA literals.Operators and expressions
the conditional expression and the other operators.
Branching
what
if is for, given that it cannot wrap a plot.