## START STUDY
## Anchored_VWAP3
## linus, 2014-06-28, v0.3
## 20211117 Sleepyz modified to use a cond to anchor vwap
input ticks = 2;
input nhighlow = 5;
input hidegaps = yes;
#Cond defined-------------------------------------------------------------------
def prevdayhigh = high(period = AggregationPeriod.DAY)[1];
def prevdaylow = low(period = AggregationPeriod.DAY)[1];
def ema1 = expaverage(close, 8);
def ema2 = expaverage(close, 21);
def he = hasearnings();
def poc = reference VolumeProfile("time per profile" = "MONTH", "on expansion" = No, profiles = 1);
def cond =
he;
#ema1 crosses ema2;
#close crosses prevdayhigh;
#close crosses prevdaylow;
#close crosses poc;
#-------------------------------------------------------------------------------
def dir = cond;
def up = dir crosses above 0;
def dn = dir crosses below 0;
def h = if dir crosses 0 then Highest(high, nhighlow) else high;
def l = if dir crosses 0 then Lowest(low, nhighlow) else low;
def LocH = (h + (TickSize() * ticks)) * volume;
def LocL = (l - (TickSize() * ticks)) * volume;
def LocC = close * volume;
rec PC;
rec VC;
rec PC2;
rec VC2;
rec PH;
rec VH;
rec PL;
rec VL;
rec PH2;
rec VH2;
rec PL2;
rec VL2;
if dn or up {
PC = LocC;
VC = volume;
PC2 = PC[1];
VC2 = VC[1];
} else {
PC = CompoundValue(1, LocC + PC[1], Double.NaN);
VC = CompoundValue(1, volume + VC[1], Double.NaN);
PC2 = CompoundValue(1, LocC + PC2[1], Double.NaN);
VC2 = CompoundValue(1, volume + VC2[1], Double.NaN);
}
if dn {
PH = LocH;
VH = volume;
PH2 = PH[1];
VH2 = VH[1];
} else {
PH = CompoundValue(1, LocH + PH[1], Double.NaN);
VH = CompoundValue(1, volume + VH[1], Double.NaN);
PH2 = CompoundValue(1, LocH + PH2[1], Double.NaN);
VH2 = CompoundValue(1, volume + VH2[1], Double.NaN);
}
if up {
PL = LocL;
VL = volume;
PL2 = PL[1];
VL2 = VL[1];
} else {
PL = CompoundValue(1, LocL + PL[1], Double.NaN);
VL = CompoundValue(1, volume + VL[1], Double.NaN);
PL2 = CompoundValue(1, LocL + PL2[1], Double.NaN);
VL2 = CompoundValue(1, volume + VL2[1], Double.NaN);
}
plot VwapC;
plot VwapC2;
plot VwapH;
plot VwapL;
plot VwapH2;
plot VwapL2;
if hidegaps {
VwapC = if dn or up then Double.NaN else PC / VC;
VwapC2 = if dn or up then Double.NaN else PC2 / VC2;
VwapH = if dn then Double.NaN else PH / VH;
VwapL = if up then Double.NaN else PL / VL;
VwapH2 = if dn then Double.NaN else PH2 / VH2;
VwapL2 = if up then Double.NaN else PL2 / VL2;
} else {
VwapC = PC / VC;
VwapC2 = PC2 / VC2;
VwapH = PH / VH;
VwapL = PL / VL;
VwapH2 = PH2 / VH2;
VwapL2 = PL2 / VL2;
}
VwapC.SetDefaultColor(Color.YELLOW);
VwapC.SetLineWeight(2);
VwapC.HideBubble();
VwapC2.SetDefaultColor(Color.YELLOW);
VwapC2.SetLineWeight(2);
VwapC2.SetStyle(Curve.SHORT_DASH);
VwapC2.HideBubble();
VwapH.SetDefaultColor(Color.DARK_RED);
VwapH.HideBubble();
VwapL.SetDefaultColor(Color.DARK_GREEN);
VwapL.HideBubble();
VwapH2.SetDefaultColor(Color.DARK_RED);
VwapH2.SetStyle(Curve.SHORT_DASH);
VwapH2.HideBubble();
VwapL2.SetDefaultColor(Color.DARK_GREEN);
VwapL2.SetStyle(Curve.SHORT_DASH);
VwapL2.HideBubble();