Ranged Volume Study - R3c0nTrader
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ranged Volume Study - R3c0nTrader
// Can be used to send buy signals to 3Commas DCA Bot
// Thank you "EvoCrypto" for granting me permission to use "Ranged Volume" to create this version of it.
//@version=5
indicator('Ranged Volume Study - R3c0nTrader', shorttitle='Ranged Volume - R3c0nTrader', format=format.volume)

// INPUTS {
Range_Length = input.int(5, title='Volume Range Length', minval=1)

Heikin_Ashi = input(true, title='Heikin Ashi')
Display_Bars = input(false, title="Show Bar Colors (Keep disabled or it will overwrite Strategy's bar coloring)")
Display_Break = input(true, title='Show Break-Out')
Display_Range = input(true, title='Show Range')
sourceInput = input.source(close, "Source")

// }

// SETTINGS {
Close = Heikin_Ashi ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, sourceInput) : sourceInput
Open = Heikin_Ashi ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open) : open

Positive = volume
Negative = -volume

Highest = ta.highest(volume, Range_Length)
Lowest = ta.lowest(-volume, Range_Length)

Up = Highest > Highest[1] and Close > Open
Dn = Highest > Highest[1] and Close < Open

Volume_Color = 
   Display_Break and Up ? color.new(#ffeb3b, 20) : 
   Display_Break and Dn ? color.new(#f44336, 20) : 
   Close > Open ? color.new(#00c0ff, 20) : 
   Close < Open ? color.new(#0001f6, 20) : na
 
Neg_Volume_Color = 
   Display_Break and Up ? color.new(#ffeb3b, 50) : 
   Display_Break and Dn ? color.new(#f44336, 50) : 
   Close > Open ? color.new(#00c0ff, 50) : 
   Close < Open ? color.new(#0001f6, 50) : na
   
// }

//PLOTS {
plot(Positive, title='Positive Volume', color=Volume_Color, style=plot.style_histogram, linewidth=4)
plot(Negative, title='Negative Volume', color=Neg_Volume_Color, style=plot.style_histogram, linewidth=4)

plot(Display_Range ? Highest : na, title='Highest', color=color.new(#f71100, 50), style=plot.style_line, linewidth=2)
plot(Display_Range ? Lowest : na, title='Lowest', color=color.new(#00ff20, 50), style=plot.style_line, linewidth=2)

//Plot bar color for volume range indicator
barcolor(Display_Bars ? Volume_Color : na)

// }

// ALERTS {
alertcondition(Up, title='Volume Spike Up', message='Volume Spike Up {{ticker}}')
alertcondition(Dn, title='Volume Spike Down', message='Volume Spike Down {{ticker}}')
// }
