High/Low Anchored VWAP For ThinkOrSwim

JakeD

New member
Is it possible to create an Anchored VWAP script which automatically anchors at the charts High and/or Low ?
 
Is it possible to create an Anchored VWAP script which automatically anchors at the charts High and/or Low ?

This will plot the vwap from the highestall/lowestall high/low of the chart.

Capture.jpg
Ruby:
def bn          = BarNumber();
def c           = close;
def v           = volume;
def vw          = vwap;
def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

#Highest High of Chart
anchorh = if high == HighestAll(high)
             then bn else anchorh[1];

volumesumh      = if bn >= HighestAll(anchorh)  then volumesumh[1] + volume else 0;
volumevwapsumh  = if bn >= HighestAll(anchorh)  then volumevwapsumh[1] + volume * vwap else 0;
volumevwap2sumh = if bn >= HighestAll(anchorh)  then volumevwap2sumh[1] + volume * Sqr(vwap) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));


plot VWAPh      = priceh;
VWAPh.SetDefaultColor(GetColor(0));

input showbands = yes;
input numDev1  = 1.0;
input numDev2  = 2.0;
input numDev3  = 3.0;

plot UpperBand1  = if !showbands then Double.NaN else vwaph + numDev1 * deviationh;
plot LowerBand1  = if !showbands then Double.NaN else vwaph - numDev1 * deviationh;
plot UpperBand2  = if !showbands then Double.NaN else vwaph + numDev2 * deviationh;
plot LowerBand2  = if !showbands then Double.NaN else vwaph - numDev2 * deviationh;
plot UpperBand3  = if !showbands then Double.NaN else vwaph + numDev3 * deviationh;
plot LowerBand3  = if !showbands then Double.NaN else vwaph - numDev3 * deviationh;

vwaph.SetDefaultColor(Color.CYAN);
UpperBand1.SetDefaultColor(Color.GREEN);
LowerBand1.SetDefaultColor(Color.RED);
UpperBand2.SetDefaultColor(Color.GREEN);
LowerBand2.SetDefaultColor(Color.RED);
UpperBand3.SetDefaultColor(Color.GREEN);
LowerBand3.SetDefaultColor(Color.RED);
vwaph.HideBubble();
UpperBand1.HideBubble();
LowerBand1.HideBubble();
UpperBand2.HideBubble();
LowerBand2.HideBubble();
UpperBand3.HideBubble();
LowerBand3.HideBubble();

input showclouds = yes;
AddCloud(if showclouds then UpperBand3 else Double.NaN, UpperBand2, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand3 else Double.NaN, LowerBand2, Color.LIGHT_RED, Color.LIGHT_RED);

#Lowest Low of Chart
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if low == LowestAll(low)
         then bn else anchor1[1];
volumesum1      = if bn >= HighestAll(anchor1)  then volumesum1[1] + volume else 0;
volumevwapsum1  = if bn >= HighestAll(anchor1)  then volumevwapsum1[1] + volume * vwap else 0;
volumevwap2sum1 = if bn >= HighestAll(anchor1)  then volumevwap2sum1[1] + volume * Sqr(vwap) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));


plot VWAP1      = price1;
VWAP1.SetDefaultColor(GetColor(0));

plot UpperBand11  = if !showbands then Double.NaN else VWAP1 + numDev1 * deviation1;
plot LowerBand11  = if !showbands then Double.NaN else VWAP1 - numDev1 * deviation1;
plot UpperBand21  = if !showbands then Double.NaN else VWAP1 + numDev2 * deviation1;
plot LowerBand21  = if !showbands then Double.NaN else VWAP1 - numDev2 * deviation1;
plot UpperBand31  = if !showbands then Double.NaN else VWAP1 + numDev3 * deviation1;
plot LowerBand31  = if !showbands then Double.NaN else VWAP1 - numDev3 * deviation1;

VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(Color.GREEN);
LowerBand11.SetDefaultColor(Color.RED);
UpperBand21.SetDefaultColor(Color.GREEN);
LowerBand21.SetDefaultColor(Color.RED);
UpperBand31.SetDefaultColor(Color.GREEN);
LowerBand31.SetDefaultColor(Color.RED);
VWAP1.HideBubble();
UpperBand11.HideBubble();
LowerBand11.HideBubble();
UpperBand21.HideBubble();
LowerBand21.HideBubble();
UpperBand31.HideBubble();
LowerBand31.HideBubble();


AddCloud(if showclouds then UpperBand31 else Double.NaN, UpperBand21, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand31 else Double.NaN, LowerBand21, Color.LIGHT_RED, Color.LIGHT_RED);
 
Intraday ONLY --see my next post for higher timeframes
I just modified the code to show automated anchored VWAP based on the selected number of days. if select "0" days, will anchor the max high/low within the aggregation period. More over, I included options to show pervious HL, OC, premarket...etc.

haI2Bka.png



CSS:
# Auto Anchored VWAP based on high/low with the Anchored period
# Sam4Cok@Samer800 - 10/2022

declare upper;
declare hide_on_daily;

input ShowLabel = yes;
input DaysAgo   = 4;        # hint DaysAgo: Excludes today
input AnchorHigh  = yes;
input AnchorLow   = yes;
input DailyOpenRange = no;
input ORBegin = 0900;
input OREnd   = 0925;
input DailyOpen   = no;
input PreMarketHL = no;
input PreviousHL  = no;
input PreviousOC  = no;
input ShowTodayOnly = yes;
input showband1   = no;
input showband2   = no;
input showclouds  = yes;
input numDev1     = 1.0;
input numDev2     = 2.0;

