Pi Frame (Dynamic)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fvideira

//@version=5
indicator("Pi Frame (Dynamic)", overlay=true)

// Study of Pi levels from Eliza123123's quantative trading series: https://youtu.be/S7UMA__wz74



// Inputs

piStd = input.bool(true, "Standard Multiples", inline = "Standard", group = "Pi Constant 3.14159")
StdCol = input.color(color.new(color.black, 0), "", inline = "Standard", group = "Pi Constant 3.14159")
piPrime = input.bool(true, "Prime Multiples", inline = "Prime", group = "Pi Constant 3.14159")
PrimeCol = input.color(color.new(color.silver, 0), "", inline = "Prime", group = "Pi Constant 3.14159")
piMulti = input.bool(true, "Multples of 10", inline = "Multi", group = "Pi Constant 3.14159")
MultiCol = input.color(color.new(color.orange, 10), "", inline = "Multi", group = "Pi Constant 3.14159")


extendRight = input.bool(false, "Extend Lines")
var extending = extend.none
if extendRight
    extending := extend.right
if not extendRight
    extending := extend.none



// Scale Factors & Constants

scale = 0.0

if close >= 10000
    scale := 1000

if close >= 1000 and close <=9999.999999
    scale := 100

if close >= 100 and close <=999.999999
    scale := 10

if close >= 10 and close <=99.999999
    scale := 1
    
if close >= 1 and close <=9.999999
    scale := 0.1
    
if close >= 0.1 and close <=0.999999
    scale := 0.01

if close >= 0.01 and close <=0.099999
    scale := 0.001
    
if close >= 0.001 and close <=0.009999
    scale := 0.0001
    
    
    
// Variables

pi = 3.14159 * scale

pi1 = 0.0
pi2 = 0.0
pi3 = 0.0
pi4 = 0.0
pi5 = 0.0
pi6 = 0.0
pi7 = 0.0
pi8 = 0.0
pi9 = 0.0
pi10 = 0.0
pi11 = 0.0
pi12 = 0.0
pi13 = 0.0
pi14 = 0.0
pi15 = 0.0
pi16 = 0.0
pi17 = 0.0
pi18 = 0.0
pi19 = 0.0
pi20 = 0.0
pi21 = 0.0
pi22 = 0.0
pi23 = 0.0
pi24 = 0.0
pi25 = 0.0
pi26 = 0.0
pi27 = 0.0
pi28 = 0.0
pi29 = 0.0
pi30 = 0.0
pi31 = 0.0
pi32 = 0.0
pi33 = 0.0
pi34 = 0.0
pi35 = 0.0
pi36 = 0.0
pi37 = 0.0
pi38 = 0.0



// If clauses (for inputs to work as on/off)

if piStd
    pi4 := pi*4
    pi6 := pi*6
    pi8 := pi*8
    pi9 := pi*9
    pi12 := pi*12
    pi14 := pi*14
    pi15 := pi*15
    pi16 := pi*16
    pi18 := pi*18
    pi21 := pi*21
    pi22 := pi*22
    pi24 := pi*24
    pi25 := pi*25
    pi26 := pi*26
    pi27 := pi*27
    pi28 := pi*28
    pi32 := pi*32
    pi33 := pi*33
    pi34 := pi*34
    pi35 := pi*35
    pi36 := pi*36
    pi38 := pi*38
else
    pi4 := na
    pi6 := na
    pi8 := na
    pi9 := na
    pi12 := na
    pi14 := na
    pi15 := na
    pi16 := na
    pi18 := na
    pi21 := na
    pi22 := na
    pi24 := na
    pi25 := na
    pi26 := na
    pi27 := na
    pi28 := na
    pi32 := na
    pi33 := na
    pi34 := na
    pi35 := na
    pi36 := na
    pi38 := na

if piPrime
    pi1 := pi*1
    pi2 := pi*2
    pi3 := pi*3
    pi5 := pi*5
    pi7 := pi*7
    pi11 := pi*11
    pi13 := pi*13
    pi17 := pi*17
    pi19 := pi*19
    pi23 := pi*23
    pi29 := pi*29
    pi31 := pi*31
    pi37 := pi*37
else
    pi1 := na
    pi2 := na
    pi3 := na
    pi5 := na
    pi7 := na
    pi11 := na
    pi13 := na
    pi17 := na
    pi19 := na
    pi23 := na
    pi29 := na
    pi31 := na
    pi37 := na
    
if piMulti
    pi10 := pi*10
    pi20 := pi*20
    pi30 := pi*30
else
    pi10 := na
    pi20 := na
    pi30 := na
    
    
    
// Plots

