Dynamic_Retracement_Target
// 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_Retracement_Target",overlay=true)
//--- setting the periods
Period_fast = input.int(defval=34)
Period_medium = input.int(defval=144)
Period_slow = input.int(defval=610)
//--- setting the levels
Target_level_superior = input(defval=1.236)
Fib_level_sup = input(defval=0.764)
Fib_level_mid = input(defval=0.500)
Fib_level_inf = input(defval=0.236)
Target_level_inferior = input(defval=-0.236)
//--- calculating the almas
mf = ta.alma(close,Period_fast,0.786,3.236)
mm = ta.alma(close,Period_medium,0.786,3.236)
ms = ta.alma(close,Period_slow,0.786,3.236)
//--- the highest ema and lowest ema
highest_alma = math.max(mf,mm,ms)
lowest_alma = math.min(mf,mm,ms)
//--- Calculating the targets and the levels
A_level_superior = lowest_alma+(highest_alma - lowest_alma)*Target_level_superior
A_sup = highest_alma
A_level_sup = lowest_alma+(highest_alma - lowest_alma)*Fib_level_sup
A_level_mid = lowest_alma+(highest_alma - lowest_alma)*Fib_level_mid
A_level_inf = lowest_alma+(highest_alma - lowest_alma)*Fib_level_inf
A_inf = lowest_alma
A_level_inferior = lowest_alma+(highest_alma - lowest_alma)*Target_level_inferior
//--- plotting the averages
plot(A_level_superior,color=color.blue)
plot(A_sup,color=color.lime,linewidth=2)
plot(A_level_sup,color=color.green)
plot(A_level_mid,color=color.white,linewidth=2)
plot(A_level_inf,color=color.red)
plot(A_inf,color=color.orange,linewidth=2)
plot(A_level_inferior,color=color.blue)
//--- plotting identifications
plotshape(A_level_superior, style= shape.diamond, location = location.absolute , color = color.blue, offset=5,text = "TS", show_last= 1)
plotshape(A_sup, style= shape.diamond, location = location.absolute , color = color.lime, offset=5,text = "A_S", show_last= 1)
plotshape(A_level_sup, style= shape.diamond, location = location.absolute , color = color.green, offset=5,text = "L_sup", show_last= 1)
plotshape(A_level_mid, style= shape.diamond, location = location.absolute , color = color.white, offset=5,text = "L_mid", show_last= 1)
plotshape(A_level_inf, style= shape.diamond, location = location.absolute , color = color.red, offset=5,text = "L_inf", show_last= 1)
plotshape(A_inf, style= shape.diamond, location = location.absolute , color = color.yellow, offset=5,text = "A_I", show_last= 1)
plotshape(A_level_inferior, style= shape.diamond, location = location.absolute , color = color.blue, offset=5,text = "TI", show_last= 1)