FuzzyInx
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © R26am

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © R26am

//@version=5
indicator("FuzzyInx", overlay=true)

length = input.int(60, minval=1, title="Period")
per = input.int(8, minval=5, title="persentLength")
per1 = input.float(1.8, minval=1.1, title="persentATR")
sum = 0.0
for j = 0.0 to length-1
    sum := sum + (high[j] - low[j])

sign() =>
    s = 1.0
    if open- close > 0
        s := -1
    s
//-------------------
size = 2
persentLength = per
//---------------------

le(size,ind) =>
    sign = sign()[ind]
    len = 0.0
    h = 0.0
    l = 8000000000000.0
    ind_i = ind 
    for i=ind_i to size+ind-1
        if sign()[i] == sign()[i+1]
            h := math.max(high[i],high[i+1],h)
            l := math.min(low[i],low[i+1],l)
            ind_i := i+1
        else
            h := math.max(high[i],h)
            l := math.min(low[i],l)
            ind_i := i+1
            break
        
    len := h-l 


    if sum/len*persentLength > len
        len := 0

    [len,sign,ind_i,h,l]  //  
//--------------------------------------

[can_l1,sign1,idx1,h1,l1] = le(size,0)
[can_l2,sign2,idx2,h2,l2] = le(size,idx1)
sss = 0
diff = 10

if sign1 != sign2
    if can_l2 > 0 and can_l1 > 0 and (math.max(can_l1,can_l2) / math.min(can_l1,can_l2) <= 1.3) 
        if (sign2 == 1 and l1 < l2) or (sign2 == -1 and h1 > h2)
            sss := 1  

 
if sss
    if sign1 == 1
        label.new(bar_index, na, str.tostring(can_l1), yloc = yloc.belowbar, color = color.new(color.green, 70), textcolor = color.black, style = label.style_label_up)
    else
        label.new(bar_index, na, str.tostring(can_l1), yloc = yloc.abovebar, color = color.new(color.red, 70) , textcolor = color.black, style = label.style_label_down)

    