def na = Double.NaN;
def bar = BarNumber();

def AdjDaysAgo = DaysAgo + 1; # Adjusted to match a true LastDate which includes today
def day = GetDay();
def lastDay = GetLastDay();
def year = GetYear();
def lastYear = GetLastYear();
def yyyymmdd = GetYYYYMMDD();
def lastDate = HighestAll( if day == lastDay and year == lastYear then yyyymmdd else na );
def currentDate = if yyyymmdd < lastDate then yyyymmdd else lastDate;
def tradingDaysAgo = CountTradingDays(currentDate, lastDate);
def previousDayPlus = tradingDaysAgo <= AdjDaysAgo;
def today = lastDate == currentDate;

def RTH =  SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0;
def todayOnly = if !ShowTodayOnly or day == lastDay then 1 else 0;

def src = hlc3;
def vw  = vwap;
def o   = open;
def h   = high;
def l   = low;
def c   = close;
def v   = volume;
def Dayhigh  = high(period = "DAY");
def DayLow   = low(period = "DAY");
def DayClose = close(period = "DAY");
def DayOpen  = open(period = "DAY");

#### Support Resistance

########## Previous day High/Low Open/Close
#previousPlot(today, Condistion, source)=>
script previousPlot {
    input today = yes;
    input previousDayPlus = yes;
    input data = high;
    plot previousPlot = if previousDayPlus then
                    HighestAll(if today then data else Double.NaN)
                    else Double.NaN;
}
def pHigh  = previousPlot(today, PreviousHL and previousDayPlus, Dayhigh[DaysAgo]);
def pLow   = previousPlot(today, PreviousHL and previousDayPlus, DayLow[DaysAgo]);
def pClose = previousPlot(today, PreviousOC and previousDayPlus, DayClose[DaysAgo]);
def pOpen  = previousPlot(today, PreviousOC and previousDayPlus, DayOpen[DaysAgo]);

plot previousHigh  = If(IsNaN(c), na, pHigh);
plot PreviousLow   = If(IsNaN(c), na, pLow);
plot PreviousClose = If(IsNaN(c), na, pClose);
plot PreviousOpen  = If(IsNaN(c), na, pOpen);

previousHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousHigh.SetDefaultColor(Color.GREEN);

PreviousLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PreviousLow.SetDefaultColor(Color.RED);

PreviousClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PreviousClose.SetDefaultColor(Color.ORANGE);

PreviousOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PreviousOpen.SetDefaultColor(Color.GRAY);

#=========== Pre/After Market ===================

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());

def vol = if GlobeX and !GlobeX[1] then v else
          if GlobeX then vol[1] + v else na;

def GlobeX_Volume = vol;

def ONhigh = if GlobeX and !GlobeX[1] then h else
             if GlobeX and h > ONhigh[1] then h else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh then bar else na;

def ONlow = if GlobeX and !GlobeX[1] then l else
            if GlobeX and l < ONlow[1] then l else ONlow[1];

def ONlowBar = if GlobeX and l == ONlow then bar else na;

def OverNightHigh = if bar == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];

def OverNightLow = if bar == HighestAll(ONlowBar) then ONlow else OverNightLow[1];

#
plot PreHigh = if OverNightHigh and PreMarketHL then If(IsNaN(c), na, OverNightHigh) else na;

PreHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PreHigh.SetDefaultColor(Color.LIGHT_GREEN);

#
plot PreLow = if OverNightLow and PreMarketHL then If(IsNaN(c), na, OverNightLow) else na;

PreLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PreLow.SetDefaultColor(Color.LIGHT_RED);

# Daily Open High/Low

plot PlotDailyOpen = if RTH and todayOnly then DayOpen else na;
PlotDailyOpen.SetHiding(!DailyOpen);
PlotDailyOpen.SetDefaultColor(Color.WHITE);
PlotDailyOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

################# premarket average ====

def ORActive = if SecondsTillTime(OREnd) >= 0 and SecondsFromTime(ORBegin) >= 0 then 1 else 0;

def SMAH = SimpleMovingAvg(h, 3);
def SMAM = SimpleMovingAvg(src,3);
def SMAL = SimpleMovingAvg(l, 3);

rec ORH = if !ORH[1] or !ORActive[1] and ORActive then SMAH else
          if ORActive and SMAH > ORH[1] then SMAH else ORH[1];
rec ORM = if !ORM[1] or !ORActive[1] and ORActive then SMAM else
          if ORActive and SMAM > ORM[1] then SMAM else ORM[1];
rec ORL = if !ORL[1] or !ORActive[1] and ORActive then SMAL else
          if ORActive and SMAL > ORL[1] then SMAL else ORL[1];

plot ORMedLine = if RTH and todayOnly then if(DailyOpenRange,ORM,na) else na;
def ORHHigh    = if RTH and todayOnly then ORH else na;
def ORHLow     = if RTH and todayOnly then ORL else na;

AddCloud(if DailyOpenRange then ORHHigh else na, ORHLow, Color.GRAY);
ORMedLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORMedLine.SetDefaultColor(Color.CYAN);
ORMedLine.SetStyle(Curve.SHORT_DASH);

