Coloring Candles
The following script colors blue all the candles which are above SMA(50).
const ma = sma(close, 50);
const colors = for_every(ma, close, (avg, c) => c > avg ? 'blue' : null);
color_candles(colors);
The following script colors blue all the candles which have volume above the average volume and RSI>60.
const colors = for_every(
volume,
sma(volume, 20),
rsi(close, 14),
(vol, avgVol, r) => (vol > avgVol && r > 60) ? 'blue' : null
);
color_candles(colors);
The following script fades candle colors depending on how significant was their volume, compared to "recent highest and recent lowest volume". Candles with abnormally high volume are bright, candles with rather negligible volume are pale.
describe_indicator('Volume weighted colors')
const maxVolume = highest(volume, 30);
const minVolume = lowest(volume, 30);
const volumeRange = sub(maxVolume, minVolume);
const candleColor = (open, close, volume, volumeRange) => {
const volumeWeight = volume / volumeRange;
const proportionalFactor = 55 + volumeWeight * 200;
const inverselyProportionalFactor = 255 - volumeWeight * 255;
return open - close > 0
? `rgb(${proportionalFactor},${inverselyProportionalFactor},${inverselyProportionalFactor})`
: `rgb(${inverselyProportionalFactor},${proportionalFactor},${inverselyProportionalFactor})`;
}
const color = for_every(open, close, volume, volumeRange, candleColor);
color_candles(color);