Five minutes from an empty editor to a moving average that colours your bars.
//@version=6 indicator("My First Indicator", overlay = true) // The average price of the last 20 bars. average = ta.sma(close, 20) plot(average, "Average", color = color.blue, linewidth = 2) // Colour the bar green when it closes above the average. barcolor(close > average ? color.green : color.red)
Press Open in editor, then Add to chart. A blue line follows the price and every bar is green or red.
//@version=6
indicator("My First Indicator", overlay = true)
overlay = true
average = ta.sma(close, 20)
average
plot(average, ...)
barcolor(...)
Change 20 to 50 and press Update on chart. To let anyone change the length from the settings dialog, replace the number with an input:
20
50
length = input.int(20, "Length", minval = 1) average = ta.sma(close, length)
Hover any word in the editor to see what it does. Start typing a name and the editor suggests the rest.