Indicator · Pine Script v5 · On the chart

Average Daily Range with Time Session Highlighter

by g-moe· code credited to goodgains

This indicator plots an average daily range from hourly high-low ranges stored for each hour across a selectable number of days.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code769
Settings25inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

769 lines of Pine Script v5 from Tradingview/average-daily-range-time-session-highlighter.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

average-daily-range-time-session-highlighter.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Average Daily Range with Time Session Highlighter", overlay = true)

// @keywords: average-daily-range, session-highlighter, hourly-range, request-security, volatility-box, upper-band, lower-band, array-average, average-true-range, dynamic-rsi, bollinger-bands, waddah-attar-explosion, stochastic-slow, macd, entry-signals, stop-loss, profit-target, band-fill, status-table, alerts

number_of_days = input.int(20, title = 'Number of Days', minval = 5, maxval = 100)
alertsOn = input.bool(false, title = 'Alerts On')
currentBoxLabel = input.bool(true, title = 'Current Box Label')
timeLineOn = input.bool(true, title = 'Timeline')


hourly_high = request.security(syminfo.tickerid, "60", high, lookahead = barmerge.lookahead_on)
hourly_low = request.security(syminfo.tickerid, "60", low, lookahead = barmerge.lookahead_on)
// plot(hourly_high, color = color.yellow, linewidth = 5, style = plot.style_stepline)
// plot(hourly_low, color = color.yellow, linewidth  = 5, style = plot.style_stepline)

// ##ADJUSTMENTS
L1_adjustment = .77  //#cyan lines
L2_adjustment = .88  //#inner band
L3_adjustment = 1.00 //#outer band or nothing
L4_adjustment = .69  //#targets


is_hour0 = hour == 23
is_hour1 = hour == 0
is_hour2 = hour == 1
is_hour3 = hour == 2
is_hour4 = hour == 3
is_hour5 = hour == 4
is_hour6 = hour == 5
is_hour7 = hour == 6
is_hour8 = hour == 7
is_hour9 = hour == 8
is_hour10 = hour == 9
is_hour11 = hour == 10
is_hour12 = hour == 11
is_hour13 = hour == 12
is_hour14 = hour == 13
is_hour15 = hour == 14
is_hour16 = hour == 15
is_hour17 = hour == 16
is_hour18 = hour == 17
is_hour19 = hour == 18
is_hour20 = hour == 19
is_hour21 = hour == 20
is_hour22 = hour == 21
is_hour23 = hour == 22


bar_range = hourly_high - hourly_low
// bgcolor(is_hour0[1] and not is_hour0 ? color.new(color.yellow,80) : na)
// bgcolor(is_hour14 ? color.new(color.yellow,80) : is_hour13 ? color.new(color.blue,50) : na)
//Set Bar Ranges
var b0_range = array.new_float(number_of_days, 0.00)
var b1_range = array.new_float(number_of_days, 0.00)
var b2_range = array.new_float(number_of_days, 0.00)
var b3_range = array.new_float(number_of_days, 0.00)
var b4_range = array.new_float(number_of_days, 0.00)
var b5_range = array.new_float(number_of_days, 0.00)
var b6_range = array.new_float(number_of_days, 0.00)
var b7_range = array.new_float(number_of_days, 0.00)
var b8_range = array.new_float(number_of_days, 0.00)
var b9_range = array.new_float(number_of_days, 0.00)
var b10_range = array.new_float(number_of_days, 0.00)
var b11_range = array.new_float(number_of_days, 0.00)
var b12_range = array.new_float(number_of_days)
var b13_range = array.new_float(number_of_days, 0.00)
var b14_range = array.new_float(number_of_days)
var b15_range = array.new_float(number_of_days)
var b16_range = array.new_float(number_of_days)
var b17_range = array.new_float(number_of_days)
var b18_range = array.new_float(number_of_days, 0.00)
var b19_range = array.new_float(number_of_days, 0.00)
var b20_range = array.new_float(number_of_days, 0.00)
var b21_range = array.new_float(number_of_days, 0.00)
var b22_range = array.new_float(number_of_days, 0.00)
var b23_range = array.new_float(number_of_days, 0.00)


if is_hour0[1] and not is_hour0  
    array.unshift(b0_range, bar_range[1])
    array.remove(b0_range, number_of_days)        
   
else if is_hour1[1] and not is_hour1  
    array.unshift(b1_range, bar_range[1])
    array.remove(b1_range, number_of_days)        
   
else if is_hour2[1] and not is_hour2  
    array.unshift(b2_range, bar_range[1])
    array.remove(b2_range, number_of_days)        
   
else if is_hour3[1] and not is_hour3  
    array.unshift(b3_range, bar_range[1])
    array.remove(b3_range, number_of_days)        
   
else if is_hour4[1] and not is_hour4  
    array.unshift(b4_range, bar_range[1])
    array.remove(b4_range, number_of_days)        

else if is_hour5[1] and not is_hour5
    array.unshift(b5_range, bar_range[1])
    array.remove(b5_range, number_of_days)

else if is_hour6[1] and not is_hour6
    array.unshift(b6_range, bar_range[1])
    array.remove(b6_range, number_of_days)

