Using Alternative Data
This indicator paints horizontal levels at strike prices. Each level's thickness depends on the amount of contracts focused at this strike. The thicker the line is, the more volume this strike contains.
describe_indicator('UO volume at strike');
const options = await request.unusual_options(constants.ticker);
const putVolumeByStrike = {};
const callVolumeByStrike = {};
let overallVolume = 0;
options.forEach(trade => {
if (trade.expDate < time[time.length - 1]) {
return;
}
const target = trade.type == 'PUT' ? putVolumeByStrike : callVolumeByStrike;
if (!target[trade.strike]) {
target[trade.strike] = 0;
}
target[trade.strike] += trade.size;
overallVolume += trade.size;
});
// BEWARE: this is a bad approach. Instead of calling paint() in loops, we'd better
// just select X closest strikes (where X is a fixed number) and then paint them.
Object.keys(putVolumeByStrike).forEach(strike => {
paint(horizontal_line(+strike), { thickness: 50 * putVolumeByStrike[strike] / overallVolume, color: '#ff000033' });
});
Object.keys(callVolumeByStrike).forEach(strike => {
paint(horizontal_line(+strike), { thickness: 50 * callVolumeByStrike[strike] / overallVolume, color: '#00ff0033' });
});