Waddah Attar Weekly Camarilla Pivots [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 Weekly CAMARILLA Pivots [Loxx]", shorttitle = "WAWCP [Loxx]", overlay = true)

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

lightgreencolor = #96E881 
lightredcolor =  #DF4F6C
lightbluecolor =  #4f6cdf

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 > 240
    runtime.error("Error: Invalid timerame. This indicaator only works on timeframes 1 hour and below.")

level1 = input.float(0.09, "Fibonacci Level 1", step = 0.01, minval = 0.0)
level2 = input.float(0.18, "Fibonacci Level 2", step = 0.01, minval = 0.0)
level3 = input.float(0.27, "Fibonacci Level 3", step = 0.01, minval = 0.0)
level4 = input.float(0.55, "Fibonacci Level 4", step = 0.01, minval = 0.0)


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

int kRSIDayPeriod= 5

Q = _high1 - _low1

H1 = _close1 + (Q * level1)
L1 = _close1 - (Q * level1)
 
H2 = _close1 + (Q * level2)
L2 = _close1 - (Q * level2)
 
H3 = _close1 + (Q * level3)
L3 = _close1 - (Q * level3)
 
H4 = _close1 + (Q * level4)
L4 = _close1 - (Q * level4)
 
hlUp = plot(H1, color = greencolor, style = plot.style_stepline, linewidth = 2)
llDn = plot(L1, color = redcolor, style = plot.style_stepline, linewidth = 2)

plot(H2, color = greencolor, style = plot.style_stepline, linewidth = 2)
plot(L2, color = redcolor, style = plot.style_stepline, linewidth = 2)

plot(H3, color = greencolor, style = plot.style_stepline, linewidth = 2)
plot(L3, color = redcolor, style = plot.style_stepline, linewidth = 2)


upH = plot(H4, color = greencolor, style = plot.style_stepline, linewidth = 5)
dnL = plot(L4, color = redcolor, style = plot.style_stepline, linewidth = 5)

fill(hlUp, upH, color.new(greencolor, 95))
fill(dnL, llDn, color.new(redcolor, 95))

h1Bufferlabel = 
     label.new(x=bar_index[1] + 5, 
         y = H1, 
         textalign = text.align_center, 
         color = darkGreenColor,
         textcolor = color.white, 
         text= "H1: " + str.tostring(H1, f_tickFormat()),
         size=size.normal, 
         style=label.style_label_left) 

h2Bufferlabel = 
     label.new(x=bar_index[1] + 5, 
         y = H2, 
         textalign = text.align_center, 
         color = darkGreenColor,
         textcolor = color.white, 
         text= "H2: " + str.tostring(H2, f_tickFormat()),
         size=size.normal, 
         style=label.style_label_left) 

h3Bufferlabel = 
     label.new(x=bar_index[1] + 5, 
         y = H3, 
         textalign = text.align_center, 
         color = darkGreenColor,
         textcolor = color.white, 
         text= "H3: " + str.tostring(H3, f_tickFormat()),
         size=size.normal, 
         style=label.style_label_left) 

h4Bufferlabel = 
     label.new(x=bar_index[1] + 5, 
         y = H4, 
         textalign = text.align_center, 
         color = darkGreenColor,
         textcolor = color.white, 
         text= "H4: " + str.tostring(H4, f_tickFormat()),
         size=size.normal, 
         style=label.style_label_left) 



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

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

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

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

 
label.delete(h1Bufferlabel[1])
label.delete(h2Bufferlabel[1])
label.delete(h3Bufferlabel[1])
label.delete(h4Bufferlabel[1])
label.delete(l1Bufferlabel[1])
label.delete(l2Bufferlabel[1])
label.delete(l3Bufferlabel[1])
label.delete(l4Bufferlabel[1])
 



















