Volume by time of a day + day of week

A custom indicator created by Dust Biter on TrendSpider. You can import this script into your TrendSpider account. Don't have TrendSpider? Create an account first, then import the script.

Chart featuring the Volume by time of a day + day of week indicator

This indicator paints Volume histogram. Columns which are above average for a given time of a given day are highlighted.

Example of reading it: avg volume for 09:30 at SPY,10 for the last 5 Mondays is 2.45M. Today is a Monday and the candle at 09:30 has volume of 4.0M which is above the average, so the volume column will be highlighted.

Source code

This indicator had been implemented by Dust Biter in JavaScript on TrendSpider. Check out the developer documentation to learn more about JS on TrendSpider.

describe_indicator('Volume by time of a day + day of week', 'lower');

if (isNaN(constants.resolution)) {
	throw Error('This indicator can only work on intraday charts');
}

const volumeByTime = {};
const lookbackPeriod = input('Lookback', 3, { min: 1, max: 10 });

const averageVolumes = for_every(volume, time, (v, t) => {
	const timeOfDay = time_of(t);
	const timeHash = `${timeOfDay.dayOfWeek}:${timeOfDay.hours}:${timeOfDay.minutes}`;

	if (!volumeByTime[timeHash]) {
		volumeByTime[timeHash] = [];
	}

	const avgVolume = volumeByTime[timeHash].
		slice(-lookbackPeriod).
		reduce((result, value) => result + value, 0) / lookbackPeriod;

	volumeByTime[timeHash].push(v); 

	return volumeByTime[timeHash].length >= lookbackPeriod + 1
		? avgVolume
		: null;
});

const volumeColors = for_every(close, open, averageVolumes, volume, (c, o, avg, vol) => {
	if (vol > avg) {
		return 'orange';
	}
	
	return '#999';
});

fill(
	paint(averageVolumes, { style: 'line', hidden: true }),
	paint(series_of(0), { style: 'line', hidden: true }),
	'#ffffff',
	0.2
);

paint(volume, { style: 'histogram', color: volumeColors });