else if is_hour7[1] and not is_hour7
    array.unshift(b7_range, bar_range[1])
    array.remove(b7_range, number_of_days)

else if is_hour8[1] and not is_hour8
    array.unshift(b8_range, bar_range[1])
    array.remove(b8_range, number_of_days)

else if is_hour9[1] and not is_hour9
    array.unshift(b9_range, bar_range[1])
    array.remove(b9_range, number_of_days)

else if is_hour10[1] and not is_hour10
    array.unshift(b10_range, bar_range[1])
    array.remove(b10_range, number_of_days)

else if is_hour11[1] and not is_hour11
    array.unshift(b11_range, bar_range[1])
    array.remove(b11_range, number_of_days)

else if is_hour12[1] and not is_hour12
    array.unshift(b12_range, bar_range[1])
    array.remove(b12_range, number_of_days)

else if is_hour13[1] and not is_hour13
    array.unshift(b13_range, bar_range[1])
    array.remove(b13_range, number_of_days)

else if is_hour14[1] and not is_hour14
    array.unshift(b14_range, bar_range[1])
    array.remove(b14_range, number_of_days)

else if is_hour15[1] and not is_hour15
    array.unshift(b15_range, bar_range[1])
    array.remove(b15_range, number_of_days)

else if is_hour16[1] and not is_hour16
    array.unshift(b16_range, bar_range[1])
    array.remove(b16_range, number_of_days)

else if is_hour17[1] and not is_hour17
    array.unshift(b17_range, bar_range[1])
    array.remove(b17_range, number_of_days)

else if is_hour18[1] and not is_hour18
    array.unshift(b18_range, bar_range[1])
    array.remove(b18_range, number_of_days)

else if is_hour19[1] and not is_hour19
    array.unshift(b19_range, bar_range[1])
    array.remove(b19_range, number_of_days)

else if is_hour20[1] and not is_hour20
    array.unshift(b20_range, bar_range[1])
    array.remove(b20_range, number_of_days)

else if is_hour21[1] and not is_hour21
    array.unshift(b21_range, bar_range[1])
    array.remove(b21_range, number_of_days)

else if is_hour22[1] and not is_hour22
    array.unshift(b22_range, bar_range[1])
    array.remove(b22_range, number_of_days)

else if is_hour23[1] and not is_hour23
    array.unshift(b23_range, bar_range[1])
    array.remove(b23_range, number_of_days)


var float hour0 = 0.00
var float hour1 = 0.00 
var float hour2 = 0.00 
var float hour3 = 0.00 
var float hour4 = 0.00 
var float hour5 = 0.00 
var float hour6 = 0.00 
var float hour7 = 0.00 
var float hour8 = 0.00 
var float hour9 = 0.00 
var float hour10 = 0.00
var float hour11 = 0.00
var float hour12 = 0.00
var float hour13 = 0.00
var float hour14 = 0.00
var float hour15 = 0.00
var float hour16 = 0.00
var float hour17 = 0.00
var float hour18 = 0.00
var float hour19 = 0.00
var float hour20 = 0.00
var float hour21 = 0.00
var float hour22 = 0.00
var float hour23 = 0.00

var float hourlyRHA = 0.00
var float hourlyRHH = 0.00
var float hourlyRLA = 0.00
var float hourlyRLL = 0.00
var float hourlyRHL = 0.00
var float hourlyRLH = 0.00
var float longT = 0.00
var float shortT = 0.00


if is_hour0
    hour0 := array.avg(b0_range)
    hourlyRHA := hourly_low + hour0 * L2_adjustment 
    hourlyRHH := hourly_low + hour0 * L3_adjustment 
    hourlyRLA := hourly_high - hour0 * L2_adjustment 
    hourlyRLL := hourly_high - hour0 * L3_adjustment
    hourlyRHL := hourly_low + hour0 * L1_adjustment
    hourlyRLH := hourly_high - hour0 * L1_adjustment
    longT :=  hourly_low + hour0 * L4_adjustment 
    shortT := hourly_high - hour0 * L4_adjustment 
else if is_hour1
    hour1:= array.avg(b1_range)
    hourlyRHA := hourly_low + hour1* L2_adjustment 
    hourlyRHH := hourly_low + hour1* L3_adjustment 
    hourlyRLA := hourly_high - hour1* L2_adjustment
    hourlyRLL := hourly_high - hour1* L3_adjustment
    hourlyRHL := hourly_low + hour1* L1_adjustment 
    hourlyRLH := hourly_high - hour1* L1_adjustment
    longT :=  hourly_low + hour1* L4_adjustment    
    shortT := hourly_high - hour1* L4_adjustment   
else if is_hour2
    hour2:= array.avg(b2_range)
    hourlyRHA := hourly_low + hour2* L2_adjustment
    hourlyRHH := hourly_low + hour2* L3_adjustment
    hourlyRLA := hourly_high - hour2* L2_adjustment
    hourlyRLL := hourly_high - hour2* L3_adjustment
    hourlyRHL := hourly_low + hour2* L1_adjustment
    hourlyRLH := hourly_high - hour2* L1_adjustment
    longT :=  hourly_low + hour2* L4_adjustment
    shortT := hourly_high - hour2* L4_adjustment
