Aroon Oscillator [bkeevil]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bkeevil
// Purpose: to highlight short term trend changes.
// Reference: https://www.investopedia.com/terms/a/aroon.asp
//            https://www.investopedia.com/terms/a/aroonoscillator.asp
// @version=5
indicator(title="Aroon Oscillator [bkeevil]", shorttitle="Aroon Osc", overlay=false, precision=0, timeframe="", timeframe_gaps=true)

DEFAULT_LENGTH =  25    // Number of periods to consider
UPPER_LIMIT    =  50    // Upper range limit
LOWER_LIMIT    = -50    // Lower range limit

COLOR_BACKGROUND = color.new(color.teal,95)
COLOR_LIMIT      = color.new(color.teal,25)
COLOR_ZERO       = color.new(color.gray,33)
COLOR_OSCILLATOR = color.new(color.blue,50)
COLOR_DOWNTREND  = color.new(color.green,90)
COLOR_UPTREND    = color.new(color.red,90)

lengthInput = input.int(DEFAULT_LENGTH, title="Length", minval=1, tooltip="Number of periods to consider when searching for the last high/low. Default is 25")

// The number of periods since the last lengthInput period high
highest = 100 * (ta.highestbars(high, lengthInput) + lengthInput) / lengthInput
// The number of periods since the last lengthInput period low
lowest = 100 * (ta.lowestbars(low, lengthInput) + lengthInput) / lengthInput
// Oscillator is the difference between upper & lower
oscillator = highest - lowest

// fillColor indicates buy/sell conditions. Use background color if neither condition is present
fillColor = oscillator > UPPER_LIMIT ? COLOR_UPTREND : oscillator < LOWER_LIMIT ? COLOR_DOWNTREND : COLOR_BACKGROUND
    
// Paint the visuals
midlinePlot = hline(0,"Zero Line",COLOR_ZERO,hline.style_solid)
upperPlot = hline(UPPER_LIMIT,"Upper Limit",COLOR_LIMIT,hline.style_dotted)
lowerPlot = hline(LOWER_LIMIT,"Lower Limit",COLOR_LIMIT,hline.style_dotted)
fill(upperPlot,lowerPlot,fillColor,title="Background")
oscillatorPlot = plot(oscillator, "Value", color=COLOR_OSCILLATOR)