Liquidity Zones[Angel Algo]
// 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("Liquidity Zones[Angel Algo]", overlay = true)

// Inputs
window = input(20, "Period")
bar_coloring = input(false, "Bar coloring")
sr_coloring = input(false, "Support/Resistance coloring")
highest_liquidity_zones = input(true, "Display high liquidity zones")
lowest_liquidity_levels = input(false, "Display low liquidity levels")

// Calculate the highest volume in the rolling window
highest_volume = ta.highest(volume,window)

// Calculate the lowest volume in the rolling window
lowest_volume = ta.lowest(volume,window)

// Calculate the high and the low of the candle with the highest volume
high_vol = ta.valuewhen(volume == highest_volume, high, 0)
low_vol = ta.valuewhen(volume == highest_volume, low, 0)

// Calculate the lowest and the highest liquidity level
lowest_liquidity_level = ta.valuewhen(volume == lowest_volume, ohlc4, 0)
highest_liquidity_level = ta.valuewhen(volume == highest_volume, ohlc4, 0)

// Define a conditional color for the bar coloring
bar_color = close > high_vol ? color.green : close < low_vol ? color.red : color.blue

// Define a conditional color for the support/resistance coloring
zone_fill_color = (open > high_vol) and (close > high_vol) ? color.green : 
  (open < low_vol) and (close < low_vol) ? color.red : color.blue

// Define a conditional color for liquidity zones and levels
conditional_color = volume == highest_volume ? color.new(color.blue,100) 
  : color.new(zone_fill_color,80)

if sr_coloring == false
    conditional_color := volume == highest_volume ? color.new(color.blue,100) 
  : color.new(color.blue,80)

if highest_liquidity_zones == false
    conditional_color := color.new(color.black,100)

conditional_color2 = volume == lowest_volume ? color.new(color.red,100) 
  : color.new(color.red,50)

if sr_coloring == false
    conditional_color2 := volume == lowest_volume ? color.new(color.red,100) 
  : color.new(color.red,50)

if lowest_liquidity_levels == false
    conditional_color2 := color.new(color.black,100)

// Define upper and lower bounds for the Smart Money Zone
u1 = plot(high_vol, style = plot.style_stepline, 
  color = color.new(color.black,100))
u2 = plot(low_vol, style = plot.style_stepline, 
 color = color.new(color.black,100))

// Plot high liquidity zones
fill(u1,u2, color =conditional_color)

// Bar coloring
barcolor(bar_coloring ? bar_color : na)

// Plot low and high liquidity levels
plot(lowest_liquidity_level, color = conditional_color2)
plot(highest_liquidity_level, color = conditional_color)

// Trading alerts
// Define signal condition
alert_condition = (open > high_vol) and (close > high_vol) ? "bullish" : 
  (open < low_vol) and (close < low_vol) ? "bearish" : na

// Define trading alerts conditions
alertcondition( alert_condition == "bullish" ,"bullish signal", "bullish signal")
alertcondition( alert_condition == "bearish" ,"bearish signal", "bearish signal")