else if is_hour3
    hour3:= array.avg(b3_range)
    hourlyRHA := hourly_low + hour3* L2_adjustment
    hourlyRHH := hourly_low + hour3* L3_adjustment
    hourlyRLA := hourly_high - hour3* L2_adjustment
    hourlyRLL := hourly_high - hour3* L3_adjustment
    hourlyRHL := hourly_low + hour3* L1_adjustment
    hourlyRLH := hourly_high - hour3* L1_adjustment
    longT :=  hourly_low + hour3* L4_adjustment
    shortT := hourly_high - hour3* L4_adjustment
else if is_hour4
    hour4:= array.avg(b4_range)
    hourlyRHA := hourly_low + hour4* L2_adjustment
    hourlyRHH := hourly_low + hour4* L3_adjustment
    hourlyRLA := hourly_high - hour4* L2_adjustment
    hourlyRLL := hourly_high - hour4* L3_adjustment
    hourlyRHL := hourly_low + hour4* L1_adjustment
    hourlyRLH := hourly_high - hour4* L1_adjustment
    longT :=  hourly_low + hour4* L4_adjustment
    shortT := hourly_high - hour4* L4_adjustment
else if is_hour5
    hour5:= array.avg(b5_range)
    hourlyRHA := hourly_low + hour5* L2_adjustment
    hourlyRHH := hourly_low + hour5* L3_adjustment
    hourlyRLA := hourly_high - hour5* L2_adjustment
    hourlyRLL := hourly_high - hour5* L3_adjustment
    hourlyRHL := hourly_low + hour5* L1_adjustment
    hourlyRLH := hourly_high - hour5* L1_adjustment
    longT :=  hourly_low + hour5* L4_adjustment
    shortT := hourly_high - hour5* L4_adjustment
else if is_hour6
    hour6:= array.avg(b6_range)
    hourlyRHA := hourly_low + hour6* L2_adjustment
    hourlyRHH := hourly_low + hour6* L3_adjustment
    hourlyRLA := hourly_high - hour6* L2_adjustment
    hourlyRLL := hourly_high - hour6* L3_adjustment
    hourlyRHL := hourly_low + hour6* L1_adjustment
    hourlyRLH := hourly_high - hour6* L1_adjustment
    longT :=  hourly_low + hour6* L4_adjustment
    shortT := hourly_high - hour6* L4_adjustment
else if is_hour7
    hour7:= array.avg(b7_range)
    hourlyRHA := hourly_low + hour7* L2_adjustment
    hourlyRHH := hourly_low + hour7* L3_adjustment
    hourlyRLA := hourly_high - hour7* L2_adjustment
    hourlyRLL := hourly_high - hour7* L3_adjustment
    hourlyRHL := hourly_low + hour7* L1_adjustment
    hourlyRLH := hourly_high - hour7* L1_adjustment
    longT :=  hourly_low + hour7* L4_adjustment
    shortT := hourly_high - hour7* L4_adjustment
else if is_hour8
    hour8:= array.avg(b8_range)
    hourlyRHA := hourly_low + hour8* L2_adjustment
    hourlyRHH := hourly_low + hour8* L3_adjustment
    hourlyRLA := hourly_high - hour8* L2_adjustment
    hourlyRLL := hourly_high - hour8* L3_adjustment
    hourlyRHL := hourly_low + hour8* L1_adjustment
    hourlyRLH := hourly_high - hour8* L1_adjustment
    longT :=  hourly_low + hour8* L4_adjustment
    shortT := hourly_high - hour8* L4_adjustment
else if is_hour9
    hour9:= array.avg(b9_range)
    hourlyRHA := hourly_low + hour9* L2_adjustment
    hourlyRHH := hourly_low + hour9* L3_adjustment
    hourlyRLA := hourly_high - hour9* L2_adjustment
    hourlyRLL := hourly_high - hour9* L3_adjustment
    hourlyRHL := hourly_low + hour9* L1_adjustment
    hourlyRLH := hourly_high - hour9* L1_adjustment
    longT :=  hourly_low + hour9* L4_adjustment
    shortT := hourly_high - hour9* L4_adjustment
else if is_hour10
    hour10:= array.avg(b10_range)
    hourlyRHA := hourly_low + hour10* L2_adjustment
    hourlyRHH := hourly_low + hour10* L3_adjustment
    hourlyRLA := hourly_high - hour10* L2_adjustment
    hourlyRLL := hourly_high - hour10* L3_adjustment
    hourlyRHL := hourly_low + hour10* L1_adjustment
    hourlyRLH := hourly_high - hour10* L1_adjustment
    longT :=  hourly_low + hour10* L4_adjustment
    shortT := hourly_high - hour10* L4_adjustment
else if is_hour11
    hour11:= array.avg(b11_range)
    hourlyRHA := hourly_low + hour11* L2_adjustment
    hourlyRHH := hourly_low + hour11* L3_adjustment
    hourlyRLA := hourly_high - hour11* L2_adjustment
    hourlyRLL := hourly_high - hour11* L3_adjustment
    hourlyRHL := hourly_low + hour11* L1_adjustment
    hourlyRLH := hourly_high - hour11* L1_adjustment
    longT :=  hourly_low + hour11* L4_adjustment
    shortT := hourly_high - hour11* L4_adjustment
