Price Cross ━ [whvntr]
//This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator(title='Price Cross ━ [whvntr]', format=format.price, precision=2, overlay = false, shorttitle='Price Cross')
//%%%%%%%%%%%%%%%%%%%%%%%%%%%SRC%%%%%%%%%%%%%%%%%%%%%%%
float source = input(close, group = 'Source'
      , inline = "top")
norepainting = barstate.isconfirmed == true
var macd_color_t = true

//%%%%%%%%%%%%%%%%%%%%%%%%%%TIP%%%%%%%%%%%%%%%%%%%%%%%%
// ─© whvntr 
string MACDDEFNI = 'investopedia.com: "Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of a securitys price. Traders use the MACD to identify when bullish or bearish momentum is high to identify entry and exit points for trades.."  So, then, also one could deduct that a SMA, crossed with the MACD, could show the relationship between the bullish or bearish momentum of the MACD."
      that will cross with the EMAs (MACD)'
string HIDDENDIVERGENCE = 'Adjust the length of the SMA 
      that will cross with the EMAs (MACD)'

//%%%%%%%%%%%%%%%%%%%%%%%%%LAO%%%%%%%%%%%%%%%%%%%%%%%%%
// ─© whvntr
color BRIGHTDOT = #f8bbd0
float FLOAT = na 
color TRANSP = #00000000 
var show_dots = true
var macd_midline = true

//%%%%%%%%%%%%%%%%%%%%%%%%%CSS%%%%%%%%%%%%%%%%%%%%%%%%%
// ─© whvntr
var sma_line = input.color(#00ff00
      , title = '―――'
      , group = 'SMA & EMAs'
      , tooltip= 'SMA')
var macd_line = input.color(#ff0000
      , title = '〳'
      , group = 'SMA & EMAs'
      , tooltip = 'EMAs')
var bear_bright_dot_css = input.color(#ff0000
      , title = '◉'
      , group = 'Dots'
      , inline = 'dots')
var bull_bright_dot_css = input.color(#00ff2a 
      , title = ' ‎ 
     ‎ '
      , group = 'Dots'
      , inline = 'dots')
