//------------------------------------------------------------------//
//PRC_TrendEnvelopes
//version = 0
//19.06.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//------------------------------------------------------------------//
//-----Inputs-------------------------------------------------------//
period=21
type=1
colorcandles=1
//------------------------------------------------------------------//
//-----Moving averages----------------------------------------------//
smax=average[period,type](high)
smin=average[period,type](low)
//------------------------------------------------------------------//
//-----Trend calculation--------------------------------------------//
once trend=undefined
if close > smax[1] then
trend=1
elsif close < smin[1] then
trend=-1
else
trend=trend
endif
//------------------------------------------------------------------//
//-----Trail calculation--------------------------------------------//
once mytrail=undefined
if trend>0 and smin < smin[1] then
smin=smin[1]
elsif trend<0 and smax > smax[1] then
smax=smax[1]
endif
if trend=1 then
mytrail=smin
r=0
g=255
b=0
if trend[1]<>1 then
drawpoint(barindex,mytrail,2)coloured("blue")
endif
elsif trend=-1 then
mytrail=smax
r=255
g=0
b=0
if trend[1]<>-1 then
drawpoint(barindex,mytrail,2)coloured("blue")
endif
endif
//------------------------------------------------------------------//
//-----Color Candles------------------------------------------------//
if colorcandles then
drawcandle(open,high,low,close)coloured(r,g,b)
endif
//------------------------------------------------------------------//
return mytrail coloured(r,g,b)style(line,2)