else if is_hour12
    hour12:= array.avg(b12_range)
    hourlyRHA := hourly_low + hour12* L2_adjustment
    hourlyRHH := hourly_low + hour12* L3_adjustment
    hourlyRLA := hourly_high - hour12* L2_adjustment
    hourlyRLL := hourly_high - hour12* L3_adjustment
    hourlyRHL := hourly_low + hour12* L1_adjustment
    hourlyRLH := hourly_high - hour12* L1_adjustment
    longT :=  hourly_low + hour12* L4_adjustment
    shortT := hourly_high - hour12* L4_adjustment
else if is_hour13
    hour13:= array.avg(b13_range)
    hourlyRHA := hourly_low + hour13* L2_adjustment
    hourlyRHH := hourly_low + hour13* L3_adjustment
    hourlyRLA := hourly_high - hour13* L2_adjustment
    hourlyRLL := hourly_high - hour13* L3_adjustment
    hourlyRHL := hourly_low + hour13* L1_adjustment
    hourlyRLH := hourly_high - hour13* L1_adjustment
    longT :=  hourly_low + hour13* L4_adjustment
    shortT := hourly_high - hour13* L4_adjustment
else if is_hour14
    hour14:= array.avg(b14_range)
    hourlyRHA := hourly_low + hour14* L2_adjustment
    hourlyRHH := hourly_low + hour14* L3_adjustment
    hourlyRLA := hourly_high - hour14* L2_adjustment
    hourlyRLL := hourly_high - hour14* L3_adjustment
    hourlyRHL := hourly_low + hour14* L1_adjustment
    hourlyRLH := hourly_high - hour14* L1_adjustment
    longT :=  hourly_low + hour14* L4_adjustment
    shortT := hourly_high - hour14* L4_adjustment
else if is_hour15
    hour15:= array.avg(b15_range)
    hourlyRHA := hourly_low + hour15* L2_adjustment
    hourlyRHH := hourly_low + hour15* L3_adjustment
    hourlyRLA := hourly_high - hour15* L2_adjustment
    hourlyRLL := hourly_high - hour15* L3_adjustment
    hourlyRHL := hourly_low + hour15* L1_adjustment
    hourlyRLH := hourly_high - hour15* L1_adjustment
    longT :=  hourly_low + hour15* L4_adjustment
    shortT := hourly_high - hour15* L4_adjustment
else if is_hour16
    hour16:= array.avg(b16_range)
    hourlyRHA := hourly_low + hour16* L2_adjustment
    hourlyRHH := hourly_low + hour16* L3_adjustment
    hourlyRLA := hourly_high - hour16* L2_adjustment
    hourlyRLL := hourly_high - hour16* L3_adjustment
    hourlyRHL := hourly_low + hour16* L1_adjustment
    hourlyRLH := hourly_high - hour16* L1_adjustment
    longT :=  hourly_low + hour16* L4_adjustment
    shortT := hourly_high - hour16* L4_adjustment
else if is_hour17
    hour17:= array.avg(b17_range)
    hourlyRHA := hourly_low + hour17* L2_adjustment
    hourlyRHH := hourly_low + hour17* L3_adjustment
    hourlyRLA := hourly_high - hour17* L2_adjustment
    hourlyRLL := hourly_high - hour17* L3_adjustment
    hourlyRHL := hourly_low + hour17* L1_adjustment
    hourlyRLH := hourly_high - hour17* L1_adjustment
    longT :=  hourly_low + hour17* L4_adjustment
    shortT := hourly_high - hour17* L4_adjustment
else if is_hour18
    hour18:= array.avg(b18_range)
    hourlyRHA := hourly_low + hour18* L2_adjustment
    hourlyRHH := hourly_low + hour18* L3_adjustment
    hourlyRLA := hourly_high - hour18* L2_adjustment
    hourlyRLL := hourly_high - hour18* L3_adjustment
    hourlyRHL := hourly_low + hour18* L1_adjustment
    hourlyRLH := hourly_high - hour18* L1_adjustment
    longT :=  hourly_low + hour18* L4_adjustment
    shortT := hourly_high - hour18* L4_adjustment
else if is_hour19
    hour19:= array.avg(b19_range)
    hourlyRHA := hourly_low + hour19* L2_adjustment
    hourlyRHH := hourly_low + hour19* L3_adjustment
    hourlyRLA := hourly_high - hour19* L2_adjustment
    hourlyRLL := hourly_high - hour19* L3_adjustment
    hourlyRHL := hourly_low + hour19* L1_adjustment
    hourlyRLH := hourly_high - hour19* L1_adjustment
    longT :=  hourly_low + hour19* L4_adjustment
    shortT := hourly_high - hour19* L4_adjustment
else if is_hour20
    hour20:= array.avg(b20_range)
    hourlyRHA := hourly_low + hour20* L2_adjustment
    hourlyRHH := hourly_low + hour20* L3_adjustment
    hourlyRLA := hourly_high - hour20* L2_adjustment
    hourlyRLL := hourly_high - hour20* L3_adjustment
    hourlyRHL := hourly_low + hour20* L1_adjustment
    hourlyRLH := hourly_high - hour20* L1_adjustment
    longT :=  hourly_low + hour20* L4_adjustment
    shortT := hourly_high - hour20* L4_adjustment
