This will hide an average within a certain distance from the chart's right edge should the condition be met. The average will still appear far off to the left, but if you pick a large enough number, you will have to scroll back to see it, and it shouldn't interfere visually with recent prices.
Its not perfect, but in regard to sethiding() not accepting ohlc data, and the typical work-arounds being laggy or forcibly invoking the once_per_bar throttle, I believe this would be the most efficient method.
If you don't want to wait to see the effect, flip the ">" sign back and forth.
input EdgeDistance = 200;
def EdgeCount =
if !EdgeCount[1] and isNaN(close[-EdgeDistance]) then 1
else if isNaN(close[-EdgeDistance]) then EdgeCount[1] + 1
else no
;
def EdgeRem = EdgeDistance - EdgeCount;
def SMA = SimpleMovingAvg(close,20);
def eSMA = GetValue(SMA,-EdgeRem);
def eCls = GetValue(Close,-EdgeRem);
plot x = if EdgeCount and eCls > eSMA then Double.NaN else SMA;
x.setpaintingStrategy(paintingStrategy.POINTS);
plot y = SMA;
Its not perfect, but in regard to sethiding() not accepting ohlc data, and the typical work-arounds being laggy or forcibly invoking the once_per_bar throttle, I believe this would be the most efficient method.
If you don't want to wait to see the effect, flip the ">" sign back and forth.
input EdgeDistance = 200;
def EdgeCount =
if !EdgeCount[1] and isNaN(close[-EdgeDistance]) then 1
else if isNaN(close[-EdgeDistance]) then EdgeCount[1] + 1
else no
;
def EdgeRem = EdgeDistance - EdgeCount;
def SMA = SimpleMovingAvg(close,20);
def eSMA = GetValue(SMA,-EdgeRem);
def eCls = GetValue(Close,-EdgeRem);
plot x = if EdgeCount and eCls > eSMA then Double.NaN else SMA;
x.setpaintingStrategy(paintingStrategy.POINTS);
plot y = SMA;