This indicator anchors a vwap to dividend date ( ex, declaration, or record)
This indicator had been implemented by TrendSpider Team in JavaScript on TrendSpider. Check out the developer documentation to learn more about JS on TrendSpider.
// This indicator was generated by AI and has not been QA checked by the TrendSpider development team. Use for informational purposes only.
describe_indicator('Dividends Anchored VWAP', 'price', { shortName: 'DivAVWAP' });
// Import the binary search library
const binarySearch = library('binary-search-bounds');
// Fetch the dividend data for the current ticker
const dividends = await request.dividends(current.ticker);
// Input to select which dividend date type to anchor the VWAP
const dateType = input.select('Dividend Date Type', 'Ex-Dividend', ['Ex-Dividend', 'Declaration', 'Record']);
// Filter dividend data based on the selected type
const selectedDividends = dividends.filter(dividend => {
if (dateType === 'Ex-Dividend' && dividend.type === 'ex-date') {
return true;
}
if (dateType === 'Declaration' && dividend.type === 'declaration') {
return true;
}
if (dateType === 'Record' && dividend.type === 'record') {
return true;
}
return false;
});
// Check if any matching dividends are found
if (selectedDividends.length > 0) {
// Use the timestamp of the most recent matching dividend
const lastDividendDate = selectedDividends[selectedDividends.length - 1].timestamp;
const lastDividendIndex = binarySearch.lt(time, lastDividendDate);
// Anchor the VWAP to the most recent matching dividend date if found
if (lastDividendIndex >= 0) {
paint(vwap(lastDividendIndex), {
color: 'purple',
thickness: 2,
name: `VWAP/${dateType}`
});
}
}