else if is_hour21
    hour21:= array.avg(b21_range)
    hourlyRHA := hourly_low + hour21* L2_adjustment
    hourlyRHH := hourly_low + hour21* L3_adjustment
    hourlyRLA := hourly_high - hour21* L2_adjustment
    hourlyRLL := hourly_high - hour21* L3_adjustment
    hourlyRHL := hourly_low + hour21* L1_adjustment
    hourlyRLH := hourly_high - hour21* L1_adjustment
    longT :=  hourly_low + hour21* L4_adjustment
    shortT := hourly_high - hour21* L4_adjustment
else if is_hour22
    hour22:= array.avg(b22_range)
    hourlyRHA := hourly_low + hour22* L2_adjustment
    hourlyRHH := hourly_low + hour22* L3_adjustment
    hourlyRLA := hourly_high - hour22* L2_adjustment
    hourlyRLL := hourly_high - hour22* L3_adjustment
    hourlyRHL := hourly_low + hour22* L1_adjustment
    hourlyRLH := hourly_high - hour22* L1_adjustment
    longT :=  hourly_low + hour22* L4_adjustment
    shortT := hourly_high - hour22* L4_adjustment
else if is_hour23
    hour23:= array.avg(b23_range)
    hourlyRHA := hourly_low + hour23* L2_adjustment
    hourlyRHH := hourly_low + hour23* L3_adjustment
    hourlyRLA := hourly_high - hour23* L2_adjustment
    hourlyRLL := hourly_high - hour23* L3_adjustment
    hourlyRHL := hourly_low + hour23* L1_adjustment
    hourlyRLH := hourly_high - hour23* L1_adjustment
    longT :=  hourly_low + hour23* L4_adjustment
    shortT := hourly_high - hour23* L4_adjustment


//
//PLOT VBOX
//
plotST = plot(shortT, title = "plotST", color = color.gray, style = plot.style_circles, join = true)
plotLT = plot(longT, title = "plotLT", color = color.gray, style = plot.style_circles, join = true)
plotLR1 = plot(hourlyRHL, title = "plotLR1", color = color.aqua, style = plot.style_circles, join = true)
plotLR2 = plot(hourlyRLH, title = "plotLR2", color = color.aqua, style = plot.style_circles, join = true)

plothourlyRHA = plot(hourlyRHA, title = "hourlyRHA", color = color.green, style = plot.style_line, linewidth = 2)
plothourlyRHH = plot(hourlyRHH, title = "hourlyRHH", color = color.green, style = plot.style_line, linewidth = 2)
fill(plothourlyRHA,plothourlyRHH, title = 'Upper Band', color = color.new(color.green,60))

plothourlyRLA = plot(hourlyRLA, title = "hourlyRLA", color = color.red, style = plot.style_line, linewidth = 2)
plothourlyRLL = plot(hourlyRLL, title = "hourlyRLL", color = color.red, style = plot.style_line, linewidth = 2)
fill(plothourlyRLA,plothourlyRLL, title = 'Lower Band', color = color.new(color.red,60))


//
//TIMELINES
//
var color_time_line = false
if timeLineOn and is_hour10 and not is_hour10[1]
    if syminfo.root == "ES" or syminfo.root == "MES" 
     or syminfo.root == "NQ" or syminfo.root == "MNQ"
     or syminfo.root == "RTY" or syminfo.root == "M2K"
     or syminfo.root == "YM" or syminfo.root == "MYM"
     or syminfo.root == "CL" or syminfo.root == "MCL"
     or syminfo.root == "NG"
        color_time_line := true
else if timeLineOn and is_hour9 and not is_hour9[1]
    if syminfo.root == "ZB"
     or syminfo.root == "HG"
     or syminfo.root == "GC" or syminfo.root == "MGC"
     or syminfo.root == "SI" or syminfo.root == "SIL"
        color_time_line := true
else
    color_time_line := false
bgcolor(color_time_line ? color.new(color.orange, 80) : na)


// //
// //ALERTS
// //
// if alertsOn
//     if low<= hourlyRLH
//         alert("Volatility Box Long Entry Trigger", alert.freq_once_per_bar)
//     if high>= hourlyRHL
//         alert("Volatility Box Short Entry Trigger", alert.freq_once_per_bar)


hourlyClose = request.security(syminfo.tickerid, "60", close, lookahead = barmerge.lookahead_on)
trendingUp = hourly_high > hourlyRHH and hourlyClose > hourlyRHH and (is_hour7 or is_hour8 or is_hour9 or is_hour10) ? 1 : 0
trendingDown = hourly_low < hourlyRLL and hourlyClose < hourlyRLL and (is_hour7 or is_hour8 or is_hour9 or is_hour10) ? 1 : 0




// ################################EDGE SIGNALS#####################################################







edge_length = 14 //default 14
edge_price = close
edge_Volatility_Band = 14 //default 14
edge_STDEV_Multiplier = 2 //default 2
RSI_Period = 20 //default 14
edge_STDEV_Multiplier1 = 1 //default 1