lpi1 = line.new(bar_index[4999], pi1, bar_index, pi1, color = PrimeCol, width = 1, extend = extending)
lpi2 = line.new(bar_index[4999], pi2, bar_index, pi2, color = PrimeCol, width = 1, extend = extending)
lpi3 = line.new(bar_index[4999], pi3, bar_index, pi3, color = PrimeCol, width = 1, extend = extending)
lpi4 = line.new(bar_index[4999], pi4, bar_index, pi4, color = StdCol, width = 1, extend = extending)
lpi5 = line.new(bar_index[4999], pi5, bar_index, pi5, color = PrimeCol, width = 1, extend = extending)
lpi6 = line.new(bar_index[4999], pi6, bar_index, pi6, color = StdCol, width = 1, extend = extending)
lpi7 = line.new(bar_index[4999], pi7, bar_index, pi7, color = PrimeCol, width = 1, extend = extending)
lpi8 = line.new(bar_index[4999], pi8, bar_index, pi8, color = StdCol, width = 1, extend = extending)
lpi9 = line.new(bar_index[4999], pi9, bar_index, pi9, color = PrimeCol, width = 1, extend = extending)
lpi10 = line.new(bar_index[4999], pi10, bar_index, pi10, color = MultiCol, width = 1, extend = extending)
lpi11 = line.new(bar_index[4999], pi11, bar_index, pi11, color = PrimeCol, width = 1, extend = extending)
lpi12 = line.new(bar_index[4999], pi12, bar_index, pi12, color = StdCol, width = 1, extend = extending)
lpi13 = line.new(bar_index[4999], pi13, bar_index, pi13, color = PrimeCol, width = 1, extend = extending)
lpi14 = line.new(bar_index[4999], pi14, bar_index, pi14, color = StdCol, width = 1, extend = extending)
lpi15 = line.new(bar_index[4999], pi15, bar_index, pi15, color = StdCol, width = 1, extend = extending)
lpi16 = line.new(bar_index[4999], pi16, bar_index, pi16, color = StdCol, width = 1, extend = extending)
lpi17 = line.new(bar_index[4999], pi17, bar_index, pi17, color = PrimeCol, width = 1, extend = extending)
lpi18 = line.new(bar_index[4999], pi18, bar_index, pi18, color = StdCol, width = 1, extend = extending)
lpi19 = line.new(bar_index[4999], pi19, bar_index, pi19, color = PrimeCol, width = 1, extend = extending)
lpi20 = line.new(bar_index[4999], pi20, bar_index, pi20, color = MultiCol, width = 1, extend = extending)
lpi21 = line.new(bar_index[4999], pi21, bar_index, pi21, color = StdCol, width = 1, extend = extending)
lpi22 = line.new(bar_index[4999], pi22, bar_index, pi22, color = StdCol, width = 1, extend = extending)
lpi23 = line.new(bar_index[4999], pi23, bar_index, pi23, color = PrimeCol, width = 1, extend = extending)
lpi24 = line.new(bar_index[4999], pi24, bar_index, pi24, color = StdCol, width = 1, extend = extending)
lpi25 = line.new(bar_index[4999], pi25, bar_index, pi25, color = StdCol, width = 1, extend = extending)
lpi26 = line.new(bar_index[4999], pi26, bar_index, pi26, color = StdCol, width = 1, extend = extending)
lpi27 = line.new(bar_index[4999], pi27, bar_index, pi27, color = PrimeCol, width = 1, extend = extending)
lpi28 = line.new(bar_index[4999], pi28, bar_index, pi28, color = StdCol, width = 1, extend = extending)
lpi29 = line.new(bar_index[4999], pi29, bar_index, pi29, color = PrimeCol, width = 1, extend = extending)
lpi30 = line.new(bar_index[4999], pi30, bar_index, pi30, color = MultiCol, width = 1, extend = extending)
lpi31 = line.new(bar_index[4999], pi31, bar_index, pi31, color = PrimeCol, width = 1, extend = extending)
lpi32 = line.new(bar_index[4999], pi32, bar_index, pi32, color = StdCol, width = 1, extend = extending)
lpi33 = line.new(bar_index[4999], pi33, bar_index, pi33, color = StdCol, width = 1, extend = extending)
lpi34 = line.new(bar_index[4999], pi34, bar_index, pi34, color = StdCol, width = 1, extend = extending)
lpi35 = line.new(bar_index[4999], pi35, bar_index, pi35, color = StdCol, width = 1, extend = extending)
lpi36 = line.new(bar_index[4999], pi36, bar_index, pi36, color = StdCol, width = 1, extend = extending)
lpi37 = line.new(bar_index[4999], pi37, bar_index, pi37, color = PrimeCol, width = 1, extend = extending)
lpi38 = line.new(bar_index[4999], pi38, bar_index, pi38, color = StdCol, width = 1, extend = extending)

//////