//-----------------------------------------------------------//
//PRC_Donchian Volatility Indicator
//version = 0
//15.05.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//-----------------------------------------------------------//
//-----Inputs------------------------------------------------//
length=50//Lookback Period for Donchian Channel
atrPeriod=14//ATR Period
atrMultiplier=2.0//ATR Multiplier
lookbackPeriod=250//Lookback Period for Extremes
signalPeriod=50//Length of Signal Line
//-----------------------------------------------------------//
//-----Calculate ATR-----------------------------------------//
atr=averagetruerange[atrPeriod](close)
//-----------------------------------------------------------//
//-----Calculate Upper and Lower Channels--------------------//
upperChannel=highest[length](high)+atr*atrMultiplier
lowerChannel=lowest[length](low)-atr*atrMultiplier
//-----------------------------------------------------------//
//-----Calculate Channel Width-------------------------------//
channelWidth=upperChannel-lowerChannel
//-----------------------------------------------------------//
//-----Signal Line-------------------------------------------//
signalLine=average[signalPeriod](channelWidth)
//-----------------------------------------------------------//
//-----Bar Color---------------------------------------------//
if channelWidth>signalLine then
r=0
g=230
b=118
else
r=224
g=64
b=251
endif
//This piece of code works in price chart
//DRAWCANDLE(open, high, low, close) coloured(r,g,b)
//-----------------------------------------------------------//
//-----Background Color--------------------------------------//
BACKGROUNDCOLOR (r,g,b,30)
//-----------------------------------------------------------//
//-----Plotting----------------------------------------------//
return channelWidth as "Channel Width"coloured("maroon")style(line,4),signalLine as "Signal Line"coloured("aqua")style(line,4)