High low volatile
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NutnonZz

//@version=4
study("High low volatility v2.0" , overlay=false)

// Choose system and main timeframe
aaa = input(title="System", type=input.string, defval="Spread Data", options=["Spread Data","Mean reversion"])
CTF = input(true, title="Use Current TimeFrame?")
TF = input("D", type=input.resolution, title="TimeFrame",tooltip='Example you trade in 15min timeframe but you want data of 60min or daychart')

// for setting in multiple timeframe
final_TF = CTF? timeframe.period : TF
close_ = security(syminfo.tickerid, final_TF, close)
low_ = security(syminfo.tickerid, final_TF, low)
high_ = security(syminfo.tickerid, final_TF, high)
//

// Calculate different between High and low
HL = high_-low_

// For setting input EMA
INPUT_EMA1 = input(10,title='EMA_HL_short')
INPUT_EMA2 = input(200,title='EMA_HL_long')

// EMA
EMA1 = ema(HL,INPUT_EMA1)
EMA2 = ema(HL,INPUT_EMA2)


// For plotting
plot(aaa == "Spread Data" ? HL   : na , title='HL',color=color.teal ,style=plot.style_histogram ,linewidth=2)
plot(aaa == "Spread Data" ? EMA1 : na , title='EMA_HL_short',color=color.red,linewidth=2)
plot(aaa == "Spread Data" ? EMA2 : na , title='EMA_HL_long',color=color.orange ,linewidth=2)

////// system 2 mean reversion data

// type of different
bbb = input(title="Type of reversion", type=input.string, defval="dif_value", options=["dif_value","dif_value_color"])

// Main EMA reverse
INPUT_EMA_reverse = input(200,title='EMA_reversion')
EMA_reverse = ema(close,INPUT_EMA_reverse)

// Calculation
C = close
diff_ema = C - EMA_reverse
diff_ema2 = abs(C - EMA_reverse)

// Color dif
color_dif = diff_ema > 0 ? color.lime : color.red

// For plotting
plot(aaa == "Mean reversion" and bbb == "dif_value_color" ? diff_ema : na , color=color_dif ,style=plot.style_area ,linewidth=1)
plot(aaa == "Mean reversion" and bbb == "dif_value" ? diff_ema2 : na , color=color.teal ,style=plot.style_area ,linewidth=1)

