Correction Territory
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FX365_Thailand

//Revision History
    //v8.0 First release
    //v20.0 Enabled to select source to calculate correction rate
    
//@version=4
study("Correction Territory",overlay=false,shorttitle="Correction Territory")

//Users input
i_period = input(type=input.integer, title="Period", defval=20)
i_source = input(type=input.string,defval="low", options=["low","close"], title="Source")

//Get highest
h = highest(high,i_period)
source = i_source == "low" ? low : close

//Calcurate correction rate
rate = (source - h ) / h * 100

// Plot
a=plot(rate, color=color.red, title="Correction Rate",style=plot.style_area)

//high line
hline(-20, title="Hiline1")
hline(-30, title="Hiline2")
hline(-35, title="Hiline3")