Dividends Anchored VWAP

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

Chart featuring the Dividends Anchored VWAP indicator

This indicator anchors a vwap to dividend date ( ex, declaration, or record)

Source code

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}`
        });
    }
}