Dynamic Stochastic
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jacobfabris

//@version=5
indicator("Dynamic Stochastic",overlay=true)
//--- setting the periods of the stochatich and the levels
P1 = input.int(defval = 50)
P2 = input.int(defval = 200)
Superior_level = input(defval = 80)
Mid_level = input(defval = 50)
Inferior_level = input(defval = 20)
//---Number of Bars to show
NB1 = input.int(defval=10)*2
NB2 = input.int(defval=20)*2
//--- Calculating the Highs and Lows from each period.
H1 = ta.highest(high,P1)
L1 = ta.lowest(low,P1)
H2 = ta.highest(high,P2)
L2 = ta.lowest(low,P2)
//--- Calculating the levels
S1 = L1+(H1-L1)*Superior_level/100
I1 = L1+(H1-L1)*Inferior_level/100
M1 = L1+(H1-L1)*Mid_level/100
S2 = L2+(H2-L2)*Superior_level/100
I2 = L2+(H2-L2)*Inferior_level/100
M2 = L2+(H2-L2)*Mid_level/100
//---
P_S1 = line.new( bar_index+NB1/2 , S1 , bar_index - NB1/2 , S1 , xloc = xloc.bar_index , extend= extend.none,style = line.style_solid , color = color.green , width=1)
line.delete(P_S1[1])
P_L1 = line.new( bar_index+NB1/2 , I1 , bar_index - NB1/2 , I1 , xloc = xloc.bar_index , extend= extend.none,style = line.style_solid , color = color.green , width=1)
line.delete(P_L1[1])
P_S2 = line.new( bar_index+NB2/2 , S2 , bar_index - NB2/2 , S2 , xloc = xloc.bar_index , extend= extend.none,style = line.style_solid , color = color.orange , width=1)
line.delete(P_S2[1])
P_L2 = line.new( bar_index+NB2/2 , I2 , bar_index - NB2/2 , I2 , xloc = xloc.bar_index , extend= extend.none,style = line.style_solid , color = color.orange , width=1)
line.delete(P_L2[1])
P_M1 = line.new( bar_index+NB1/2 , M1 , bar_index - NB1/2 , M1 , xloc = xloc.bar_index , extend= extend.none,style = line.style_solid , color = color.white , width=1)
line.delete(P_M1[1])
P_M2 = line.new( bar_index+NB2/2 , M2 , bar_index - NB2/2 , M2 , xloc = xloc.bar_index , extend= extend.none,style = line.style_solid , color = color.gray , width=1)
line.delete(P_M2[1])
//---
plotshape(S1, style= shape.diamond, location = location.absolute , color = color.green, offset=NB1/2+1,text = "", show_last=1)
plotshape(S1, style= shape.diamond, location = location.absolute , color = color.green, offset=-NB1/2-1,text = "", show_last=1)
plotshape(I1, style= shape.diamond, location = location.absolute , color = color.green, offset=NB1/2+1,text = "", show_last=1)
plotshape(I1, style= shape.diamond, location = location.absolute , color = color.green, offset=-NB1/2-1,text = "", show_last=1)
//---
plotshape(S2, style= shape.diamond, location = location.absolute , color = color.orange, offset=NB2/2+1,text = "", show_last=1)
plotshape(S2, style= shape.diamond, location = location.absolute , color = color.orange, offset=-NB2/2-1,text = "", show_last=1)
plotshape(I2, style= shape.diamond, location = location.absolute , color = color.orange, offset=NB2/2+1,text = "", show_last=1)
plotshape(I2, style= shape.diamond, location = location.absolute , color = color.orange, offset=-NB2/2-1,text = "", show_last=1)
