Thanks appreciate it. I actually figured it out myself. Now I'm trying to figure out if you can move the position of the bubbles more to the right because sometimes they get in the way. Sorry for all the commented out code, didn't really clean it out yet.Great code, really appreciate it. Is there a way to combine this with a Previous day High / Low / Close / and current day Open? Trying to use this intraday on 2/5min charts. Thanks.
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
#input displace = -1;
input displace_amount = {default zero, negative_one};
input ShowChartBubbles = yes;
def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;
def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];
def displacement;
switch (displace_amount) {
case zero:
displacement = 0;
case negative_one:
displacement = -1;
}
input showOnlyLastPeriod = yes;
plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;
if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
PrevDayOpen = Double.NaN;
PrevDayHigh = Double.NaN;
PrevDayLow = Double.NaN;
PrevDayClose = Double.NaN;
}
else
{
PrevDayOpen = Highest(open(period = aggregationPeriod)[displace_amount], length);
PrevDayHigh = Highest(high(period = aggregationPeriod)[displace_amount], length);
PrevDayLow = Highest(low(period = aggregationPeriod)[displace_amount], length);
PrevDayClose = Highest(close(period = aggregationPeriod)[displace_amount], length);
}
AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
PrevDayOpen,
"Prev Day Open",
Color.yellow,
1);
#PrevDayOpen.SetDefaultColor(Color.yellow);
#PrevDayOpen.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);
AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
PrevDayHigh,
"Prev Day High",
Color.green,
1);
#PrevDayHigh.SetDefaultColor(Color.green);
#PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);
AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
PrevDayLow,
"Prev Day Low",
Color.red,
1);
#PrevDayLow.SetDefaultColor(Color.red);
#PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);
AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
PrevDayClose,
"Prev Day Close",
Color.white,
1);
#PrevDayClose.SetDefaultColor(color.whITE);
#PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayClose.SetStyle(Curve.LONG_DASH);