#--Anchored VWAP-----------------------
def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

def vHigh  = if DaysAgo <= 0 then HighestAll(h) else
             HighestAll(If(previousDayPlus and !today, h[DaysAgo], na));
def vLow   = if DaysAgo <= 0 then LowestAll(l) else
             LowestAll(If(previousDayPlus and !today, l[DaysAgo + 1], na));
#Highest High of Chart
anchorh = if h == vHigh then bar else anchorh[1];

volumesumh      = if bar >= HighestAll(anchorh)  then volumesumh[1] + v else 0;
volumevwapsumh  = if bar >= HighestAll(anchorh)  then volumevwapsumh[1] + v * vw else 0;
volumevwap2sumh = if bar >= HighestAll(anchorh)  then volumevwap2sumh[1] + v * Sqr(vw) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));

plot VWAPh      = if(AnchorHigh,priceh,na);
VWAPh.SetDefaultColor(Color.LIME);
def UpBand1  = VWAPh + numDev1 * deviationh;
def LoBand1  = VWAPh - numDev1 * deviationh;
def UpBand2  = VWAPh + numDev2 * deviationh;
def LoBand2  = VWAPh - numDev2 * deviationh;

plot UpperBand1  = if !showband1 then na else UpBand1;
plot LowerBand1  = if !showband1 then na else LoBand1;
plot UpperBand2  = if !showband2 then na else UpBand2;
plot LowerBand2  = if !showband2 then na else LoBand2;

UpperBand1.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand1.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand2.SetDefaultColor(Color.DARK_GREEN);
LowerBand2.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand2 else na, UpBand1, CreateColor(15, 51, 37), CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand2 else na, LoBand1, CreateColor(65, 0, 0), CreateColor(65, 0, 0));

#Lowest Low of Chart
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if l == vLow then bar else anchor1[1];
volumesum1      = if bar >= HighestAll(anchor1) then volumesum1[1] + v else 0;
volumevwapsum1  = if bar >= HighestAll(anchor1) then volumevwapsum1[1] + v * vw else 0;
volumevwap2sum1 = if bar >= HighestAll(anchor1) then volumevwap2sum1[1] + v * Sqr(vw) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));

plot VWAP1      = if(AnchorLow,price1,na);
VWAP1.SetDefaultColor(Color.PINK);

def UpBand11  = VWAP1 + numDev1 * deviation1;
def LoBand11  = VWAP1 - numDev1 * deviation1;
def UpBand21  = VWAP1 + numDev2 * deviation1;
def LoBand21  = VWAP1 - numDev2 * deviation1;

plot UpperBand11  = if !showband1 then na else UpBand11;
plot LowerBand11  = if !showband1 then na else LoBand11;
plot UpperBand21  = if !showband2 then na else UpBand21;
plot LowerBand21  = if !showband2 then na else LoBand21;

#VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand11.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand21.SetDefaultColor(Color.DARK_GREEN);
LowerBand21.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand21 else na, UpBand11, CreateColor(15, 51, 37), CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand21 else na, LoBand11, CreateColor(65, 0, 0), CreateColor(65, 0, 0));

AddLabel(ShowLabel, "Anchor days(" + DaysAgo + ")", Color.WHITE);

#---- End Code
 
Last edited by a moderator:
Thank you for the code. I've been able to get the plots to appear on intraday charts but not on daily or weekly charts.
I tried specifying 130 days ago
Are there specific parameters that would place the plots on daily/weekly charts?
Does the hide_on_daily variable somehow specifically exclude daily/weekly plots? (I didn't see it referenced anywhere in the code after its def statment.)
 
I've been able to get the plots to appear on intraday charts but not on daily or weekly charts.
above code for intraday and can't be used for daily aggregation. use below code if you want to use for any time frame but will be auomated based on highest price and lowest price.

CSS:
#AutoAnchored VWAP based on High/low
# Created by Sam4Cok@Samer800 - 10/2022
#--Anchored VWAP-----------------------
input AnchorHigh = yes;
input AnchorLow = yes;
input numDev1     = 1.0;
input numDev2     = 2.0;
input showclouds = no;
input showband1 = no;
input showband2 = no;

def na = Double.NaN;
def bar = BarNumber();

def vw  = vwap;
def o   = open;
def h   = high;
def l   = low;
def c   = close;
def v   = volume;

def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

def vHigh  = HighestAll(h);
def vLow   = LowestAll(l);
#Highest High of Chart
anchorh = if h == vHigh then bar else anchorh[1];

volumesumh      = if bar >= HighestAll(anchorh)  then volumesumh[1] + v else 0;
volumevwapsumh  = if bar >= HighestAll(anchorh)  then volumevwapsumh[1] + v * vw else 0;
volumevwap2sumh = if bar >= HighestAll(anchorh)  then volumevwap2sumh[1] + v * Sqr(vw) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));

plot VWAPh      = If(AnchorHigh, priceh, na);
VWAPh.SetDefaultColor(Color.LIME);
def UpBand1  = VWAPh + numDev1 * deviationh;
def LoBand1  = VWAPh - numDev1 * deviationh;
def UpBand2  = VWAPh + numDev2 * deviationh;
def LoBand2  = VWAPh - numDev2 * deviationh;