// ### Dynamic RSI Colored Candles ###
NetChgAvg = ta.rma(edge_price - edge_price[1], edge_length)
TotChgAvg = ta.rma(math.abs(edge_price - edge_price[1]), edge_length)
ChgRatio =  TotChgAvg != 0 ? NetChgAvg / TotChgAvg : 0

DYNRSI = ta.rsi(close, RSI_Period)
SDBB = ta.stdev(DYNRSI, edge_Volatility_Band)

RSI = 50 * (ChgRatio + 1)
DYNAverage = ta.sma(DYNRSI, edge_Volatility_Band)

// ### Bollinger Band Plots for Colored Candles
UpperBollinger = DYNAverage + edge_STDEV_Multiplier * SDBB
UpperBollinger1 = DYNAverage + edge_STDEV_Multiplier1 * SDBB
LowerBollinger = DYNAverage - edge_STDEV_Multiplier * SDBB
LowerBollinger1 = DYNAverage - edge_STDEV_Multiplier1 * SDBB

////// Colored Candles
SOS = RSI < LowerBollinger //darkred
OS = RSI < LowerBollinger1 and RSI > LowerBollinger //red
NEUTRALH = RSI > DYNAverage and RSI < UpperBollinger1 //yellow
NEUTRALL = RSI < DYNAverage and RSI > LowerBollinger1 //orange
OB = RSI < UpperBollinger and RSI > UpperBollinger1 //green
SOB = RSI > UpperBollinger //darkgreen

////// Waddah Attar Explosion Indicator //////
sensitivity = 150 //"Sensitivity"
fastLength = 20 //"FastEMA Length"
slowLength = 40 //"SlowEMA Length"
channelLength = 20 //"BB Channel Length"
mult = 2.0 //"BB Stdev Multiplier"
deadZone = 20 //"No trade zone threshold"

t1 = ((ta.ema(close, fastLength) - ta.ema(close, slowLength)) - (ta.ema(close[1], fastLength) - ta.ema(close, slowLength))) * sensitivity
t2 = ((ta.ema(close[2], fastLength) - ta.ema(close, slowLength)) - (ta.ema(close[3], fastLength) - ta.ema(close, slowLength))) * sensitivity

e1 = ta.bbw(close, channelLength, mult)
e2 = ta.bbw(close[1], channelLength, mult)

trendUp = t1 >= 0 ? t1 : 0
trendDown = t1 < 0 ? (-1 * t1) : 0
tUp = trendUp //"UpTrend"
tDn = trendDown //"DownTrend"

// ### Trigger Signals ###
bearishDynamicRSISum = math.sum(SOS or OS ? 1.00 : 0, 7) >= 5
bullishDynamicRSIsum = math.sum(SOB or OB ? 1.00 : 0, 7) >= 5

var bearishDynamicRSISumCarry = 0
var bullishDynamicRSISumCarry = 0

bearishDynamicRSISumCarry := bearishDynamicRSISum ? 1 : bullishDynamicRSIsum ? 0 : bearishDynamicRSISumCarry[1]
bullishDynamicRSISumCarry :=  bullishDynamicRSIsum ? 1 : bearishDynamicRSISum ? 0 : bullishDynamicRSISumCarry[1]


filter_with_vbox = input.bool(true, title = 'Filter with VBOX')
vbox_bull_filter = (filter_with_vbox and low <= math.max(hourlyRLA,hourlyRLH))  or not filter_with_vbox
vbox_bear_filter = (filter_with_vbox and high >= math.min(hourlyRHA,hourlyRHL)) or not filter_with_vbox




// ################################ RSM #####################################################

rangeType = input.string("ADR", options = ["ADR", "ATR"])
// ################################################################
// ##########              ATR/ADR Calc                   #########
// ################################################################


ATRlength = input.int(14)
var float atr_range = na
if rangeType == "ADR"
    atr_range := ta.atr(ATRlength)
else
    atr_range := ta.sma(high - low , 7)


// ################################################################
// ##########                 RSI                         #########
// ################################################################
// input lengthRSI = 7;
// input rsi_price = close;
// input averageTypeRSI = AverageType.EXPONENTIAL;
// def rsm_NetChgAvg = MovingAverage(averageTypeRSI, rsi_price - rsi_price[1], lengthRSI);
// def rsm_TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(rsi_price - rsi_price[1]), lengthRSI);
// def rsm_ChgRatio = if rsm_TotChgAvg != 0 then rsm_NetChgAvg / rsm_TotChgAvg else 0;
// def rsm_RSI = 50 * (ChgRatio + 1);

lengthRSI = input.int(7)
rsi_price = input.source(close)
rsm_NetChgAvg = ta.ema(rsi_price - rsi_price[1], lengthRSI)
rsm_TotChgAvg = ta.ema(math.abs(rsi_price - rsi_price[1]), lengthRSI)
rsm_ChgRatio = rsm_TotChgAvg != 0 ? rsm_NetChgAvg / rsm_TotChgAvg : 0
rsm_RSI = 50 * (ChgRatio + 1)
 
// #################################################################
// ##########                 Stochastic Slow             #########
// ################################################################
over_boughtSt = input.int(80)
over_soldSt = input.int(20)
KPeriod = input.int(14)
DPeriod = input.int(3)

