Inputs and visuals
Give users useful controls and keep an indicator's output easy to read.
Inputs are the settings shown to people using your script. Give them clear labels and sensible ranges.
input (
fastLength = input.int(12, title: "Fast Length", min: 1, max: 200)
slowLength = input.int(26, title: "Slow Length", min: 2, max: 400)
bullishColor = input.color(color.green, title: "Bullish")
bearishColor = input.color(color.red, title: "Bearish", sameLine: true)
)Plots describe the stable outputs of the indicator:
plot spread = plot.histogram(title: "MA Spread")
on chart.update {
let fast = ta.ema(chart.close, fastLength)
let slow = ta.ema(chart.close, slowLength)
let value: float? = fast == null || slow == null ? null : fast - slow
spread.plot(value, color: (value ?? 0.0) >= 0.0 ? bullishColor : bearishColor)
}A vertical histogram without on: gets its own value pane automatically. That is why the MA spread works here without a pane declaration.
Other plot types default to the price pane. To draw the same spread as a line, declare pane spreadPane = pane(title: "MA Spread", height: 0.3) above the plot block and pass on: spreadPane to the line.
Prefer a small number of meaningful settings. Defaults should produce a useful chart immediately, without requiring configuration first.