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 Wedge detection #712

Open kenorb opened 11 months ago

kenorb commented 11 months ago
bool IsValidWedge(int startIndex, int totalBars, const double &high[], const double &low[], int direction)
{
    double trendlineSlope = (high[startIndex] - low[startIndex]) / 2;
    double prevSlope = 0;

    for (int i = startIndex; i > startIndex - totalBars; i--)
    {
        double slope = (high[i] - low[i]) / 2;

        if (direction * slope < 0)
            return false;

        if (direction * prevSlope > 0)
            return false;

        prevSlope = slope;

        if (MathAbs(slope) > MathAbs(trendlineSlope))
            return false;
    }

    return true;
}