plot UpperBand1  = if !showband1 then na else UpBand1;
plot LowerBand1  = if !showband1 then na else LoBand1;
plot UpperBand2  = if !showband2 then na else UpBand2;
plot LowerBand2  = if !showband2 then na else LoBand2;

UpperBand1.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand1.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand2.SetDefaultColor(Color.DARK_GREEN);
LowerBand2.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand2 else na,   UpBand1,   CreateColor(15, 51, 37),   CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand2 else na,   LoBand1,   CreateColor(65, 0, 0),   CreateColor(65, 0, 0));

#Lowest Low of Chart
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if l == vLow then bar else anchor1[1];
volumesum1      = if bar >= HighestAll(anchor1) then volumesum1[1] + v else 0;
volumevwapsum1  = if bar >= HighestAll(anchor1) then volumevwapsum1[1] + v * vw else 0;
volumevwap2sum1 = if bar >= HighestAll(anchor1) then volumevwap2sum1[1] + v * Sqr(vw) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));

plot VWAP1      = If(AnchorLow, price1, na);
VWAP1.SetDefaultColor(Color.PINK);

def UpBand11  = VWAP1 + numDev1 * deviation1;
def LoBand11  = VWAP1 - numDev1 * deviation1;
def UpBand21  = VWAP1 + numDev2 * deviation1;
def LoBand21  = VWAP1 - numDev2 * deviation1;

plot UpperBand11  = if !showband1 then na else UpBand11;
plot LowerBand11  = if !showband1 then na else LoBand11;
plot UpperBand21  = if !showband2 then na else UpBand21;
plot LowerBand21  = if !showband2 then na else LoBand21;

#VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand11.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand21.SetDefaultColor(Color.DARK_GREEN);
LowerBand21.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand21 else na,   UpBand11,   CreateColor(15, 51, 37),   CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand21 else na,   LoBand11,   CreateColor(65, 0, 0),   CreateColor(65, 0, 0));

#---END CODE
 
Last edited by a moderator:
@samer800 Is it possible to auto-anchor to each pivot high and low? Maybe including an (x) amount of plots for the day?
try this but it may repaint based on the change of the pivot high/low.

CSS:
#AutoAnchored VWAP based on High/low
# Created by Sam4Cok@Samer800 - 10/2022
#--Anchored VWAP-----------------------
input AnchorHigh = yes;
input AnchorLow = yes;
input rightBars   = 5;
input leftBars    = 5;
input numDev1     = 1.0;
input numDev2     = 2.0;
input showclouds = no;
input showband1 = no;
input showband2 = no;

def na = Double.NaN;
def bar = BarNumber();

def vw  = vwap;
def o   = open;
def h   = high;
def l   = low;
def c   = close;
def v   = volume;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def ph =  findpivots(h, 1, leftBars, rightBars);
def pl =  findpivots(l, -1, leftBars, rightBars);

def ph_1 = if !IsNaN(ph) then ph else ph_1[1];
def pl_1 = if !IsNaN(pl) then pl else pl_1[1];
def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

def vHigh  = HighestAll(ph_1);
def vLow   = LowestAll(pl_1);
#Highest High of Chart
anchorh = if h == vHigh then bar else anchorh[1];

volumesumh      = if bar >= HighestAll(anchorh)  then volumesumh[1] + v else 0;
volumevwapsumh  = if bar >= HighestAll(anchorh)  then volumevwapsumh[1] + v * vw else 0;
volumevwap2sumh = if bar >= HighestAll(anchorh)  then volumevwap2sumh[1] + v * Sqr(vw) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));

plot VWAPh      = If(AnchorHigh, priceh, na);
VWAPh.SetDefaultColor(Color.LIME);
def UpBand1  = VWAPh + numDev1 * deviationh;
def LoBand1  = VWAPh - numDev1 * deviationh;
def UpBand2  = VWAPh + numDev2 * deviationh;
def LoBand2  = VWAPh - numDev2 * deviationh;

plot UpperBand1  = if !showband1 then na else UpBand1;
plot LowerBand1  = if !showband1 then na else LoBand1;
plot UpperBand2  = if !showband2 then na else UpBand2;
plot LowerBand2  = if !showband2 then na else LoBand2;

UpperBand1.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand1.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand2.SetDefaultColor(Color.DARK_GREEN);
LowerBand2.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand2 else na,   UpBand1,   CreateColor(15, 51, 37),   CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand2 else na,   LoBand1,   CreateColor(65, 0, 0),   CreateColor(65, 0, 0));

#Lowest Low of Chart
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if l == vLow then bar else anchor1[1];
volumesum1      = if bar >= HighestAll(anchor1) then volumesum1[1] + v else 0;
volumevwapsum1  = if bar >= HighestAll(anchor1) then volumevwapsum1[1] + v * vw else 0;
volumevwap2sum1 = if bar >= HighestAll(anchor1) then volumevwap2sum1[1] + v * Sqr(vw) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));

plot VWAP1      = If(AnchorLow, price1, na);
VWAP1.SetDefaultColor(Color.PINK);

def UpBand11  = VWAP1 + numDev1 * deviation1;
def LoBand11  = VWAP1 - numDev1 * deviation1;
def UpBand21  = VWAP1 + numDev2 * deviation1;
def LoBand21  = VWAP1 - numDev2 * deviation1;

