Nifty strike price 2/3σ 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RajeevNaik
//@version=4
study("Nifty strike price 2/3σ ",overlay=true)
src = input(close, title="source")
step = input(title="strike steps", type=input.integer, defval=50)

// nearest full 50s value.
RoundTofifty(value) =>
    round(value / 50.0) * 50
x = RoundTofifty(src)
one_day = 24 * 60 * 60 * 1000

lineColor = input(title="Strike line Colour", type=input.color, defval=color.new(color.blue, 0))
single(tkr, dte, strike) =>
    if syminfo.ticker == tkr
        line.new(time, strike, time + dte * one_day, strike,style=line.style_dotted, color = lineColor, xloc = xloc.bar_time)
strangle(tkr, dte, put, call) =>
    single(tkr, dte, put)
    single(tkr, dte, call)
    
if barstate.islast
    exp = 1
    
    
    // Bank nifty strikes
    
    single("NIFTY", exp, x+step*25) 
    single("NIFTY", exp, x+step*24)
    single("NIFTY", exp, x+step*23) 
    single("NIFTY", exp, x+step*22)
    single("NIFTY", exp, x+step*21) 
    single("NIFTY", exp, x+step*20)
    single("NIFTY", exp, x+step*19) 
    single("NIFTY", exp, x+step*18)
    single("NIFTY", exp, x+step*17) 
    single("NIFTY", exp, x+step*16)
    single("NIFTY", exp, x+step*15) 
    single("NIFTY", exp, x+step*14)
    single("NIFTY", exp, x+step*13) 
    single("NIFTY", exp, x+step*12)
    single("NIFTY", exp, x+step*11) 
    single("NIFTY", exp, x+step*10)
    single("NIFTY", exp, x+step*9) 
    single("NIFTY", exp, x+step*8)
    single("NIFTY", exp, x+step*7) 
    single("NIFTY", exp, x+step*6)
    single("NIFTY", exp, x+step*5) 
    single("NIFTY", exp, x+step*4)
    single("NIFTY", exp, x+step*3) 
    single("NIFTY", exp, x+step*2) 
    single("NIFTY", exp, x+step*1) 
    single("NIFTY", exp, x)
    single("NIFTY", exp, x-step*1) 
    single("NIFTY", exp, x-step*2)  
    single("NIFTY", exp, x-step*3)  
    single("NIFTY", exp, x-step*4) 
    single("NIFTY", exp, x-step*5)  
    single("NIFTY", exp, x-step*6)
    single("NIFTY", exp, x-step*7) 
    single("NIFTY", exp, x-step*8)  
    single("NIFTY", exp, x-step*9)  
    single("NIFTY", exp, x-step*10) 
    single("NIFTY", exp, x-step*11)  
    single("NIFTY", exp, x-step*12)
    single("NIFTY", exp, x-step*13) 
    single("NIFTY", exp, x-step*14)  
    single("NIFTY", exp, x-step*15)  
    single("NIFTY", exp, x-step*16) 
    single("NIFTY", exp, x-step*17)  
    single("NIFTY", exp, x-step*18)
    single("NIFTY", exp, x-step*19) 
    single("NIFTY", exp, x-step*20)  
    single("NIFTY", exp, x-step*21)  
    single("NIFTY", exp, x-step*22) 
    single("NIFTY", exp, x-step*23)  
    single("NIFTY", exp, x-step*24)
    single("NIFTY", exp, x-step*25)

//BB for 2 sigma limits
length1 = input(20, minval=1,title="BB2 length")
src2 = input(close, title="BB2 Source")
mult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis1 = sma(src2, length1)
dev1 = mult1 * stdev(src2, length1)
upper1 = basis1 + dev1
lower1 = basis1 - dev1
offset1 = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//p3 = plot(upper1, "Upper", color=color.orange, offset = offset)
//p4 = plot(lower1, "Lower", color=color.orange, offset = offset)

//2sigma bands
lineColor2 = input(title="2 sigma line Colour", type=input.color, defval=color.new(color.white, 0))
single2(tkr, dte, strike) =>
    if syminfo.ticker == tkr
        line.new(time, strike, time + dte * one_day, strike, style=line.style_solid, color = lineColor2, xloc = xloc.bar_time, width=1)

strangle2(tkr, dte, put, call) =>
    single2(tkr, dte, put)
    single2(tkr, dte, call)
    
if barstate.islast
    exp = 1
    
    // 2Sigma limits
     
    strangle2("NIFTY", exp, lower1, upper1)
    
//BB for 3 sigma limits
length = input(20, minval=1,title="BB3 length")
src1 = input(close, title="BB3 Source")
mult = input(3.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src1, length)
dev = mult * stdev(src1, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
//p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
//p2 = plot(lower, "Lower", color=#2962FF, offset = offset)

//3sigma bands
lineColor1 = input(title="3 sigma line Colour", type=input.color, defval=color.new(color.red, 0))
single1(tkr, dte, strike) =>
    if syminfo.ticker == tkr
        line.new(time, strike, time + dte * one_day, strike, style=line.style_solid, color = lineColor1, xloc = xloc.bar_time, width=1)

strangle1(tkr, dte, put, call) =>
    single1(tkr, dte, put)
    single1(tkr, dte, call)
    
if barstate.islast
    exp = 1
    
    // 3Sigma limits
    
    strangle1("NIFTY", exp, lower, upper)
