//@version=6 indicator("Manual harmonic ratio audit", overlay = false) x = input.float(100, "X") a = input.float(120, "A") b = input.float(107.64, "B") c = input.float(116.50, "C") d = input.float(104.28, "D") family = input.string("Gartley", "Family", options = ["Gartley", "Bat", "Butterfly", "Crab"]) tolerance = input.float(0.005, "Ratio tolerance", minval = 0) xa = math.abs(a - x) ab = math.abs(b - a) bc = math.abs(c - b) cd = math.abs(d - c) valid = xa > 0 and ab > 0 and bc > 0 rb = valid ? ab / xa : na rc = valid ? bc / ab : na rd = valid ? math.abs(d - a) / xa : na projection = valid ? cd / bc : na bMin = family == "Gartley" ? 0.618 : family == "Bat" ? 0.382 : family == "Butterfly" ? 0.786 : 0.382 bMax = family == "Bat" or family == "Crab" ? 0.618 : bMin dRatio = family == "Gartley" ? 0.786 : family == "Bat" ? 0.886 : family == "Butterfly" ? 1.27 : 1.618 pMin = family == "Gartley" ? 1.27 : family == "Crab" ? 2.618 : 1.618 pMax = family == "Gartley" ? 1.618 : family == "Crab" ? 3.618 : 2.618 shape = (a > x and b < a and b > x and c > b and c < a and d < c) or (a < x and b > a and b < x and c < b and c > a and d > c) bPass = rb >= bMin - tolerance and rb <= bMax + tolerance if family == "Bat" bPass := rb >= 0.382 - tolerance and rb <= 0.50 + tolerance passed = valid and shape and bPass and rc >= 0.382 - tolerance and rc <= 0.886 + tolerance and math.abs(rd - dRatio) <= tolerance and projection >= pMin - tolerance and projection <= pMax + tolerance plot(rb, "B / XA", color.blue) plot(rc, "C / AB", color.gray) plot(rd, "AD / XA", color.red) plot(projection, "CD / BC", color.orange) bgcolor(passed ? color.new(color.green, 85) : na)