plot UpperBand11  = if !showband1 then na else UpBand11;
plot LowerBand11  = if !showband1 then na else LoBand11;
plot UpperBand21  = if !showband2 then na else UpBand21;
plot LowerBand21  = if !showband2 then na else LoBand21;

#VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand11.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand21.SetDefaultColor(Color.DARK_GREEN);
LowerBand21.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand21 else na,   UpBand11,   CreateColor(15, 51, 37),   CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand21 else na,   LoBand11,   CreateColor(65, 0, 0),   CreateColor(65, 0, 0));

#---END CODE
 
How can i anchor vwap to last week high and last week low ?

This should display 2 vwaps, one anchored to last week's high and one anchored to last week's low.

Screenshot 2023-09-26 072618.png
Code:
#Anchored_VWAP_LastWEEKs_High_Low

def bn          = BarNumber();
def c           = close;
def v           = volume;
def vw          = vwap;
def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

#Last Week's High
anchorh = if GetWeek() == GetLastWeek() - 1 and high == high(period = AggregationPeriod.WEEK)
             then bn else anchorh[1];

volumesumh      = if bn >= HighestAll(anchorh)  then volumesumh[1] + volume else 0;
volumevwapsumh  = if bn >= HighestAll(anchorh)  then volumevwapsumh[1] + volume * vwap else 0;
volumevwap2sumh = if bn >= HighestAll(anchorh)  then volumevwap2sumh[1] + volume * Sqr(vwap) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));


plot VWAPh      = priceh;
VWAPh.SetDefaultColor(GetColor(0));

input showbands = yes;
input numDev1  = 1.0;
input numDev2  = 2.0;
input numDev3  = 3.0;

plot UpperBand1  = if !showbands then Double.NaN else VWAPh + numDev1 * deviationh;
plot LowerBand1  = if !showbands then Double.NaN else VWAPh - numDev1 * deviationh;
plot UpperBand2  = if !showbands then Double.NaN else VWAPh + numDev2 * deviationh;
plot LowerBand2  = if !showbands then Double.NaN else VWAPh - numDev2 * deviationh;
plot UpperBand3  = if !showbands then Double.NaN else VWAPh + numDev3 * deviationh;
plot LowerBand3  = if !showbands then Double.NaN else VWAPh - numDev3 * deviationh;

VWAPh.SetDefaultColor(Color.CYAN);
UpperBand1.SetDefaultColor(Color.GREEN);
LowerBand1.SetDefaultColor(Color.RED);
UpperBand2.SetDefaultColor(Color.GREEN);
LowerBand2.SetDefaultColor(Color.RED);
UpperBand3.SetDefaultColor(Color.GREEN);
LowerBand3.SetDefaultColor(Color.RED);
VWAPh.HideBubble();
UpperBand1.HideBubble();
LowerBand1.HideBubble();
UpperBand2.HideBubble();
LowerBand2.HideBubble();
UpperBand3.HideBubble();
LowerBand3.HideBubble();

input showclouds = yes;
AddCloud(if showclouds then UpperBand3 else Double.NaN, UpperBand2, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand3 else Double.NaN, LowerBand2, Color.LIGHT_RED, Color.LIGHT_RED);

#Last Week's Low
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if GetWeek() == GetLastWeek() - 1 and low == low(period = AggregationPeriod.WEEK)
         then bn else anchor1[1];
volumesum1      = if bn >= HighestAll(anchor1)  then volumesum1[1] + volume else 0;
volumevwapsum1  = if bn >= HighestAll(anchor1)  then volumevwapsum1[1] + volume * vwap else 0;
volumevwap2sum1 = if bn >= HighestAll(anchor1)  then volumevwap2sum1[1] + volume * Sqr(vwap) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));

plot VWAP1      = price1;
VWAP1.SetDefaultColor(GetColor(0));

plot UpperBand11  = if !showbands then Double.NaN else VWAP1 + numDev1 * deviation1;
plot LowerBand11  = if !showbands then Double.NaN else VWAP1 - numDev1 * deviation1;
plot UpperBand21  = if !showbands then Double.NaN else VWAP1 + numDev2 * deviation1;
plot LowerBand21  = if !showbands then Double.NaN else VWAP1 - numDev2 * deviation1;
plot UpperBand31  = if !showbands then Double.NaN else VWAP1 + numDev3 * deviation1;
plot LowerBand31  = if !showbands then Double.NaN else VWAP1 - numDev3 * deviation1;

VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(Color.GREEN);
LowerBand11.SetDefaultColor(Color.RED);
UpperBand21.SetDefaultColor(Color.GREEN);
LowerBand21.SetDefaultColor(Color.RED);
UpperBand31.SetDefaultColor(Color.GREEN);
LowerBand31.SetDefaultColor(Color.RED);
VWAP1.HideBubble();
UpperBand11.HideBubble();
LowerBand11.HideBubble();
UpperBand21.HideBubble();
LowerBand21.HideBubble();
UpperBand31.HideBubble();
LowerBand31.HideBubble();


AddCloud(if showclouds then UpperBand31 else Double.NaN, UpperBand21, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand31 else Double.NaN, LowerBand21, Color.LIGHT_RED, Color.LIGHT_RED);

#
 
I just modified the code to show automated anchored VWAP based on the selected number of days. if select "0" days, will anchor the max high/low within the aggregation period. More over, I included options to show pervious HL, OC, premarket...etc.

