Untitled

 avatar
unknown
plain_text
3 years ago
2.7 kB
12
Indexable
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © konidtaly88

//@version=5

isCypherPattern(float X, float A, float B, float C, float D) =>
    bearish = (A<X) and (B<X) and (B>A) and (C<A) and (D<X) and (D>C)
    bullish = (A>X) and (B>X) and (B<A) and (C>A) and (D>X) and (D<C)

    ax = math.abs(X-A)
    ba = math.abs(A-B)
    bc = math.abs(C-B)
    cd = math.abs(C-D)
    cx = math.abs(X-C)
    dx = math.abs(X-D)

    r1 = ba/ax
    r2 = cx/ax
    r3 = cd/bc
    r4 = dx/cx

    isCypher = false
    if bearish or bullish
        one = (r1 <= 0.618) and (r1 >= 0.382)
        two = (r2 <= 1.41) and (r2 >= 1.13)
        three = (r3 <= 2) and (r3 >= 1.272)
        four = (r4 <= 0.786)
        isCypher := one and two and three and four
    [isCypher, bullish, bearish, r1, r2, r3, r4]

sinceT(int t) => ta.barssince((time <= t) and (t >= time_close))
barPriceSinceT(int t) =>
    since = sinceT(t)
    [bar_index[since], hlc3[since]]

indicator("Harmonic Pattern Checker")

X = input.time(timestamp("20 Oct 2022 00:00 +0000"))
A = input.time(timestamp("21 Oct 2022 00:00 +0000"))
B = input.time(timestamp("22 Oct 2022 00:00 +0000"))
C = input.time(timestamp("23 Oct 2022 00:00 +0000"))
D = input.time(timestamp("24 Oct 2022 00:00 +0000"))

[barX, priceX] = barPriceSinceT(X)
[barA, priceA] = barPriceSinceT(A)
[barB, priceB] = barPriceSinceT(B)
[barC, priceC] = barPriceSinceT(C)
[barD, priceD] = barPriceSinceT(D)

// [isCypher, bullish, bearish, r1, r2, r3, r4] = isCypherPattern(barX, barA, barB, barC, barD)

var line lineAX = na
var line lineAB = na
var line lineBC = na
var line lineAC = na
var line lineCD = na
var line lineBD = na
var line lineDX = na

// if isCypher and na(lineAX)
//     lineAX := line.new(barX, priceX, barA, priceA)
//     lineAB := line.new(barB, priceB, barA, priceA)
//     lineBC := line.new(barB, priceB, barC, priceC)
//     lineAC := line.new(barC, priceC, barA, priceA)
//     lineCD := line.new(barC, priceC, barD, priceD)
//     lineBD := line.new(barB, priceB, barD, priceD)
//     lineDX := line.new(barD, priceD, barX, priceX)

// plotshape(isCypher)
plotchar(bar_index[1] == barX, char='X', location = location.top, size=size.tiny)
plotchar(bar_index[1] == barA, char='A', location = location.top, size=size.tiny)
plotchar(bar_index[1] == barB, char='B', location = location.top, size=size.tiny)
plotchar(bar_index[1] == barC, char='C', location = location.top, size=size.tiny)
plotchar(bar_index[1] == barD, char='D', location = location.top, size=size.tiny)
Editor is loading...