Skip to main content

Accumulation Distribution (AD) indicator for Amibroker (AFL)

oliviajamie70 7 months ago Amibroker (AFL)

  • Rating:
    0 / 5 (Votes 0)
  • Tags:

Explanation of Key Components
High, Low, Close, Volume: These variables hold the respective price and volume data for each bar.
Money Flow Multiplier: This determines the direction of the money flow relative to the current high and low.
Money Flow Volume: This is calculated using the Money Flow Multiplier and volume, reflecting buying or selling pressure.
Cumulative Sum (Cum): The AD line is a cumulative total of the Money Flow Volume, allowing identification of trends over time.
Plot: The script uses the Plot function to draw the AD line and a reference line at 0 for visual aid.
Signals: It generates buy and sell signals based on the crossing of the AD line with the zero line.
You can copy and paste this AFL script into the AmiBroker formula editor to visualize the Accumulation Distribution indicator on your charts. Adjust colors and styles as needed based on your preferences!

Indicator / Formula

Copy & Paste Friendly
// Accumulation Distribution (AD) Indicator AFL Script
// This script calculates the Accumulation Distribution line
// based on closing prices, volume, and the high/low range.

function AccumulationDistribution()
{
    // Price components
    H = High;    // High price of the current bar
    L = Low;     // Low price of the current bar
    C = Close;   // Closing price of the current bar
    V = Volume;   // Volume of the current bar

    // Calculate the AD value for the current bar
    // Money Flow Multiplier calculation
    MoneyFlowMultiplier = IIf(H == L, 0, // Avoid division by zero
                               (C - L) / (H - L));

    // Money Flow Volume calculation
    MoneyFlowVolume = MoneyFlowMultiplier * V;

    // Initialize the Accumulation Distribution (AD) array
    // AD should be cumulative, start from 0
    AD = Cum(MoneyFlowVolume); // Cumulative sum of Money Flow Volume

    return AD; // Return the AD values
}

// Call the function to calculate AD values
AD = AccumulationDistribution();

// Plot the Accumulation Distribution line
Plot(AD, "Accumulation Distribution", colorBlue, styleLine | styleThick);

// Add horizontal line at 0 for reference
Plot(0, "Zero Line", colorRed, styleLine | styleDashed);

// Create an alert condition (optional)
// This generates a buy/sell signal when the AD line crosses above/below 0
BuySignal = Cross(AD, 0);
SellSignal = Cross(0, AD);

// Plot buy/sell signals on the chart
PlotShapes(IIf(BuySignal, shapeUpArrow, shapeNone), colorGreen, 0, Low - 2*ATR(14));
PlotShapes(IIf(SellSignal, shapeDownArrow, shapeNone), colorRed, 0, High + 2*ATR(14));

// Displaying buy/sell signals in the analysis window
Filter = 1; // This will always allow the buy/sell signals
AddColumn(AD, "AD Value", 1.2);

0 comments

Leave Comment

Please login here to leave a comment.