Variation analysis 1.1
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © celsorodrigomf

//@version=5
indicator("Analise de Variação 1.0" , "AV_1", overlay=true)
// Enable or disable pivot labels
pricebase   = input(0, "Start price")
showLabels  = input(true, title="Show Labels?")
showInner   = input(true, title="Plot Inner Levels?")

// Step 2. Calculate indicator values
// Create a function to fetch daily
GetData(res, data) => 
    request.security(syminfo.tickerid, res, data[1],lookahead=barmerge.lookahead_on)



dailyClose = pricebase == 0 ? GetData("D", close) : pricebase

rs = dailyClose

// Calculate levels values
rs2  = rs * 0.0025 + rs
rs3  = rs * 0.005  + rs
rs4  = rs * 0.0075 + rs
rs5  = rs * 0.01   + rs
rs6  = rs * 0.0125 + rs
rs7  = rs * 0.015  + rs
rs8  = rs * 0.0175 + rs
rs9  = rs * 0.02   + rs
rs10 = rs * 0.0225 + rs
rs11 = rs * 0.025  + rs
rs12 = rs * 0.0275 + rs
rs13 = rs * 0.03   + rs
rs14 = rs * 0.0325 + rs
rs15 = rs * 0.035  + rs
rs16 = rs * 0.0375 + rs
rs17 = rs * 0.04   + rs
rs18 = rs * 0.0425 + rs
rs19 = rs * 0.045  + rs
rs20 = rs * 0.0475 + rs
//
rs21 = rs - rs * 0.0025
rs22 = rs - rs * 0.005
rs23 = rs - rs * 0.0075
rs24 = rs - rs * 0.01
rs25 = rs - rs * 0.0125
rs26 = rs - rs * 0.015
rs27 = rs - rs * 0.0175
rs28 = rs - rs * 0.02
rs29 = rs - rs * 0.0225
rs30 = rs - rs * 0.025      
rs31 = rs - rs * 0.0275
rs32 = rs - rs * 0.03
rs33 = rs - rs * 0.0325
rs34 = rs - rs * 0.035      
rs35 = rs - rs * 0.0375
rs36 = rs - rs * 0.04
rs37 = rs - rs * 0.0425
rs38 = rs - rs * 0.045      
rs39 = rs - rs * 0.0475


plot(rs,  title ="0%"   , style=plot.style_line,color=color.yellow,linewidth=2)