View attachment 16193


CSS:
# Auto Anchored VWAP based on high/low with the Anchored period
# Sam4Cok@Samer800 - 10/2022

declare upper;
declare hide_on_daily;

input ShowLabel = yes;
input DaysAgo   = 4;        # hint DaysAgo: Excludes today
input AnchorHigh  = yes;
input AnchorLow   = yes;
input DailyOpenRange = no;
input ORBegin = 0900;
input OREnd   = 0925;
input DailyOpen   = no;
input PreMarketHL = no;
input PreviousHL  = no;
input PreviousOC  = no;
input ShowTodayOnly = yes;
input showband1   = no;
input showband2   = no;
input showclouds  = yes;
input numDev1     = 1.0;
input numDev2     = 2.0;

def na = Double.NaN;
def bar = BarNumber();

def AdjDaysAgo = DaysAgo + 1; # Adjusted to match a true LastDate which includes today
def day = GetDay();
def lastDay = GetLastDay();
def year = GetYear();
def lastYear = GetLastYear();
def yyyymmdd = GetYYYYMMDD();
def lastDate = HighestAll( if day == lastDay and year == lastYear then yyyymmdd else na );
def currentDate = if yyyymmdd < lastDate then yyyymmdd else lastDate;
def tradingDaysAgo = CountTradingDays(currentDate, lastDate);
def previousDayPlus = tradingDaysAgo <= AdjDaysAgo;
def today = lastDate == currentDate;

def RTH =  SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0;
def todayOnly = if !ShowTodayOnly or day == lastDay then 1 else 0;

def src = hlc3;
def vw  = vwap;
def o   = open;
def h   = high;
def l   = low;
def c   = close;
def v   = volume;
def Dayhigh  = high(period = "DAY");
def DayLow   = low(period = "DAY");
def DayClose = close(period = "DAY");
def DayOpen  = open(period = "DAY");

#### Support Resistance

########## Previous day High/Low Open/Close
#previousPlot(today, Condistion, source)=>
script previousPlot {
    input today = yes;
    input previousDayPlus = yes;
    input data = high;
    plot previousPlot = if previousDayPlus then
                    HighestAll(if today then data else Double.NaN)
                    else Double.NaN;
}
def pHigh  = previousPlot(today, PreviousHL and previousDayPlus, Dayhigh[DaysAgo]);
def pLow   = previousPlot(today, PreviousHL and previousDayPlus, DayLow[DaysAgo]);
def pClose = previousPlot(today, PreviousOC and previousDayPlus, DayClose[DaysAgo]);
def pOpen  = previousPlot(today, PreviousOC and previousDayPlus, DayOpen[DaysAgo]);

plot previousHigh  = If(IsNaN(c), na, pHigh);
plot PreviousLow   = If(IsNaN(c), na, pLow);
plot PreviousClose = If(IsNaN(c), na, pClose);
plot PreviousOpen  = If(IsNaN(c), na, pOpen);

previousHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousHigh.SetDefaultColor(Color.GREEN);

PreviousLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PreviousLow.SetDefaultColor(Color.RED);

PreviousClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PreviousClose.SetDefaultColor(Color.ORANGE);

PreviousOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PreviousOpen.SetDefaultColor(Color.GRAY);

#=========== Pre/After Market ===================

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());

def vol = if GlobeX and !GlobeX[1] then v else
          if GlobeX then vol[1] + v else na;

def GlobeX_Volume = vol;

def ONhigh = if GlobeX and !GlobeX[1] then h else
             if GlobeX and h > ONhigh[1] then h else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh then bar else na;

def ONlow = if GlobeX and !GlobeX[1] then l else
            if GlobeX and l < ONlow[1] then l else ONlow[1];

def ONlowBar = if GlobeX and l == ONlow then bar else na;

def OverNightHigh = if bar == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];

def OverNightLow = if bar == HighestAll(ONlowBar) then ONlow else OverNightLow[1];

#
plot PreHigh = if OverNightHigh and PreMarketHL then If(IsNaN(c), na, OverNightHigh) else na;

PreHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PreHigh.SetDefaultColor(Color.LIGHT_GREEN);

#
plot PreLow = if OverNightLow and PreMarketHL then If(IsNaN(c), na, OverNightLow) else na;

PreLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PreLow.SetDefaultColor(Color.LIGHT_RED);

# Daily Open High/Low

plot PlotDailyOpen = if RTH and todayOnly then DayOpen else na;
PlotDailyOpen.SetHiding(!DailyOpen);
PlotDailyOpen.SetDefaultColor(Color.WHITE);
PlotDailyOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

################# premarket average ====

def ORActive = if SecondsTillTime(OREnd) >= 0 and SecondsFromTime(ORBegin) >= 0 then 1 else 0;

def SMAH = SimpleMovingAvg(h, 3);
def SMAM = SimpleMovingAvg(src,3);
def SMAL = SimpleMovingAvg(l, 3);

rec ORH = if !ORH[1] or !ORActive[1] and ORActive then SMAH else
          if ORActive and SMAH > ORH[1] then SMAH else ORH[1];
rec ORM = if !ORM[1] or !ORActive[1] and ORActive then SMAM else
          if ORActive and SMAM > ORM[1] then SMAM else ORM[1];
