Volume Crop ━ Hidden Volume Divergence [whvntr]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ─© whvntr Tyler Ray 
//    @version=5

// • Hidden Divergence formula by TheLark.
// • Filter for that divergence formula by ─© whvntr  
// • I have filtered the hidden divergence formula to display only signals on one side of 
//   midline, by using my "Mideline Tool", and thereby filtering out a lot of false siganls.
indicator(title='Volume Crop ━ Hidden Volume Divergence [whvntr]', format=format.volume, precision=2,
       overlay = true, shorttitle='VOL_CROP ━ whvntr')


//#########################################################
// ℹ️ Source ─© whvntr 
//#########################################################
float src = volume
//#########################################################
// ℹ️ Source ─© whvntr 
//#########################################################


//#########################################################
// ╸>   ╸ ╸>   ╸ ╸ ╸> ─© whvntr
//#########################################################
var s_b = true
var s_b_1 = true
var s_b_2 = true 
var s_b_3 = true 
var not_s_b = not s_b
var not_s_b_1 = not s_b_1
var not_s_b_2 = not s_b_2
var not_s_b_3 = not s_b_3
// ╸>   ╸ ╸>   ╸ ╸ ╸>
var s_l = true
var s_l_1 = true
var s_l_2 = true 
var s_l_3 = true 
var not_s_l = not s_l
var not_s_l_1 = not s_l_1
var not_s_l_2 = not s_l_2
var not_s_l_3 = not s_l_3
//#########################################################
// ╸>   ╸ ╸>   ╸ ╸ ╸> ─© whvntr
//#########################################################


