Fake break
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © salarkamjoo
// $KMagician/*

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

// Inputs ----------------------------------------------------------------------
atrStrength = input.float(1.2, "Candle strength")

// Call Average True Range Indicator -------------------------------------------
atr = ta.atr(14)

// Call Average True Range Indicator -------------------------------------------
body = math.abs(close - open)

// Conditions ------------------------------------------------------------------
candleColor = close>open ? true : false
sellFb = candleColor == false and 
         candleColor[1] == true and 
         body > atrStrength * atr and 
         body[1] > atrStrength * atr[1] and
         body > 0.75 * body[1]

buyFb  = candleColor == true and 
         candleColor[1] == false and 
         body > atrStrength * atr and 
         body[1] > atrStrength * atr[1] and 
         body > 0.75 * body[1]


// Plot Shapes -----------------------------------------------------------------
plotshape(sellFb, 
          "sell fake-break", 
          shape.triangledown, 
          location.abovebar, 
          color.yellow, 
          text="FB-D", 
          textcolor=color.yellow)

plotshape(buyFb, 
          "buy fake-break", 
          shape.triangleup, 
          location.belowbar, 
          color.aqua, 
          text="FB-U", 
          textcolor=color.aqua)

    
// Alert's Message -------------------------------------------------------------
txt = sellFb ? "Fake Break Down":
      buyFb? "Fake Break Up": ""

if sellFb or buyFb
    alert(txt, alert.freq_once_per_bar_close)