Double candlestick reversal pattern
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mcashflow

//@version=5
indicator("Several & Double candle reversal pattern",overlay=true)
barnum=input(defval=4,title="input line")
a_value = input.int(defval=2,title="a_value",minval=1, maxval=10, step=1,group="Entity comparison value")
b_value = input.int(defval=3,title="b_value",minval=1, maxval=10, step=1,group="Entity comparison value")
c_value = input.float(defval=0.008,title="Increase ratio",minval=0.004, maxval=0.1, step=0.001,
     group="Entity comparison value")
first_value = input.float(defval=0.01,title="Increase ratio",minval=0.005, maxval=0.1, step=0.001,
     group="Double candle value")
second_value = input.float(defval=2.5,title="second_value",minval=1, maxval=4, step=0.5,
     group="Double candle value")
     
entity_k=math.abs (open-close) 
entity_k1=math.abs (open[1]-close[1])
Shadow=math.abs(high-low) 
Shadow1=math.abs(high[1]-low[1])     
cond = close[0] == ta.highest(close, barnum) and close[1] ==ta.lowest(close,barnum)
      and close[3]>close[2] and close[2]>close[1] 
      and (math.abs(close[3]-open[3]) + math.abs(close[2]-open[2]) + math.abs(close[1]-open[1]))/
      a_value<(close[0]-open[0])
      and open[3]>close[2] and open[2]>close[1]
      and (math.abs(close[3]-open[3]) + math.abs(close[2]-open[2]) + math.abs(close[1]-open[1]))*
      b_value>(close[0]-open[0])  and entity_k >( open[1]*c_value) 
      //and open[3]>open[2] and open[2]>open[1]
      
cond1 = close[1] == ta.highest(close, barnum) and close[0] ==ta.lowest(close,barnum)
      and close[3]<close[2] and close[2]<close[1] 
      and (math.abs(close[3]-open[3]) + math.abs(close[2]-open[2]) + math.abs(close[1]-open[1]))/
      a_value<(open[0]-close[0])
      and open[3]<close[2] and open[2]<close[1]
      and (math.abs(close[3]-open[3]) + math.abs(close[2]-open[2]) + math.abs(close[1]-open[1]))*
      b_value>(open[0]-close[0])  and entity_k >( open[1]*c_value) 
      //and open[3]<open[2] and open[2]<open[1]
if cond
    labelh = label.new(x=bar_index, y=na, text="LONG", 
             size=size.normal, color=color.green, textcolor=#EEEEEE,yloc=yloc.belowbar, 
             style=label.style_label_up
             )

if cond1
    labelh = label.new(x=bar_index, y=na, text="SHORT", 
             size=size.normal, color=color.red, textcolor=#EEEEEE,yloc=yloc.abovebar, 
             style=label.style_label_down
             )
//Double candle reversal pattern
var color x = na


//entity_k >= entity_k1
//Shadow_line >= Shadow_line1 

cond3 =(entity_k >= entity_k1) and entity_k >( open[1]*first_value) and 
      entity_k<( entity_k1*second_value) and open < open[1] and close >open[1]
cond4=(entity_k >= entity_k1) and entity_k >( open[1]*first_value ) and 
      entity_k<( entity_k1*second_value) and open > open[1] and close <open[1]
      
if  cond3
    x := #E0E0E0
else if  cond4
    x := #FFE153

else
   
    x := na
barcolor(x)     
plotshape(cond3,title="Double candlestick reversal",style=shape.labelup,location=location.belowbar,
      color=color.green,text="reversal+++",textcolor = #ECFFFF,
      size=size.small)
plotshape(cond4,title="Double candlestick reversal",style=shape.labeldown,location=location.abovebar,
      color=color.red,text="reversal---",textcolor = 	#FFFF37,
      size=size.small)
            
alertcondition(cond, title="long", message="You have a message, buy btc, think about it {{close}} - {{time}}")     
alertcondition(cond1, title="sell", message="You have a message, sell btc, think about it {{close}} - {{time}}") 

alertcondition((entity_k >= entity_k1) and entity_k >( open[1]*first_value) and entity_k<( entity_k1*second_value)  
     and open < open[1] 
     and close >open[1], title="Reversal pattern+", message="You have a message,Double candlestick reversal {{close}} - {{time}}")     
alertcondition((entity_k >= entity_k1) and entity_k >( open[1]*first_value ) and entity_k<( entity_k1*second_value)  
     and open > open[1] 
     and close <open[1], title="Reversal pattern-", message="You have a message, Double candlestick reversal {{close}} - {{time}}") 