lowest_k = ta.lowest(low, KPeriod)
c1 = close - lowest_k
c2 = ta.highest(high, KPeriod) - lowest_k
FastK = c2 != 0 ? c1 / c2 * 100 : 0

SlowK = ta.rma(FastK, 3)
SlowD = ta.rma(SlowK, DPeriod)


// ################################################################
// ##########                  MACD                       #########
// ################################################################
rsm_fastLength = input.int(12)
rsm_slowLength = input.int(26)
MACDLength = input.int(9)

Value = ta.wma(close, rsm_fastLength) - ta.wma(close, rsm_slowLength)
Avg = ta.wma(Value, MACDLength)
Diff = Value - Avg


rsm_bull =   RSI >= 50 and SlowK >= 50 and Value > Avg
rsm_bear =  RSI < 50 and SlowK < 50 and Value < Avg




color_rsm_candles = input.bool(true, title = "Color rsm Candles")
show_rsm_label  = input.bool(true, title = "Show rsm Label")
barcolor(color_rsm_candles and rsm_bear ? color.red :  color_rsm_candles and rsm_bull ? color.green : color_rsm_candles ? color.gray : na)

filter_with_rsm = input.bool(true, title =  'Filter with rsm')
rsm_bull_filter = (filter_with_rsm and rsm_bull) or not filter_with_rsm
rsm_bear_filter = (filter_with_rsm and rsm_bear) or not filter_with_rsm





// ################################ STRATEGY #####################################################


bullishTrigger =   vbox_bull_filter and rsm_bull_filter and bearishDynamicRSISumCarry and (tUp and not tUp[1]) ? 1 : 0
bearishTrigger =   vbox_bear_filter and rsm_bear_filter and bullishDynamicRSISumCarry and (tDn and not tDn[1]) ? 1 : 0


plotshape(bullishTrigger, title = 'Bullish Trigger', location = location.belowbar, style = shape.triangleup, color = color.green, size = size.small)
plotshape(bearishTrigger, title = 'Bearish Trigger', location = location.abovebar, style = shape.triangledown, color = color.red, size = size.small)


//
//ALERTS
//
if alertsOn
    if bullishTrigger[1]
        alert("Bull Edge Signal", alert.freq_once_per_bar)
    if bearishTrigger[1]
        alert("Bear Edge Signal", alert.freq_once_per_bar)


tgt_1 = input.float(5.00, title = 'Target 1')
tgt_2 = input.float(10.00, title = 'Target 2')
stop_loss = input.float(20.00, title = 'Stop Loss')


var last_signal = 0
var entry_edge_price = 0.00
last_signal :=  bullishTrigger ? 1 :  bearishTrigger ? -1 :  last_signal[1] == 1 and not rsm_bull ? 0 :  last_signal[1] == -1 and not rsm_bear ? 0 : last_signal[1]
entry_edge_price :=   bullishTrigger[1] or bearishTrigger[1] ? open : entry_edge_price[1]

actual_entry_price = last_signal[1] == 0 ? na : entry_edge_price
tgt1_price = last_signal[1] == 1 ? entry_edge_price * (1+tgt_1/100) : last_signal[1] == -1 ? entry_edge_price * (1-tgt_1/100) : na
tgt2_price = last_signal[1] == 1 ? entry_edge_price * (1+tgt_2/100) : last_signal[1] == -1 ? entry_edge_price * (1-tgt_2/100) : na
stop_price = last_signal[1] == 1 ? entry_edge_price * (1-stop_loss/100) : last_signal[1] == -1 ? entry_edge_price * (1+stop_loss/100) : na

entry_plot = plot(actual_entry_price, title = "Entry Price", color = color.aqua, style = plot.style_linebr, linewidth = 5)
tgt1_plot = plot(tgt1_price, title = "TGT 1", color = last_signal == 1 ? color.green : color.red, style = plot.style_linebr, linewidth = 5)
tgt2_plot = plot(tgt2_price, title = "TGT 2", color =last_signal == 1 ? color.green : color.red, style = plot.style_linebr, linewidth = 5)
stop_plot = plot(stop_price, title = "STOP", color = last_signal == 1 ? color.fuchsia : color.teal, style = plot.style_linebr, linewidth = 5)