rec ORL = if !ORL[1] or !ORActive[1] and ORActive then SMAL else
          if ORActive and SMAL > ORL[1] then SMAL else ORL[1];

plot ORMedLine = if RTH and todayOnly then if(DailyOpenRange,ORM,na) else na;
def ORHHigh    = if RTH and todayOnly then ORH else na;
def ORHLow     = if RTH and todayOnly then ORL else na;

AddCloud(if DailyOpenRange then ORHHigh else na, ORHLow, Color.GRAY);
ORMedLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORMedLine.SetDefaultColor(Color.CYAN);
ORMedLine.SetStyle(Curve.SHORT_DASH);

#--Anchored VWAP-----------------------
def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

def vHigh  = if DaysAgo <= 0 then HighestAll(h) else
             HighestAll(If(previousDayPlus and !today, h[DaysAgo], na));
def vLow   = if DaysAgo <= 0 then LowestAll(l) else
             LowestAll(If(previousDayPlus and !today, l[DaysAgo + 1], na));
#Highest High of Chart
anchorh = if h == vHigh then bar else anchorh[1];

volumesumh      = if bar >= HighestAll(anchorh)  then volumesumh[1] + v else 0;
volumevwapsumh  = if bar >= HighestAll(anchorh)  then volumevwapsumh[1] + v * vw else 0;
volumevwap2sumh = if bar >= HighestAll(anchorh)  then volumevwap2sumh[1] + v * Sqr(vw) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));

plot VWAPh      = if(AnchorHigh,priceh,na);
VWAPh.SetDefaultColor(Color.LIME);
def UpBand1  = VWAPh + numDev1 * deviationh;
def LoBand1  = VWAPh - numDev1 * deviationh;
def UpBand2  = VWAPh + numDev2 * deviationh;
def LoBand2  = VWAPh - numDev2 * deviationh;

plot UpperBand1  = if !showband1 then na else UpBand1;
plot LowerBand1  = if !showband1 then na else LoBand1;
plot UpperBand2  = if !showband2 then na else UpBand2;
plot LowerBand2  = if !showband2 then na else LoBand2;

UpperBand1.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand1.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand2.SetDefaultColor(Color.DARK_GREEN);
LowerBand2.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand2 else na, UpBand1, CreateColor(15, 51, 37), CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand2 else na, LoBand1, CreateColor(65, 0, 0), CreateColor(65, 0, 0));

#Lowest Low of Chart
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if l == vLow then bar else anchor1[1];
volumesum1      = if bar >= HighestAll(anchor1) then volumesum1[1] + v else 0;
volumevwapsum1  = if bar >= HighestAll(anchor1) then volumevwapsum1[1] + v * vw else 0;
volumevwap2sum1 = if bar >= HighestAll(anchor1) then volumevwap2sum1[1] + v * Sqr(vw) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));

plot VWAP1      = if(AnchorLow,price1,na);
VWAP1.SetDefaultColor(Color.PINK);

def UpBand11  = VWAP1 + numDev1 * deviation1;
def LoBand11  = VWAP1 - numDev1 * deviation1;
def UpBand21  = VWAP1 + numDev2 * deviation1;
def LoBand21  = VWAP1 - numDev2 * deviation1;

plot UpperBand11  = if !showband1 then na else UpBand11;
plot LowerBand11  = if !showband1 then na else LoBand11;
plot UpperBand21  = if !showband2 then na else UpBand21;
plot LowerBand21  = if !showband2 then na else LoBand21;

#VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(CreateColor(15, 51, 37));
LowerBand11.SetDefaultColor(CreateColor(65, 0, 0));
UpperBand21.SetDefaultColor(Color.DARK_GREEN);
LowerBand21.SetDefaultColor(CreateColor(95, 0, 0));

AddCloud(if showclouds and showband2 then UpBand21 else na, UpBand11, CreateColor(15, 51, 37), CreateColor(15, 51, 37));
AddCloud(if showclouds and showband2 then LoBand21 else na, LoBand11, CreateColor(65, 0, 0), CreateColor(65, 0, 0));

AddLabel(ShowLabel, "Anchor days(" + DaysAgo + ")", Color.WHITE);

#---- End Code
I've tried to get anchored VWAP plotted off HOD/LOD for the current day only. If I set to 1 day aggregation it still pulls from yestererday (if highest candle was in previous day). I've tried setting Days Ago to negative etc. Then tried changing the code and could never get a plot to form (I scrapped it because it was a mess). I'm attaching my chart with HOD in Cyan and LOD in Red (the LOD VWAP works perfect because it was the low candle in the aggregation). For example on SPY today would like a HOD VWAP to print from the 9:30 candle, I sketched in what it may look like. Any help is sincerley appreciated. https://tos.mx/DrCmmR4
1698365090358.png
 
I've tried to get anchored VWAP plotted off HOD/LOD for the current day only. If I set to 1 day aggregation it still pulls from yestererday (if highest candle was in previous day). I've tried setting Days Ago to negative etc. Then tried changing the code and could never get a plot to form (I scrapped it because it was a mess). I'm attaching my chart with HOD in Cyan and LOD in Red (the LOD VWAP works perfect because it was the low candle in the aggregation). For example on SPY today would like a HOD VWAP to print from the 9:30 candle, I sketched in what it may look like. Any help is sincerley appreciated. https://tos.mx/DrCmmR4View attachment 20018

This is meant to auto anchor the vwap to today's RTHrs High/Low

