So I've been experimenting with the idea of tracking an indicator's range per bar and displaying that data as candles, (in my case WaveTrend, although the principle should apply to any calculation on close values), and have been able to achieve this on realtime bars using varip to track the WT output at bar open and it's high/low value but am unable to figure out how to use OHLC values to apply the same theory to historical bars.
Essentially I would like to display how much the WaveTrend calculation "wiggles" in each bar by using OHLC values.
//@version=5
indicator("My script")
WT(src,length,length2) =>
esa = ta.ema(src,length)
d = ta.stdev(src,length)
ci = ta.ema((src - esa) / d*100,length2)
WT = WT(close,3,5)
varip float test = na
if barstate.isrealtime and barstate.isnew
test := WT
testO = test
varip priceP = array.new_float ()
varip tt = 0
varip tC = 0
varip cl = WT
varip pcl = WT
tt += 1
testT = WT
if barstate.isnew
tt := 0
array.clear(priceP)
if ta.change(tt)
pcl := cl
cl := testT
array.unshift(priceP, cl)
liveH = array.max(priceP)
liveL = array.min(priceP)
bool live = array.size(priceP) > 0
plotcandle( testO , liveH , liveL , WT)
This code functions exactly as I want it to on realtime bars but I am struggling with converting this to work on historical bars as well. Any help would be greatly appreciated!