colorer
Syntax
Parameters
Return Value
Example
//@version=1
init = () => {
// Configure the indicator in the main chart panel
indicator({ onMainPanel: false, format: 'inherit' });
};
// Example: Color a moving average depending on price relation
const closeSeries = [];
onTick = (length, _moment, _, ta) => {
const close = closeC(0);
closeSeries.push(close);
if (closeSeries.length < 20) return;
// Calculate a 20-period SMA
const smaArray = ta.sma(closeSeries, 20);
const sma = smaArray.at(-1);
// Draw the SMA line (this is the target we will color later)
plot.line("SMA20", sma, "#AAAAAA");
// Choose the palette index
const paletteIndex = close > sma ? 0 : 1;
// Apply the colorer to the target line "SMA20"
plot.colorer("SMA20 Colorer", paletteIndex, "SMA20", [{ name: "Price Above", color: "green" }, { name: "Price Below", color: "red" }]);
};
Result

Last updated