show_entry_bubble = input.bool(true, title = 'Show Entry Bubble')
if show_entry_bubble and last_signal != 0
    entry_label = label.new(bar_index+1, entry_edge_price , text = 'Entry', color = color.aqua, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
    tgt1_label = label.new(bar_index+1, tgt1_price , text = 'T1', color = last_signal == 1 ? color.green : color.red, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
    tgt2_label = label.new(bar_index+1, tgt2_price , text = 'T2', color = last_signal == 1 ? color.green : color.red, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
    stop_label = label.new(bar_index+1, stop_price , text = 'Stop', color = last_signal == 1 ? color.fuchsia : color.teal, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
    
    if last_signal == last_signal[1]
        label.delete(entry_label[1])
        label.delete(tgt1_label[1])
        label.delete(tgt2_label[1])
        label.delete(stop_label[1])
        
        
    if last_signal == 1 and last_signal[1] != 1
        long_label = label.new(bar_index[1], low , text = 'LONG ' + str.tostring(close), color = color.green, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
  
        
    if last_signal == -1 and last_signal[1] != -1
        short_label = label.new(bar_index[1], high , text = 'SHORT ' + str.tostring(close), color = color.red, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
  
 
show_exit_bubble = input.bool(true, title = 'Show Exit Bubble')
if show_exit_bubble 
    if (rsm_bull[1] and not rsm_bull and last_signal[1] == 1)
        exit_long = label.new(bar_index, close , text = 'Exit ' + str.tostring(close), color = color.white, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
    if (rsm_bear[1] and not rsm_bear and last_signal[1] == -1)
        exit_short = label.new(bar_index, close , text = 'Exit ' + str.tostring(close), color = color.white, style = label.style_label_left, textcolor = color.black, size = size.normal, textalign = text.align_left)
       

fill(entry_plot, tgt2_plot, color.new(color.green,80))
fill(entry_plot, stop_plot, color.new(color.red,80))


show_position_labels = input.bool(true, title = 'Show Position Labels')
//
//TABLE
//
var t = table.new(position = position.top_right, columns = 6, rows = 1, bgcolor = color.new(#000000,0), border_width = 1)
if barstate.islast
    table.cell(table_id = t, column = 0, row = 0, text = currentBoxLabel ?  "VB: Scalper Mod" : na, bgcolor = color.white)
    table.cell(table_id = t, column = 1, row = 0, text = show_rsm_label ?  "rsm" : na, bgcolor =rsm_bear ? color.red : rsm_bull ? color.green : color.gray)
    
    table.cell(table_id = t, column = 2, row = 0, text = show_position_labels ?  "Entry: " + str.tostring(actual_entry_price) : na, bgcolor = 
         last_signal[1] == 1 ? color.aqua : last_signal[1] == -1 ? color.aqua : color.black)
        
    table.cell(table_id = t, column = 3, row = 0, text = show_position_labels ?  "T1: " + str.tostring(tgt1_price) : na, bgcolor = 
         last_signal[1] == 1 ? color.green : last_signal[1] == -1 ? color.red : color.black)
        
    table.cell(table_id = t, column = 4, row = 0, text = show_position_labels ?  "T2: " + str.tostring(tgt2_price) : na, bgcolor =  
         last_signal[1] == 1 ? color.green : last_signal[1] == -1 ? color.red : color.black)
        
    table.cell(table_id = t, column = 5, row = 0, text = show_position_labels ?  "STOP: " + str.tostring(stop_price) : na, bgcolor = 
         last_signal[1] == 1 ? color.fuchsia : last_signal[1] == -1 ? color.teal : color.black)

Overview

Average Daily Range with Time Session Highlighter highlights time sessions on the price chart and can show a timeline and the current range box. Optional filters use a volatility box plus RSI, stochastic, and MACD settings to color candles and display entry, exit, target, and stop labels. Alerts can be turned on. It requests hourly highs and lows with lookahead enabled, so the current hour can change before that hour closes.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Sessions & time, Oscillators & momentum

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Number of Daysint20number_of_days
Alerts OnboolfalsealertsOn
Current Box LabelbooltruecurrentBoxLabel
TimelinebooltruetimeLineOn
Filter with VBOXbooltruefilter_with_vbox
rangeTypestringADRrangeType
ATRlengthint14ATRlength
lengthRSIint7lengthRSI
rsi_pricesourceclosersi_price
over_boughtStint80over_boughtSt
over_soldStint20over_soldSt
KPeriodint14KPeriod
Show all 25 settings
SettingTypeDefaultVariable
DPeriodint3DPeriod
rsm_fastLengthint12rsm_fastLength
rsm_slowLengthint26rsm_slowLength
MACDLengthint9MACDLength
Color rsm Candlesbooltruecolor_rsm_candles
Show rsm Labelbooltrueshow_rsm_label
Filter with rsmbooltruefilter_with_rsm
Target 1float5.00tgt_1
Target 2float10.00tgt_2
Stop Lossfloat20.00stop_loss
Show Entry Bubblebooltrueshow_entry_bubble
Show Exit Bubblebooltrueshow_exit_bubble
Show Position Labelsbooltrueshow_position_labels
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Z-Score Highlighter

by ryangaraygay
2 stars

Calculates the Z-score of closing prices over a specified moving average period and standard deviation length. It identifies potential statistical outliers by checking if the Z-score breaches positive or negative threshold levels during a user-configurable tra

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · MIT GitHub repository of Z-Score Highlighter

Gold Dominator Pro

by thanvish21
1 stars

Gold Dominator Pro is a multi-indicator overlay designed primarily for gold trading. It combines higher-timeframe exponential moving averages with momentum oscillators like RSI, MACD, and StochRSI, alongside volatility tools such as ATR, Bollinger Bands, and A

Indicator v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Gold Dominator Pro
1 stars

Overlay indicator for XAUUSD gold that draws predicted support and resistance levels at 08:00 and 19:00 SGT on the price chart along with buy and sell take-profit levels spaced by ATR multiples. It generates RSI reversal signals as triangles when the indicator

Indicator v5 Support & resistanceOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Predicted Signals + RSI trigger

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers