Using Stacking on Histograms
This indicator paints the distance form SMA(20), SMA(50) and SMA(70) as a stacked histogram. Each distance is colored with a different shade of blue.
describe_indicator('Distance from MA', 'lower');
const ma1 = sma(close, 20);
const ma2 = sma(close, 50);
const ma3 = sma(close, 70);
const distance1 = for_every(ma1, ohlc4, (ma, midpoint) => Math.abs(ma - midpoint));
const distance2 = for_every(ma2, ohlc4, (ma, midpoint) => Math.abs(ma - midpoint));
const distance3 = for_every(ma3, ohlc4, (ma, midpoint) => Math.abs(ma - midpoint));
paint(distance1, { style: 'stacked_histogram', color: '#0000ff' });
paint(distance2, { style: 'stacked_histogram', color: '#7777ff' });
paint(distance3, { style: 'stacked_histogram', color: '#aaaaff' });
The version below does the same, but it does stacking as a percentage. Each column will take 100% of the vertical space, and then it will be distributed between all the participating columns (at a given X coordinate) according to their values. This example also uses padding to make your histogram looking like a solid space instead of "set of columns with spaces in between".
describe_indicator('Distance from MA', 'lower');
const ma1 = sma(close, 20);
const ma2 = sma(close, 50);
const ma3 = sma(close, 70);
const distance1 = for_every(ma1, ohlc4, (ma, midpoint) => Math.abs(ma - midpoint));
const distance2 = for_every(ma2, ohlc4, (ma, midpoint) => Math.abs(ma - midpoint));
const distance3 = for_every(ma3, ohlc4, (ma, midpoint) => Math.abs(ma - midpoint));
paint(distance1, { style: 'stacked_histogram', color: '#0000ff', stacking: 'percent', padding: 0 });
paint(distance2, { style: 'stacked_histogram', color: '#7777ff', stacking: 'percent', padding: 0 });
paint(distance3, { style: 'stacked_histogram', color: '#aaaaff', stacking: 'percent', padding: 0 });