Automatically Anchored Volume-Weighted Average Price (VWAP)
This is a simple example to demonstrate how to generate automatically anchored indicators on a chart based on conditions you create, such as fractal highs and lows used in the example.

describe_indicator('Williams Fractal AVWAPs', 'price', { shortName: 'FAVWAPs' });
const length = input('Length', 5, { min: 3, max: 31 });
const fractalHighs = fractal_high(high, length);
const fractalLows = fractal_low(low, length);
const indexedFractalHighs = indexed_points_of(fractalHighs);
const indexedFractalLows = indexed_points_of(fractalLows);
const fractalHighDots = series_of(null);
const fractalLowDots = series_of(null);
const highAvwaps = [];
const lowAvwaps = [];
for (let seriesIndex = 0; seriesIndex < 5; seriesIndex++) {
if (indexedFractalHighs.length > seriesIndex) {
const currentFractalHigh = indexedFractalHighs[indexedFractalHighs.length - 1 - seriesIndex];
fractalHighDots[currentFractalHigh.candleIndex] = currentFractalHigh.value;
highAvwaps.push(vwap(currentFractalHigh.candleIndex));
}
else {
highAvwaps.push(series_of(null));
}
if (indexedFractalLows.length > seriesIndex) {
const currentFractalLow = indexedFractalLows[indexedFractalLows.length - 1 - seriesIndex];
fractalLowDots[currentFractalLow.candleIndex] = currentFractalLow.value;
lowAvwaps.push(vwap(currentFractalLow.candleIndex));
}
else {
lowAvwaps.push(series_of(null));
}
}
paint(fractalHighDots, 'F.High', '#bf3d2b', 'dotted', 3);
paint(fractalLowDots, 'F.Low', '#38751d', 'dotted', 3);
paint(highAvwaps[4], 'H5', '#efafb0');
paint(highAvwaps[3], 'H4', '#eb9589');
paint(highAvwaps[2], 'H3', '#cb5949');
paint(highAvwaps[1], 'H2', '#bf3d2b');
paint(highAvwaps[0], 'H1', '#982414');
paint(lowAvwaps[0], 'L1', '#275214');
paint(lowAvwaps[1], 'L2', '#38751d');
paint(lowAvwaps[2], 'L3', '#5d9445');
paint(lowAvwaps[3], 'L4', '#9dd584');
paint(lowAvwaps[4], 'L5', '#c7e0be');