TheATR: Aroon Oscillator.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thealgorithmictrader

//@version=5
indicator("TheATR: Aroon Oscillator.")

//User has to agree to have the indi loading on the chart.
//{
var user_consensus = input.string(defval="", title="By typing 'agree' you acknowledge the understanding about the fact 'TheATR: Aroon Oscillator.' doesn't aim and/or intend to provide any financial advice, as of its nature of being an educational tool.\n © TheATR", confirm = true, group="consensus")
var valid = false
if user_consensus == "agree"
    valid := true
else
    runtime.error("Type 'agree' first in order to show the algo!")
    valid := false
//}

//Fisher Oscillator Settings
//{
g_aroon = "Aroon Oscillator"

i_ar_sign = input.bool(true, "Entries",group=g_aroon,inline="ar0")
i_ar_exit_sign = input.bool(true, "Exits",group=g_aroon,inline="ar0")

i_ar_ws = input.bool(true, "Weak Spots Filter",group=g_aroon,inline="ar2")
i_ar_src = input.source(close, "|Src",group=g_aroon,inline="ar2")
i_ar_l = input.int(21, "Len",group=g_aroon,inline="ar2",minval=2)
i_ar_exit_l = input.float(50.0, "Exit Signal Line Level",group=g_aroon,inline="ar2",minval=5, maxval = 95)




g_aroon_sty = "Aroon Oscillator Style"

i_bull_col = input.color(color.blue, "Colors: Bull", group=g_aroon_sty, inline = "sty0")
i_bear_col = input.color(color.purple, "Bear", group=g_aroon_sty, inline = "sty0")
i_exit_col = input.color(color.yellow, "Exit Signal Line", group=g_aroon_sty, inline = "sty00")
i_ar_alerts = input.bool(true, "Alerts",group=g_aroon_sty,inline="sty1")
//}


//Aroon Oscillator Calculations And Plots
//{

aroon_up = 100* (ta.highestbars(i_ar_src, i_ar_l+1)+i_ar_l)/i_ar_l
aroon_dw = 100* (ta.lowestbars(i_ar_src, i_ar_l+1)+i_ar_l)/i_ar_l


plot(valid?aroon_up:na, "Aroon Up", aroon_up>aroon_dw? i_bull_col : color.new(i_bull_col,50),style=plot.style_columns)
plot(valid?aroon_dw:na, "Aroon Down", aroon_up<=aroon_dw? i_bear_col : color.new(i_bear_col,50),style=plot.style_columns)

hline(0, "0 Line", color.gray)
hline(100, "100 Line", color.gray)
hline(i_ar_exit_l, "Exit Signal Line", i_exit_col, editable = true, linestyle= hline.style_dashed)

//}

//Aroon Signals Generation
//{
    
var aroon_bull = false
var aroon_bear = false
var aroon_bull_exit = false
var aroon_bear_exit = false

var curr_dir = ""

aroon_bull  := ta.crossover(aroon_up, aroon_dw) and (i_ar_ws? aroon_up>i_ar_exit_l :true)
aroon_bear := ta.crossunder(aroon_up, aroon_dw) and (i_ar_ws? aroon_dw>i_ar_exit_l :true)

if aroon_bull
    curr_dir:="LONG"
if aroon_bear
    curr_dir:="SHORT"
    
aroon_bull_exit  := ta.crossunder(aroon_up, i_ar_exit_l) and curr_dir == "LONG" 
aroon_bear_exit := ta.crossunder(aroon_dw, i_ar_exit_l) and curr_dir == "SHORT"

//Aroon Signals Plots
plotshape(i_ar_sign and aroon_bull and valid, "Aroon Long Signals", shape.circle,location.bottom,i_bull_col,text="Long",textcolor=i_bull_col)
plotshape(i_ar_sign and aroon_bear and valid, "Aroon Short Signals", shape.circle,location.top,i_bear_col,text="Short",textcolor=i_bear_col)
//Aroon Exit Signals Plots
plotshape(i_ar_sign and i_ar_exit_sign and aroon_bull_exit and valid, "Aroon Long Exit Signals", shape.circle,location.bottom,i_bull_col,text="Exit Long",textcolor=i_bull_col)
plotshape(i_ar_sign and i_ar_exit_sign and aroon_bear_exit and valid, "Aroon Short Exit Signals", shape.circle,location.top,i_bear_col,text="Exit Short",textcolor=i_bear_col)


//Aroon Alerts
if i_ar_sign and aroon_bull and valid and i_ar_alerts
    alert("Aroon Long Alert")
if i_ar_sign and aroon_bear and valid and i_ar_alerts
    alert("Aroon Short Alert")
if i_ar_exit_sign and aroon_bull_exit and valid and i_ar_alerts
    alert("Aroon Exit Long Alert")
if i_ar_exit_sign and aroon_bear_exit and valid and i_ar_alerts
    alert("Aroon Exit Short Alert")
//}
