input Percent = 100;
input Days = 40;
input Weeks = 8;
def iAgg =
getAggregationPeriod()
;
def iOffset =
if iAgg == aggregationPeriod.WEEK then Weeks
else if iAgg == aggregationPeriod.Day then Days
else 0
;
def bRange =
isNaN(close[-iOffset])
;
def bEdge =
bRange and !isNaN(close[-(iOffset - 1)])
;
def rTrackLow =
if bEdge then Low
else if bRange then Min(low,rTrackLow[1])
else Double.NaN
;
def dSeekLow =
if bEdge then GetValue(rTrackLow,-(iOffSet -1))
else if bRange then dSeekLow[1]
else Double.NaN;
;
def dBase =
if !bRange then Double.NaN
else if bEdge then dSeekLow
else dBase[1]
;
def dTop =
dBase + (dBase * (Percent / 100));
;
def bBreach =
if bRange and high > dTop then Yes else bBreach[1]
;
def dCloud =
dBase + 0
;
AddCloud(
dCloud,dTop,color.cyan
);
assignpriceColor(
if bBreach then color.cyan
else color.current
);
Plot Scan = bBreach and BarNumber() > iOffset and bRange;
Scan.hide();