var bear_highlight_css = input.color(color.new(#ff0000, 70)
      , title = '☼'
      , group = 'Highlights'
      , inline = 'highlight')
var bull_highlight_css = input.color(color.new(#00ff00, 80)
      , title = ' ‎ 
     ‎ '
      , group = 'Highlights'
      , inline = 'highlight') 
var bear_barcolor_css = input.color(color.new(#ff0000, 25)
      , title = '🕯‎ 
     ‎'
      , group = 'Bar Colors'
      , inline = 'barcolor')
var bull_barcolor_css = input.color(color.new(#00ff00, 32)
      , title = ' ‎ 
     ‎ '
      , group = 'Bar Colors'
      , inline = 'barcolor') 
var upperline_css = input.color(#4CAF50
      , title = '𝘜𝘱𝘱𝘦𝘳𝘭𝘪𝘯𝘦 ‎'
      , group = ''
      , inline = 'upperline')
var midline_css = input.color(#ffa726 
      , title = '𝘔𝘪𝘥𝘭𝘪𝘯𝘦 ‎ ‎ 
       ‎ ‎ ‎‎'
      , group = ''
      , inline = 'midline') 
var lowline_css = input.color(#FF5252
      , title = '𝘓𝘰𝘸𝘦𝘳𝘭𝘪𝘯𝘦 ‎ ‎'
      , group = ''
      , inline = 'lowerline')
//%%%%%%%%%%%%%%%%%%%%%%%%%%MACD%%%%%%%%%%%%%%%%%%%%%%%
// ─© whvntr 
ema_len_26 = input.int(7, minval=1
     , title= '┉ ┉'
     , group = 'MACD'
     , tooltip = MACDDEFNI
     , inline = 'macd_bear')
ema_len_12 = input.int(5, minval=1
      , title= '┉'
      , group = 'MACD'
      , tooltip = MACDDEFNI
      , inline = 'macd_bear')
ema_26 = ta.ema(source, ema_len_26)
ema_12 = ta.ema(source, ema_len_12)
macd = ema_12 - ema_26
sma_len_10 = input(10, title = '⦿'
      , group = "Hidden Divergence Length ‎"
      , tooltip = HIDDENDIVERGENCE)
// Circles Formula ─ TheLark (Modified)
cross_ = ta.sma(macd, sma_len_10)
out_ = macd
in_ = cross_
macd_cross = out_ >= in_
macd_color_highlights = (macd_color_t) ? (macd_cross ? bull_highlight_css : bear_highlight_css) : BRIGHTDOT
macd_color_brightdots = (macd_color_t) ? (macd_cross ? bull_bright_dot_css : bear_bright_dot_css) : BRIGHTDOT
hidden_dot = out_
// ─© whvntr  
//%%%%%%%%%%%%%%%%%%%%%%%%%INT%%%%%%%%%%%%%%%%%%%%%%%%%
float upperint = input.float(0.0002
      , title = ''
      , group = ''
      , inline = 'upperline'
      , step = 0.0001
      , minval = 0)
float midint = input.float(0
      , title = ''
      , group = ''
      , inline = 'midline'
      , step = 0.0001)
float lowerint = input.float(-0.0002
      , title = ''
      , group = ''
      , inline = 'lowerline'
      , step = 0.0001
      , maxval = 0)

//%%%%%%%%%%%%%%%%%%%%%%%%%PLOT%%%%%%%%%%%%%%%%%%%%%%%% 
plot(macd
      , title ='MACD', color = macd_line 
      , style = plot.style_line, linewidth = 1
      , editable = false)
plot(macd_midline and in_ ? in_ : FLOAT
      , title ='SMA', color = sma_line
      , style = plot.style_line, linewidth = 1
      , editable = false)
plotshape(show_dots and ta.cross(out_, in_) and norepainting
      ? hidden_dot : FLOAT 
      , location = location.absolute
      , size = size.small
      , title = 'Dot'
      , style = shape.circle
      , color = macd_color_highlights
      , editable = false)
plotshape(show_dots and ta.cross(out_, in_) and norepainting 
      ? hidden_dot : FLOAT
      , location = location.absolute
      , size = size.tiny
      , title = 'Dot'
      , style = shape.circle
      , color = macd_color_brightdots
      , editable = false)
//%%%%%%%%%%%%%%%%%%%%%%%%%%HLINE%%%%%%%%%%%%%%%%%%%%%% 
hline(upperint, 'Upperline'
      , linestyle = hline.style_dotted
      , linewidth = 1
      , color = upperline_css
      , editable = true)
hline(midint, 'Midline'
      , linestyle = hline.style_solid
      , linewidth = 2
      , color = midline_css
      , editable = true)
hline(lowerint, 'Lowerline'
      , linestyle = hline.style_dotted
      , linewidth = 1
      , color = lowline_css
      , editable = true)
//%%%%%%%%%%%%%%%%%%%%%%%BAR%%%%%%%%%%%%%%%%%%%%%%%%% 
var color recent_bar_color = na

var int last_bull_cross = na
var int last_bear_cross = na

isBearBright() =>
    bool bearBright = false
    if ta.cross(out_, in_) and norepainting and macd_color_brightdots == bear_bright_dot_css
        bearBright := true
    bearBright

isBullBright() =>
    bool bullBright = false
    if ta.cross(out_, in_) and norepainting and macd_color_brightdots == bull_bright_dot_css
        bullBright := true
    bullBright

if isBearBright()
    recent_bar_color := bear_barcolor_css
else if isBullBright()
    recent_bar_color := bull_barcolor_css
else
    if last_bull_cross > last_bear_cross
        recent_bar_color := bull_barcolor_css

// Barcolor switch
var bool use_barcolor = input(false
      , title = "Check for custom bar colors"
      , group = 'Source'
      , inline = "Top")

// Barcolor
barcolor(use_barcolor ? recent_bar_color : na)
