#provide by Tonie Hock in thinkscript lounge
input symbol = "$TICK/Q";
input AggPeriodMin = 5;
#hidePricePlot();
def ChartAggMin = getAggregationPeriod() / 1000 / 60;
def multiplier = AggPeriodMin / ChartAggMin;
def x = barNumber();
def c = close(symbol);
def o = if x % multiplier == 0
then open(symbol)
else o[1];
def h = if x % multiplier == 0
then high(symbol)
else max(high(symbol), h[1]);
def l = if x % multiplier == 0
then low(symbol)
else min(low(symbol), l[1]);
def c1=if x%multiplier==0 and o<=c then c else double.nan;
def o1=if x%multiplier==0 and o<=c then o[1]+0 else double.nan;
def h1=if x%multiplier==0 and o<=c then max(h+0,h[1]+0) else double.nan;
def l1=if x%multiplier==0 and o<=c then min(l+0,l[1]+0) else double.nan;
addLabel(1, "Agg Min. = " + AggPeriodMin +
" Open = " + o +
" High = " + h +
" Low = " + l +
" Close = " + c +
" OHLC = " + ((o+h+l+c)/4), color.white);
addchart(h1,l1,o1,c1, type = charttype.candle,color.white);
def c2=if x%multiplier==0 and o>=c then c else double.nan;
def o2=if x%multiplier==0 and o>=c then o[1]+0 else double.nan;
def h2=if x%multiplier==0 and o>=c then max(h+0,h[1]+0) else double.nan;
def l2=if x%multiplier==0 and o>=c then min(l+0,l[1]+0) else double.nan;
addchart(h2,l2,o2,c2, type = charttype.candle,color.cyan);
plot zerobase = 0;