Waddah Attar Hidden Levels [Loxx]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx

//@version=5
indicator("Waddah Attar Hidden Levels [Loxx]",  shorttitle = "WAHL [Loxx]", overlay = true)

greencolor = #2DD204
redcolor = #D2042D 
bluecolor = #042dd2

lightgreencolor = #D2042D 
lightredcolor =  #DF4F6C

darkGreenColor =  #1B7E02 
darkRedColor = #93021F
darkBlueColor = #021f93

f_tickFormat() =>
    _s = str.tostring(syminfo.mintick)
    _s := str.replace_all(_s, '25', '00')
    _s := str.replace_all(_s, '5', '0')
    _s := str.replace_all(_s, '1', '0')
    _s
    
tfInMinutes(simple string tf = "") =>
    float chartTf =
      timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
    float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf, chartTf)
    
float chartTFInMinutes = tfInMinutes()

if chartTFInMinutes > 60
    runtime.error("Error: Invalid timerame. This indicaator only works on timeframes 1 hour and below.")

multiplier = input.float(0.618, "Fibonacci Multiplier", minval = 0.0, step = 0.01)

_close1 = request.security(syminfo.tickerid, "D", close[1], barmerge.gaps_off, barmerge.lookahead_on)
_close2 = request.security(syminfo.tickerid, "D", close[2], barmerge.gaps_off, barmerge.lookahead_on)
_close3 = request.security(syminfo.tickerid, "D", close[3], barmerge.gaps_off, barmerge.lookahead_on)
_open1 = request.security(syminfo.tickerid, "D", open[1], barmerge.gaps_off, barmerge.lookahead_on)
_high1 = request.security(syminfo.tickerid, "D", high[1], barmerge.gaps_off, barmerge.lookahead_on)
_low1 = request.security(syminfo.tickerid, "D", low[1], barmerge.gaps_off, barmerge.lookahead_on)

c1 = 0.0, c2 = 0.0

if(_close1 >= _open1)
    c1 := (_high1 - _close1) / 2 + _close1
    c2 := (_open1 - _low1) / 2 + _low1

else
    c1 := (_high1 - _open1) / 2 + _open1  
    c2 := (_close1 - _low1) / 2 + _low1 
    
topBuffer = c1
bottomBuffer = c2
midBuffer = (c1 + c2) / 2
upBoundaryBuffer = c1 + (c1 - c2) * multiplier
dnBoundaryBuffer = c2 - (c1 - c2) * multiplier

plot(topBuffer, color = redcolor, linewidth = 2, style = plot.style_circles)
plot(bottomBuffer, color = greencolor, linewidth = 2, style = plot.style_circles)
plot(midBuffer, color = color.white, linewidth = 1, style = plot.style_circles)
up = plot(upBoundaryBuffer, color = bluecolor, linewidth = 2, style = plot.style_circles)
dn = plot(dnBoundaryBuffer, color = bluecolor, linewidth = 2, style = plot.style_circles)

fill(up, dn, color.new(color.gray, 90))

topBufferLabel = 
     label.new(x=bar_index[1] + 5, 
         y = topBuffer, 
         textalign = text.align_center, 
         color = darkRedColor,
         textcolor = color.white, 
         text= str.tostring(topBuffer, f_tickFormat()), 
         size=size.normal, 
         style=label.style_label_left)  

bottomBufferLabel = 
     label.new(x=bar_index[1] + 5, 
         y = bottomBuffer, 
         textalign = text.align_center, 
         color = darkGreenColor,
         textcolor = color.white, 
         text= str.tostring(bottomBuffer, f_tickFormat()),
         size=size.normal, 
         style=label.style_label_left)  
         
midBufferLabel = 
     label.new(x=bar_index[1] + 5, 
         y = midBuffer, 
         textalign = text.align_center, 
         color = color.white,
         textcolor = bluecolor, 
         text= str.tostring(midBuffer, f_tickFormat()), 
         size=size.normal, 
         style=label.style_label_left) 
         
upBoundaryBufferLabel = 
     label.new(x=bar_index[1] + 5, 
         y = upBoundaryBuffer, 
         textalign = text.align_center, 
         color = darkBlueColor,
         textcolor = color.white, 
         text= str.tostring(upBoundaryBuffer, f_tickFormat()) + " (" + str.tostring(multiplier, "#.###") + ")", 
         size=size.normal, 
         style=label.style_label_left) 
         
dnBoundaryBufferLabel = 
     label.new(x=bar_index[1] + 5, 
         y = dnBoundaryBuffer, 
         textalign = text.align_center, 
         color = darkBlueColor,
         textcolor = color.white, 
         text= str.tostring(dnBoundaryBuffer, f_tickFormat()) + " (" + str.tostring(multiplier, "#.###") + ")",
         size=size.normal, 
         style=label.style_label_left) 
         
label.delete(topBufferLabel[1])
label.delete(bottomBufferLabel[1])
label.delete(midBufferLabel[1])
label.delete(upBoundaryBufferLabel[1])
label.delete(dnBoundaryBufferLabel[1])














