EA31337 / EA31337-classes

📦📈 EA31337 framework (MQL library for writing trading Expert Advisors, indicators and scripts)
https://ea31337.github.io/EA31337-classes
GNU General Public License v3.0
178 stars 97 forks source link

Pattern: Add Gartley pattern #711

Open kenorb opened 11 months ago

kenorb commented 11 months ago

Detects a harmonic pattern called the Gartley pattern.

Example code:

//+------------------------------------------------------------------+
//| Function to check if a Gartley pattern is present         |
//+------------------------------------------------------------------+
bool IsGartleyPattern(int index, const double &high[], const double &low[])
{
    double XA = high[index - 4] - low[index - 4];
    double AB = high[index - 3] - low[index - 3];
    double BC = high[index - 2] - low[index - 2];
    double CD = high[index - 1] - low[index - 1];

    double ABtoXA = AB / XA;
    double BCtoAB = BC / AB;
    double CDtoBC = CD / BC;

    bool isGartleyPattern = (ABtoXA >= 0.618 && ABtoXA <= 0.786) &&
                            (BCtoAB >= 0.382 && BCtoAB <= 0.886) &&
                            (CDtoBC >= 1.618 && CDtoBC <= 2.618);

    return isGartleyPattern;
}