// ------------------------------------------------------
//PRC_Zone Shift [ChartPrime]
//version = 1
//06.11.2025
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
// ------------------------------------------------------
// inputs
// ------------------------------------------------------
per = 100 // Length 60-200 / minval = 60, maxval = 200
if per >200 then
length=200
elsif per <60 then
length=60
else
length=per
endif
colorCandles=1
atr=averagetruerange[14](close)
// ------------------------------------------------------
// Indicator calculations
// ------------------------------------------------------
once trend = 0
once trendStart = 0
once lastRetest = 0
ema= average[length,1](close)
hma= average[max(20,length-40),8](close)
dist=average[200](high-low)
mid = (ema+hma)/2
itop = mid+dist
ibot = mid-dist
if low > itop and low[1] < itop[1] and not trend then
trend=1
trendStart=low
r=0
g=255
b=0
endif
if high < ibot and high[1] > ibot[1] and trend then
trend=0
trendStart=high
r=255
g=0
b=0
endif
// Retest TrendStart Level
if (close > trendStart and close[1] < trendStart[1] or low > trendStart and low[1] <trendStart[1]) and trend and barindex-lastRetest>5 then
lastRetest=barindex
drawtext("⯁",barindex,low-0.2*atr)coloured("green",150)
endif
if (close[1]>trendStart and close<trendStart[1] or high[1]>trendStart and high<trendStart[1]) and not trend and barindex-lastRetest>5 then
lastRetest=barindex
drawtext("⯁",barindex,high+0.2*atr)coloured("red",150)
endif
// ------------------------------------------------------
// PLOT
// ------------------------------------------------------
if colorcandles then
drawcandle(open,high,low,close)coloured(r,g,b)
endif
// ------------------------------------------------------
return mid as "Middle"style(dottedline), itop as "Top" coloured("blue"), ibot as "Bottom"coloured("blue")