plot(showInner ? rs2 : na ,  title = "0.25%", style=plot.style_circles,  color=#4caf4f45,linewidth=1)
plot(rs3,  title = "0.5%" , style=plot.style_linebr,    color=#034706,linewidth=2)
plot(showInner ? rs4 : na ,  title = "0.75%" , style=plot.style_circles, color=#4caf4f45 ,linewidth=1)
plot(rs5,  title = "1.0%" , style=plot.style_line,    color=color.green,linewidth=3)
plot(showInner ? rs6 : na ,  title = "1.25%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs7,  title = "1.5%" , style=plot.style_linebr,    color=#034706,linewidth=2)
plot(showInner ? rs8 : na ,  title = "1.75%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs9,  title = "2.0%" , style=plot.style_line,    color=color.green,linewidth=3)
plot(showInner ? rs10 : na , title = "2.25%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs11, title = "2.5%" , style=plot.style_linebr,    color=#034706,linewidth=2)
plot(showInner ? rs12 : na , title = "2.75%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs13, title = "3.0%" , style=plot.style_line,    color=color.green,linewidth=3)
plot(showInner ? rs14 : na , title = "3.25%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs15, title = "3.5%" , style=plot.style_linebr,    color=#034706,linewidth=2)
plot(showInner ? rs16 : na , title = "3.75%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs17, title = "4.0%" , style=plot.style_line,    color=color.green,linewidth=3)
plot(showInner ? rs18 : na , title = "4.25%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)
plot(rs19, title = "4.5%" , style=plot.style_linebr,    color=#034706,linewidth=2)
plot(showInner ? rs20 : na , title = "4.75%" , style=plot.style_circles, color=#4caf4f45,linewidth=1)


plot(showInner ? rs21 : na , title="-0.25%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs22, title="-0.5%"   , style=plot.style_linebr,    color=#6d0e0e,linewidth=2)
plot(showInner ? rs23 : na , title="-0.75%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs24, title="-1.0%"   , style=plot.style_line,    color=color.red,linewidth=3)
plot(showInner ? rs25 : na , title="-1.25%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs26, title="-1.5%"   , style=plot.style_linebr,    color=#6d0e0e,linewidth=2)
plot(showInner ? rs27 : na , title="-1.75%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs28, title="-2.0%"   , style=plot.style_line,    color=color.red,linewidth=3)
plot(showInner ? rs29 : na , title="-2.25%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs30, title="-2.5%"   , style=plot.style_linebr,    color=#6d0e0e,linewidth=2)
plot(showInner ? rs31 : na , title="-2.75%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs32, title="-3.0%"   , style=plot.style_line,    color=color.red,linewidth=3)
plot(showInner ? rs33 : na , title="-3.25%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs34, title="-3.5%"   , style=plot.style_linebr,    color=#6d0e0e,linewidth=2)
plot(showInner ? rs35 : na , title="-3.75%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs36, title="-4.0%"   , style=plot.style_line,    color=color.red,linewidth=3)
plot(showInner ? rs37 : na , title="-4.25%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)
plot(rs38, title="-4.5%"   , style=plot.style_linebr,    color=#6d0e0e,linewidth=2)
plot(showInner ? rs39 : na , title="-4.75%" ,  style=plot.style_circles,  color=#a0292952,linewidth=1)


if showLabels
    nLabel0     = label.new(bar_index,rs   + 25,    text="0%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    
    nLabel05    = label.new(bar_index,rs3   + 25,   text="0.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel1     = label.new(bar_index,rs5   + 25,   text="1%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel15    = label.new(bar_index,rs7   + 25,   text="1.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel2     = label.new(bar_index,rs9   + 25,   text="2%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel25    = label.new(bar_index,rs11   + 25,  text="2.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel3     = label.new(bar_index,rs13   + 25,  text="3%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel35    = label.new(bar_index,rs15   + 25,  text="3.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel4     = label.new(bar_index,rs17  + 25,   text="4%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel45    = label.new(bar_index,rs19   + 25,  text="4.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    
    nLabel_05    = label.new(bar_index,rs22   + 25, text="-5%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_1     = label.new(bar_index,rs24   + 25, text="-1%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_15    = label.new(bar_index,rs26   + 25, text="-1.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_2     = label.new(bar_index,rs28   + 25, text="-2%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_25    = label.new(bar_index,rs30   + 25, text="-2.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_3     = label.new(bar_index,rs32   + 25, text="-3%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_35    = label.new(bar_index,rs34   + 25, text="-3.5%" , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_4     = label.new(bar_index,rs36   + 25, text="-4%"   , size=size.small , style = label.style_label_left, color = #ffffff)
    nLabel_45    = label.new(bar_index,rs38   + 25, text="4.5%"  , size=size.small , style = label.style_label_left, color = #ffffff)
    
    label.delete(nLabel0[1])
    label.delete(nLabel05[1])
    label.delete(nLabel1[1])
    label.delete(nLabel15[1])
    label.delete(nLabel2[1])
    label.delete(nLabel25[1])
    label.delete(nLabel3[1])
    label.delete(nLabel35[1])
    label.delete(nLabel4[1])
    label.delete(nLabel45[1])
    
    label.delete(nLabel_05[1])
    label.delete(nLabel_1[1])
    label.delete(nLabel_15[1])
    label.delete(nLabel_2[1])
    label.delete(nLabel_25[1])
    label.delete(nLabel_3[1])
    label.delete(nLabel_35[1])
    label.delete(nLabel_4[1])
    label.delete(nLabel_45[1])


    

    