Screenshot 2023-10-27 074855.png
Code:
#Anchored_VWAP_LastWEEKs_High_Low

def bn          = BarNumber();
def c           = close;
def v           = volume;
def vw          = vwap;
def anchorh;
def volumesumh;
def volumevwapsumh;
def volumevwap2sumh;
def priceh;
def deviationh;

#Today's RTH High
anchorh = if GetDay() == GetLastDay() and high == high(period = AggregationPeriod.DAY)
             then bn else anchorh[1];

volumesumh      = if bn >= HighestAll(anchorh)  then volumesumh[1] + volume else 0;
volumevwapsumh  = if bn >= HighestAll(anchorh)  then volumevwapsumh[1] + volume * vwap else 0;
volumevwap2sumh = if bn >= HighestAll(anchorh)  then volumevwap2sumh[1] + volume * Sqr(vwap) else 0;
priceh          = volumevwapsumh / volumesumh;
deviationh      = Sqrt(Max(volumevwap2sumh / volumesumh - Sqr(priceh), 0));


plot VWAPh      = priceh;
VWAPh.SetLineWeight(2);
VWAPh.SetStyle(Curve.MEDIUM_DASH);

input showbands = no;
input numDev1  = 1.0;
input numDev2  = 2.0;
input numDev3  = 3.0;

plot UpperBand1  = if !showbands then Double.NaN else VWAPh + numDev1 * deviationh;
plot LowerBand1  = if !showbands then Double.NaN else VWAPh - numDev1 * deviationh;
plot UpperBand2  = if !showbands then Double.NaN else VWAPh + numDev2 * deviationh;
plot LowerBand2  = if !showbands then Double.NaN else VWAPh - numDev2 * deviationh;
plot UpperBand3  = if !showbands then Double.NaN else VWAPh + numDev3 * deviationh;
plot LowerBand3  = if !showbands then Double.NaN else VWAPh - numDev3 * deviationh;

VWAPh.SetDefaultColor(Color.CYAN);
UpperBand1.SetDefaultColor(Color.GREEN);
LowerBand1.SetDefaultColor(Color.RED);
UpperBand2.SetDefaultColor(Color.GREEN);
LowerBand2.SetDefaultColor(Color.RED);
UpperBand3.SetDefaultColor(Color.GREEN);
LowerBand3.SetDefaultColor(Color.RED);
VWAPh.HideBubble();
UpperBand1.HideBubble();
LowerBand1.HideBubble();
UpperBand2.HideBubble();
LowerBand2.HideBubble();
UpperBand3.HideBubble();
LowerBand3.HideBubble();

input showclouds = no;
AddCloud(if showclouds then UpperBand3 else Double.NaN, UpperBand2, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand3 else Double.NaN, LowerBand2, Color.LIGHT_RED, Color.LIGHT_RED);

#Today's RTH Low
def anchor1;
def volumesum1;
def volumevwapsum1;
def volumevwap2sum1;
def price1;
def deviation1;

anchor1 = if GetDay() == GetLastDay() and low == low(period = AggregationPeriod.DAY)
             then bn else anchor1[1];
volumesum1      = if bn >= HighestAll(anchor1)  then volumesum1[1] + volume else 0;
volumevwapsum1  = if bn >= HighestAll(anchor1)  then volumevwapsum1[1] + volume * vwap else 0;
volumevwap2sum1 = if bn >= HighestAll(anchor1)  then volumevwap2sum1[1] + volume * Sqr(vwap) else 0;
price1          = volumevwapsum1 / volumesum1;
deviation1      = Sqrt(Max(volumevwap2sum1 / volumesum1 - Sqr(price1), 0));

plot VWAP1      = price1;
VWAP1.SetLineWeight(2);
VWAP1.SetStyle(Curve.MEDIUM_DASH);

plot UpperBand11  = if !showbands then Double.NaN else VWAP1 + numDev1 * deviation1;
plot LowerBand11  = if !showbands then Double.NaN else VWAP1 - numDev1 * deviation1;
plot UpperBand21  = if !showbands then Double.NaN else VWAP1 + numDev2 * deviation1;
plot LowerBand21  = if !showbands then Double.NaN else VWAP1 - numDev2 * deviation1;
plot UpperBand31  = if !showbands then Double.NaN else VWAP1 + numDev3 * deviation1;
plot LowerBand31  = if !showbands then Double.NaN else VWAP1 - numDev3 * deviation1;

VWAP1.SetDefaultColor(Color.CYAN);
UpperBand11.SetDefaultColor(Color.GREEN);
LowerBand11.SetDefaultColor(Color.RED);
UpperBand21.SetDefaultColor(Color.GREEN);
LowerBand21.SetDefaultColor(Color.RED);
UpperBand31.SetDefaultColor(Color.GREEN);
LowerBand31.SetDefaultColor(Color.RED);
VWAP1.HideBubble();
UpperBand11.HideBubble();
LowerBand11.HideBubble();
UpperBand21.HideBubble();
LowerBand21.HideBubble();
UpperBand31.HideBubble();
LowerBand31.HideBubble();


AddCloud(if showclouds then UpperBand31 else Double.NaN, UpperBand21, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showclouds then LowerBand31 else Double.NaN, LowerBand21, Color.LIGHT_RED, Color.LIGHT_RED);

#
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
489 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top