//#########################################################
// 🗓️ Multiple Timeframes ─© whvntr
//#########################################################
keepFrame = input.bool(defval = true
     , title = ''
     , group = '☑ Chart Timeframe ‎ 
     ‎ ✗☐ To Use Multi')
keepFrameFor = keepFrame ? timeframe.period : timeframe.period 
changetframeBear = input.timeframe (title='📕'
     , defval ='10', group = "Multiple Timeframes"
     , inline = 'books'
     , tooltip = '🐼 ‎ & 
     ‎ 🐂')
changetframeBull = input.timeframe(title='📘'
     , defval='10'
     , inline = 'books'
     , group = 'Multiple Timeframes'
     , tooltip = '🐼 ‎ & 
     ‎ 🐂')   
alt_period_bear =  keepFrame ? keepFrameFor : changetframeBear  
alt_period_bull =  keepFrame ? keepFrameFor : changetframeBull  
//#########################################################
// 🗓️ Multiple Timeframes ─© whvntr
//#########################################################  


//#########################################################
// Tooltips ─© whvntr 
//#########################################################
string MIDLINETOOLBEAR = '🐼 Adjusting this line will alter the inclusion spots for the MACD cross signals'
string MACDDEFBEAR = '🐼 MACD is calculated by subtracting the long-term EMA (26 periods) from the short-term EMA (12 periods). An EMA is a type of moving average (MA) that places a greater weight and significance on the most recent data points. The exponential moving average is also referred to as the exponentially weighted moving average'
string HIDDENDIVERGENCEBEAR = '🐼 Adjust the length of the SMA that will cross with the EMAs (MACD)'
string MIDLINETOOLBULL = '🐂 Adjusting this line will alter the inclusion spots for the MACD cross signals'
string MACDDEFBULL = '🐂 MACD is calculated by subtracting the long-term EMA (26 periods) from the short-term EMA (12 periods). An EMA is a type of moving average (MA) that places a greater weight and significance on the most recent data points. The exponential moving average is also referred to as the exponentially weighted moving average'
string HIDDENDIVERGENCEBULL = '🐂 Adjust the length of the SMA that will cross with the EMAs (MACD)'
string REPAINTING = 'Checking this box will permit signals to show before the realtime bar has closed'
//#########################################################
// Tooltips ─© whvntr 
//#########################################################


//#########################################################
// Detect Short/Longs ─© whvntr 
//#########################################################
shorts_input = input.bool(true
       , title = "𝘚𝘩𝘰𝘳𝘵𝘴"
       , group = 'Detect'
       , inline = 'exit_arrow')
longs_input  = input.bool(true
       , title = "𝘓𝘰𝘯𝘨𝘴‎ ‎ "
       , group = 'Detect'
       , inline = 'take_arrow')
//#########################################################
// Detect Short/Longs ─© whvntr 
//#########################################################


//#########################################################
// ☐ or ✔ ─© whvntr
//#########################################################
var bull_spot_true = true
var bear_spot_true = true
var arrow_below_color_true = true
var arrow_above_color_true = true
//#########################################################
// ☐ or ✔ ─© whvntr
//#########################################################


//#########################################################
// 🖌︎ CSS Menu ─© whvntr
//######################################################### 
arrow_above_color_css = input.color(#be0e49,''
     , group = 'Detect'
     , inline = 'exit_arrow')
arrow_below_color_css = input.color(#2962ff,''
     , group = 'Detect'
     , inline = 'take_arrow')
bear_dot_css = input(#f8bbd0,'•'
     , group = 'Dots & Arrow Lengths'
     , inline = 'exit_dot')
bull_dot_css = input(#5fd0ff,'•'
     , group = 'Dots & Arrow Lengths'
     , inline = 'take_dot')
//#########################################################
// 🖌︎ CSS Menu ─© whvntr 
//######################################################### 


//#########################################################
// ╍╍ MACD 🐼 ─© whvntr 
//######################################################### 
ema_len_26_bear = input.int(7, minval=1
     , title= '┉ ┉'
     , group = 'MACD Bearish'
     , tooltip = MACDDEFBEAR
     , inline = 'macd_bear')
ema_len_12_bear = input.int(5, minval=1
      , title= '┉'
      , group = 'MACD Bearish'
      , tooltip = MACDDEFBEAR
      , inline = 'macd_bear')
ema_26_bear = ta.ema(src, ema_len_26_bear)
ema_12_bear = ta.ema(src, ema_len_12_bear)
macd_bear = ema_12_bear - ema_26_bear
sma_len_10_bear = input(10, title = '⦿'
      , group = "Hidden Divergence Length ‎"
      , tooltip = HIDDENDIVERGENCEBEAR)
//#########################################################
// ╍╍ MACD 🐼 ─© whvntr 
//######################################################### 


//#########################################################
// ◉ Circles Formula 🐼 ─ TheLark ©
//######################################################### 
cross_bear = ta.sma(macd_bear, sma_len_10_bear)
out_bear = request.security(syminfo.tickerid, alt_period_bear
      , macd_bear) 
in_bear = request.security(syminfo.tickerid, alt_period_bear
      , cross_bear) 
macd_bear_cross = out_bear >= in_bear
arrow_above = arrow_above_color_true ? macd_bear_cross 
      ? na : arrow_above_color_css : na
locate_bear = in_bear
bear_spot = ta.cross(out_bear, in_bear) ? locate_bear 
      : na 
dot_above = arrow_below_color_true ? macd_bear_cross 
      ? na : bear_dot_css : na
//#########################################################
// ◉ Circles Formula 🐼 ─ TheLark ©
//######################################################### 


var r_t_b = true
var r_t_l = true
if barstate.isconfirmed == false and barstate.isrealtime == true 
    r_t_b := false 
if barstate.isconfirmed == false and barstate.isrealtime == true 
    r_t_l := false


//#########################################################
// ⚙️ Midline Tool 🐼 ─© whvntr
//##########################################################         
midline_bear = input.float(defval = 0, minval = -50000000000
      , maxval = 50000000000,  step = 1000, title =
       '🎮'
      , group = 'Midline Tool ‎'
      , tooltip = MIDLINETOOLBEAR)
bear_found_midline_tool = ta.cross(bear_spot, midline_bear)
no_repaint_bear = bear_found_midline_tool and r_t_b
bear_alert = bear_found_midline_tool[0] 
       and not bear_found_midline_tool[1] and r_t_b
//#########################################################
// ⚙️ Midline Tool 🐼 ─© whvntr
//######################################################### 


//#########################################################
// 🎯 Arrow Length Feature 🐼 Position ─© whvntr  
//#########################################################
string one_len_bear = '╸'
string two_len_bear = '╸ ╸'
string three_len_bear = '╸ ╸ ╸'
arrow_style_bear = input.string(defval = '╸ ╸ ╸'
     , title = '‎ ‎ '
     , inline = 'exit_dot'
     , options = [one_len_bear, two_len_bear, three_len_bear]
     , group = 'Dots & Arrow Lengths'  
     , tooltip = 'Adjust the length of the arrows')
var get_1_bear =  arrow_style_bear == one_len_bear
var get_2_bear = arrow_style_bear == two_len_bear
var get_3_bear = arrow_style_bear == three_len_bear
if arrow_style_bear == one_len_bear
    not_s_b_1 := true
if arrow_style_bear == two_len_bear
    not_s_b_2 := true
if arrow_style_bear == three_len_bear
    not_s_b_3 := true 
plotchar(no_repaint_bear and not_s_b_1 and shorts_input
     , title = ''
     , text = '|\nv'
     , textcolor = arrow_above
     , location=location.abovebar
     , offset=0
     , color = dot_above
     , char = '•'
     , size=size.tiny, editable = false)
plotchar(no_repaint_bear and not_s_b_2 and shorts_input
     , title = ''
     , text = '|\n|\nv'
     , textcolor = arrow_above
     , location=location.abovebar
     , offset=0, color = dot_above
     , char = '•'
     , size=size.tiny, editable = false)
plotchar(no_repaint_bear and not_s_b_3 and shorts_input
     , title = ''
     , text = '|\n|\n|\nv'
     , textcolor = arrow_above
     , location=location.abovebar
     , offset=0, color = dot_above
     , char = '•'
     , size=size.tiny, editable = false)
//#########################################################
// 🎯 Arrow Length Feature 🐼 Position ─© whvntr  
//#########################################################


//#########################################################
// ╍╍ MACD 🐂 ─© whvntr 
//######################################################### 
ema_len_26_bull = input.int(7, minval=1
      , title= '┉ ┉'
      , group = 'MACD Bullish'
      , tooltip = MACDDEFBULL
      , inline = 'macd_bull')
ema_len_12_bull = input.int(5, minval=1
      , group = 'MACD Bullish'
      , title= '┉'
      , tooltip = MACDDEFBULL
      , inline = 'macd_bull')
ema_26_bull = ta.ema(src, ema_len_26_bull)
ema_12_bull = ta.ema(src, ema_len_12_bull)
macd_bull = ema_12_bull - ema_26_bull
sma_len_10_bull = input(10
     , title = '⦿'
     , group = "Hidden Divergence Length"
     , tooltip = HIDDENDIVERGENCEBULL)
//#########################################################
// ╍╍ MACD 🐂 ─© whvntr 
//######################################################### 


//#########################################################
// ◉ Circles Formula 🐂 ─ TheLark ©
//######################################################### 
cross_bull = ta.sma(macd_bull, sma_len_10_bull)
out_bull = request.security(syminfo.tickerid
      , alt_period_bull, macd_bull) 
in_bull = request.security(syminfo.tickerid
      , alt_period_bull, cross_bull)
macd_bull_cross = out_bull >= in_bull
arrow_below = arrow_below_color_true ? macd_bull_cross 
      ? arrow_below_color_css : na : na 
locate_bull = in_bull
bull_spot = ta.cross(out_bull, in_bull) 
      ? locate_bull : na 
via_bull = bull_spot_true and bull_spot
dot_below = arrow_below_color_true ? macd_bull_cross 
      ? bull_dot_css : na : na
//#########################################################
// ◉ Circles Formula 🐂 ─ TheLark ©
//######################################################### 


//#########################################################
// ⚙️ Midline Tool 🐂 ─© whvntr
//######################################################### 
midline_bull = input.float(defval = 0 , minval = -50000000000
      , maxval = 50000000000,  step = 1000, title = 
       '🎮'
      , group = 'Midline Tool'
      , tooltip = MIDLINETOOLBULL) 
bull_found_midline_tool = ta.cross(bull_spot, midline_bull)
no_repaint_bull = bull_found_midline_tool and r_t_l
bull_alert = bull_found_midline_tool and r_t_l
//#########################################################
// ⚙️ Midline Tool 🐂 ─© whvntr
//######################################################### 


//######################################################### 
// 🎯 Arrow Length Feature 🐂 Position ─© whvntr  
//######################################################### 
string one_len_bull = '╸'
string two_len_bull = '╸ ╸'
string three_len_bull = '╸ ╸ ╸'
arrow_style_bull = input.string(defval = '╸ ╸ ╸'
  , title = '‎ ‎ '
  , inline = 'take_dot'
  , options = [one_len_bull, two_len_bull, three_len_bull]
  , group = 'Dots & Arrow Lengths'
  , tooltip = 'Adjust the length of the arrows')
var get_1_bull =  arrow_style_bull == one_len_bull
var get_2_bull = arrow_style_bull == two_len_bull
var get_3_bull = arrow_style_bull == three_len_bull
if arrow_style_bull == one_len_bull
    not_s_l_1 := true
if arrow_style_bull == two_len_bull
    not_s_l_2 := true
if arrow_style_bull == three_len_bull
    not_s_l_3 := true 
plotchar(no_repaint_bull and not_s_l_1 and longs_input
     , title = ''
     , text = 'ʌ\n|'
     , textcolor = arrow_below
     , location=location.belowbar
     , offset=0, color = dot_below
     , char = '•'
     , size=size.tiny, editable = false)
plotchar(no_repaint_bull and not_s_l_2 and longs_input
     , title = ''
     , text = 'ʌ\n|\n|'
     , textcolor = arrow_below
     , location=location.belowbar
     , offset=0, color = dot_below
     , char = '•'
     , size=size.tiny, editable = false)
plotchar(no_repaint_bull and not_s_l_3 and longs_input
     , title = ''
     , text = 'ʌ\n|\n|\n|'
     , textcolor = arrow_below
     , location=location.belowbar
     , offset=0, color = dot_below
     , char = '•'
     , size=size.tiny, editable = false)
//######################################################### 
// 🎯 Arrow Length Feature 🐂 Position ─© whvntr  
//######################################################### 