RSI-VWAP Indicator for ThinkorSwim

In honor of GME going to 300 I'm sharing a script that uses the RSI instead of price for the VWAP. I use it on the today 5 minute graph if anyone knows how to set it up daily, weekly or monthly it would be great.

Mdr7RZp.png


Code:
declare lower;

input length = 14;
input price = close;
input averageType = AverageType.simple;
input ratio = 2.236;
DefineGlobalColor("RisingMA", color.uptick);
DefineGlobalColor("FallingMA", color.downtick);

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);


def o = (RSI + RSI[1]) / 2;

def h = Max(RSI, RSI[1]);

def l = Min(RSI, RSI[1]);

def c = RSI;

def hl2 = (h+l)/2;
AddChart(high = h, low = l, open = o, close = c, type = ChartType.CANDLE, Color.WHITE);
input charttype = ChartType.CANDLE;


def Data = BarNumber();
input Number_Of_Bar = 1;

def bar =  Data >= Number_Of_Bar;
def pv = if bar then pv[1] + hl2 * volume else 0;
def cumvolume = if bar then cumvolume[1] + volume else 0;
plot vw = pv / cumvolume;
def bars = Data - Number_Of_Bar;
def sample = if bar then sample[1] + Sqr(hl2 - vw) else 0;
def var = sample / bars;
def dev = Sqrt(var);

plot dev1 =  vw + (dev * ratio);
plot dev2 = vw - (dev * ratio);

vw.setdefaultColor(color.yellow);
dev1.SetDefaultColor(Color.White);
dev2.SetDefaultColor(Color.White);


dev1.Setlineweight(2);
dev2.Setlineweight(2);


vw.SetLineWeight(3);
#vw.AssignValueColor(if rsi > vw
                           #then color.light_GREEN
                           #else color.light_RED);
By the way really like the indicator
 
By the way really like the indicator
stitch this part and the other code together if you can, this has the color candles. but not the clouds and the other components.

Code:
declare lower;
# hide the default candles
#HidePricePlot();


input length = 21;

input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);


input BarsBetween = 0;

# calculate the offset
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = BarsBetween * ((lastBar - BarNumber()) / (BarsBetween + 1));

# build the candle
def o;
def h;
def l;
def c;

def R = RSI();


if offset % 1 == 0
then {

    o = (R + R[1]) / 2;

    h = Max(R, R[1]);

    l = Min(R, R[1]);

    c = R;

} else {
    o = Double.NaN;
    h = Double.NaN;
    l = Double.NaN;
    c = Double.NaN;
}

# just the UP candles
def UpO;
def UpH;
def UpL;
def UpC;
if o <= c
then {
    UpO = o;
    UpH = h;
    UpL = l;
    UpC = c;
} else {
    UpO = Double.NaN;
    UpH = Double.NaN;
    UpL = Double.NaN;
    UpC = Double.NaN;
}

# just the DOWN candles
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
    DnO = o;
    DnH = h;
    DnL = l;
    DnC = c;
} else {
    DnO = Double.NaN;
    DnH = Double.NaN;
    DnL = Double.NaN;
    DnC = Double.NaN;
}

# Plot the new Chart
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);


#VM_MIDAS_StandartDeviationBands;
input tt = 2.68;

def Data = BarNumber();
input Number_Of_Bar = 1;

def bar =  Data >= Number_Of_Bar;
def pv = if bar then pv[1] + c * volume else 0;
def cumvolume = if bar then cumvolume[1] + volume else 0;
plot vw = pv / cumvolume;
def bars = Data - Number_Of_Bar;
def sample = if bar then sample[1] + Sqr(c - vw) else 0;
def var = sample / bars;
def dev = Sqrt(var);#var

plot dev1 =  vw + dev * 2.0;
plot dev2 = vw - (dev * 2.0);

vw.SetDefaultColor(Color.YELLOW);
vw.SetLineWeight(1);
dev1.SetDefaultColor(Color.WHITE);
dev2.SetDefaultColor(Color.WHITE);

dev1.SetLineWeight(2);
dev2.SetLineWeight(2);

input length2 = 10;
plot average = average(rsi, length2);

#END BURRITO CODE.............................................
 
@hmbart Welcome to the usethinkscript forums... I'm sure your scan is doable but we need to define a few items better first... First, confirmations are based on conditional criteria, not colors... Therefore we need to determine which conditional criteria are met... Colors can be different on different members charts but the criteria remains the same... We need to establish proper semantics before we can create proper syntax... By that I mean that we need to know logic causes the condition that causes a color to be displayed, not the color itself... Clear as mud yet...???

Now. all that being said there are a few issues with your code as I will go through...

First, when we are working with conditional code we are talking numbers, not text... Therefore, all results are numbers... That means your "+1" and "-1" and "0" should not have quotes and the "+1" should simply be a 1, etc... That's the first part...

Next there is the issue of def shared_vwap_1;... You will receive an error in the subsequent code because shared_vwap_1 hasn't been assigned a value... Until it has been properly defined it cannot be used for anything else... Which brings me to the optimization aspect of writing code... Virtually all scripting languages will perform faster and more efficiently if we fully define variables before calculations rather than using function calls within complex calculation structures... This is very important in Thinkscript because it can greatly improve performance and mitigate potential lag...

So, without giving up the answer I'll leave it up to you to determine what the value of shared_vwap_1 should be and then you can optimize the code to work from there... Trust me, you're close - I think... You have some concepts to work from now at the very least... If you have additional questions just ask...
Thanks so much for your input. I'm going to work on it again tonight!
 
@hmbart Welcome to the usethinkscript forums... I'm sure your scan is doable but we need to define a few items better first... First, confirmations are based on conditional criteria, not colors... Therefore we need to determine which conditional criteria are met... Colors can be different on different members charts but the criteria remains the same... We need to establish proper semantics before we can create proper syntax... By that I mean that we need to know logic causes the condition that causes a color to be displayed, not the color itself... Clear as mud yet...???

Now. all that being said there are a few issues with your code as I will go through...

First, when we are working with conditional code we are talking numbers, not text... Therefore, all results are numbers... That means your "+1" and "-1" and "0" should not have quotes and the "+1" should simply be a 1, etc... That's the first part...

Next there is the issue of def shared_vwap_1;... You will receive an error in the subsequent code because shared_vwap_1 hasn't been assigned a value... Until it has been properly defined it cannot be used for anything else... Which brings me to the optimization aspect of writing code... Virtually all scripting languages will perform faster and more efficiently if we fully define variables before calculations rather than using function calls within complex calculation structures... This is very important in Thinkscript because it can greatly improve performance and mitigate potential lag...

So, without giving up the answer I'll leave it up to you to determine what the value of shared_vwap_1 should be and then you can optimize the code to work from there... Trust me, you're close - I think... You have some concepts to work from now at the very least... If you have additional questions just ask...
Here's the code I'm trying now. The only thing that shows errors is the last statement about Assigning background color:

Code:
#code
# Green background means price is above vwap
# Blue background means price is at vwap within last 5 bars
# Red background means price is below vwap

plot RSI = reference RSI();

def shared_vwap_1 = VWAP();
def price = close;

addLabel(yes, RSI);

AssignBackgroundColor(if price>shared_vwap_1 then color.GREEN else if price<shared_vwap_1 then color.RED else if price=shared_vwap_1 within last 5 bars then color.CYAN else color.GRAY);
#end

Any idea what I have done wrong?
 
@hmbart Here you go... You had two errors... The first was that a comparator is == and = is an assignment... The second was the un-needed use of last in your within clause...

Also, few tips... If you use the </> icon you can encapsulate your code and if your select Ruby as the language it will color the syntax of the code... Or you can type the code tags manually... You can learn what the codes look like by clicking on the Toggle BB Code [ ] icon at the right side of the formatting bar...

Ruby:
#code
# Green background means price is above vwap
# Blue background means price is at vwap within last 5 bars
# Red background means price is below vwap

plot RSI = reference RSI();

def shared_vwap_1 = VWAP();
def price = close;

addLabel(yes, RSI);

AssignBackgroundColor(if price > shared_vwap_1 then color.GREEN else if price < shared_vwap_1 then color.RED else if price == shared_vwap_1 within 5 bars then color.CYAN else color.GRAY);

#end
 
@hmbart Here you go... You had two errors... The first was that a comparator is == and = is an assignment... The second was the un-needed use of last in your within clause...

Also, few tips... If you use the </> icon you can encapsulate your code and if your select Ruby as the language it will color the syntax of the code... Or you can type the code tags manually... You can learn what the codes look like by clicking on the Toggle BB Code [ ] icon at the right side of the formatting bar...

Ruby:
#code
# Green background means price is above vwap
# Blue background means price is at vwap within last 5 bars
# Red background means price is below vwap

plot RSI = reference RSI();

def shared_vwap_1 = VWAP();
def price = close;

addLabel(yes, RSI);

AssignBackgroundColor(if price > shared_vwap_1 then color.GREEN else if price < shared_vwap_1 then color.RED else if price == shared_vwap_1 within 5 bars then color.CYAN else color.GRAY);

#end
Thank you! That was really helpful! It works great now, however I need to change the value color of RSI because I can't read it all with the background colors unless I highlight the row. I added AssignValueColor to black but the text color hasn't changed on my watchlist....Does anyone have a solution or can someone point out an error? Here is the updated code:

Code:
#code
# Green background means price is above vwap
# Blue background means price is at vwap within last 5 bars
# Red background means price is below vwap

plot RSI = reference RSI();

def shared_vwap_1 = VWAP();
def price = close;

addLabel(yes, RSI);

RSI.AssignValueColor(color.BLACK);

AssignBackgroundColor(if price > shared_vwap_1 then color.GREEN else if price < shared_vwap_1 then color.RED else if price == shared_vwap_1 within 5 bars then color.CYAN else color.GRAY);

#end
 
@hmbart Here you go... You had two errors... The first was that a comparator is == and = is an assignment... The second was the un-needed use of last in your within clause...

Also, few tips... If you use the </> icon you can encapsulate your code and if your select Ruby as the language it will color the syntax of the code... Or you can type the code tags manually... You can learn what the codes look like by clicking on the Toggle BB Code [ ] icon at the right side of the formatting bar...

Ruby:
#code
# Green background means price is above vwap
# Blue background means price is at vwap within last 5 bars
# Red background means price is below vwap

plot RSI = reference RSI();

def shared_vwap_1 = VWAP();
def price = close;

addLabel(yes, RSI);

AssignBackgroundColor(if price > shared_vwap_1 then color.GREEN else if price < shared_vwap_1 then color.RED else if price == shared_vwap_1 within 5 bars then color.CYAN else color.GRAY);

#end
I fixed the value color...newest code. I can't wait to use it tomorrow! Thanks again!

#code
# Green background means price is above vwap
# Blue background means price is at vwap within last 5 bars
# Red background means price is below vwap

plot RSI = reference RSI();

def shared_vwap_1 = VWAP();
def price = close;

addLabel(yes, RSI, Color.BLACK);


AssignBackgroundColor(if price > shared_vwap_1 then color.GREEN else if price < shared_vwap_1 then color.RED else if price == shared_vwap_1 within 5 bars then color.CYAN else color.GRAY);
 
stitch this part and the other code together if you can, this has the color candles. but not the clouds and the other components.

Code:
declare lower;
# hide the default candles
#HidePricePlot();


input length = 21;

input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);


input BarsBetween = 0;

# calculate the offset
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = BarsBetween * ((lastBar - BarNumber()) / (BarsBetween + 1));

# build the candle
def o;
def h;
def l;
def c;

def R = RSI();


if offset % 1 == 0
then {

    o = (R + R[1]) / 2;

    h = Max(R, R[1]);

    l = Min(R, R[1]);

    c = R;

} else {
    o = Double.NaN;
    h = Double.NaN;
    l = Double.NaN;
    c = Double.NaN;
}

# just the UP candles
def UpO;
def UpH;
def UpL;
def UpC;
if o <= c
then {
    UpO = o;
    UpH = h;
    UpL = l;
    UpC = c;
} else {
    UpO = Double.NaN;
    UpH = Double.NaN;
    UpL = Double.NaN;
    UpC = Double.NaN;
}

# just the DOWN candles
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
    DnO = o;
    DnH = h;
    DnL = l;
    DnC = c;
} else {
    DnO = Double.NaN;
    DnH = Double.NaN;
    DnL = Double.NaN;
    DnC = Double.NaN;
}

# Plot the new Chart
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);


#VM_MIDAS_StandartDeviationBands;
input tt = 2.68;

def Data = BarNumber();
input Number_Of_Bar = 1;

def bar =  Data >= Number_Of_Bar;
def pv = if bar then pv[1] + c * volume else 0;
def cumvolume = if bar then cumvolume[1] + volume else 0;
plot vw = pv / cumvolume;
def bars = Data - Number_Of_Bar;
def sample = if bar then sample[1] + Sqr(c - vw) else 0;
def var = sample / bars;
def dev = Sqrt(var);#var

plot dev1 =  vw + dev * 2.0;
plot dev2 = vw - (dev * 2.0);

vw.SetDefaultColor(Color.YELLOW);
vw.SetLineWeight(1);
dev1.SetDefaultColor(Color.WHITE);
dev2.SetDefaultColor(Color.WHITE);

dev1.SetLineWeight(2);
dev2.SetLineWeight(2);

input length2 = 10;
plot average = average(rsi, length2);

#END BURRITO CODE.............................................
I'm sorry I cant do this, if you can help that will be great.
 
I didn't realize how awesome this indicator was until today. I came across it in my list of studies pre market - added and removed mostly everything. layered it on top of the BTD percentile Lows - with a custom RSM like clouds based on line 1 and 3 and BAM! B E A UUUTTIFULL! thanks for the great work.

Image of MNQ 8kt

 
I am using length 13, smooth 21, length2 5, and length3 55. if everything above length3 then it's bullish and if all below it then it's bearish if length 2 above level 50 it showing the trend is getting stronger and the below trend is weak. All other settings are same as given before.
I just added this code, and wanted to confirm, which line is avg line, length 2 and length 3 line:

https://prnt.sc/13mxc7t

My settings:

https://prnt.sc/13mxd7b

Lastly, is there any good settings to use with daytrade/scalping?

Thanks
 
After "clicking" onto the "share" button provided and pasting this link into Safari, the window opens into a gray blank page, nothing more, no chart or additional loading, just blank. No error, but no chart, studies in the imgur.com site.
Thank you.

2 pending questions;
How do you change VWAP setting from trading hours (9:30-4:00) to 24 hours? (Resetting new VWAP as suppose to?)
How do you change "scaling" of one indicator to another indicator in the same indicator window to be of same scale?

Thank you all for your help.

Grateful2Bhere
 
After "clicking" onto the "share" button provided and pasting this link into Safari, the window opens into a gray blank page, nothing more, no chart or additional loading, just blank. No error, but no chart, studies in the imgur.com site.
Thank you.

2 pending questions;
How do you change VWAP setting from trading hours (9:30-4:00) to 24 hours? (Resetting new VWAP as suppose to?)
How do you change "scaling" of one indicator to another indicator in the same indicator window to be of same scale?

Thank you all for your help.

Grateful2Bhere
so for vwap. it would be anchored vwap maybe what youre looking for. for the scaling are you asking about aggregation? maybe that can help. now for vwap it will be the same. the problem with vwap is that its going to calculate everything thats on the actual screen that youre looking at unless you have a specific type of vwap, you ight really like this indicator.
Code:
#####################################################################
#VWAP_Limited_Full_Lines 2011.11.12 14:45pst zzz added limited lines and full lines #     instead of normal curves
#VWAP Study: thinkorswim, inc. (c) 2011
# 2012-02-06  duplicated the thinkorswim code
#             modified some thinkorswim variable names
#             modified default colors for plotting
#             and added code for 2nd deviation
#
input num1stDevUp = 1.0;
input num2ndDevUp = 2.0;
input num3rdDevUp = 3.0;
def num1stDevDn   = -num1stDevUp;
def num2ndDevDn   = -num2ndDevUp;
def num3rdDevDn   = -num3rdDevUp;
input multiplier  = 1.0;#Hint multiplier: Change to +/- number of "Days", "Weeks", etc
input lines       = {default limited, horizontal, lines};

input timeFrame = {MINUTE, MIN2, MIN3, MIN5, MIN10, MIN15, MIN20, MIN30, default HOUR, TWOHOUR, FOURHOUR, DAY, WEEK, MONTH, CHART};

def cap = GetAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "vwap timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
def seconds = SecondsFromTime(0);
def minutes;
def day_number = DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd));
switch (timeFrame) {
case MINUTE:
    periodIndx = Floor(seconds / 60 + day_number * 24 * 60);
    minutes    = 1;
case MIN2:
    periodIndx = Floor(seconds / 120 + day_number * 24);
    minutes    = 2;
case MIN3:
    periodIndx = Floor(seconds / 180 + day_number * 24);
    minutes    = 3;
case MIN5:
    periodIndx = Floor(seconds / 300 + day_number * 24);
    minutes    = 5;
case MIN10:
    periodIndx = Floor(seconds / 600 + day_number * 24);
    minutes    = 10;
case MIN15:
    periodIndx = Floor(seconds / 900 + day_number * 24);
    minutes    = 15;
case MIN20:
    periodIndx = Floor(seconds / 1200 + day_number * 24);
    minutes    = 20;
case MIN30:
    periodIndx = Floor(seconds / 1800 + day_number * 24);
    minutes    = 30;
case HOUR:
    periodIndx = Floor(seconds / 3600 + day_number * 24);
    minutes    = 60;
case TWOHOUR:
    periodIndx = Floor(seconds / 7200 + day_number * 24);
    minutes    = 120;
case FOURHOUR:
    periodIndx = Floor(seconds / 14400 + day_number * 24);
    minutes    = 240;
case DAY:
    periodIndx = CountTradingDays(Min(First(yyyyMmDd), yyyyMmDd), yyyyMmDd) - 1;
    minutes    = 720;
case WEEK:
    periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
    minutes    = 3600;
case MONTH:
    periodIndx = RoundDown(yyyyMmDd / 100, 0);
    minutes    = 15120;
case CHART:
    periodIndx = 0;
    minutes    = 0;
}
def countindx = CompoundValue(1, if periodIndx != periodIndx[1] then (countindx[1] + periodIndx - periodIndx[1]) % multiplier else countindx[1], 0);
def isPeriodRolled = countindx < countindx[1] + periodIndx - periodIndx[1];
#def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);

input num_vwap_displayed = 2000;
def Count = num_vwap_displayed;
def cond = if isPeriodRolled
           then 1
           else Double.NaN;
def dataCount = CompoundValue(1, if !IsNaN(cond)
                                 then dataCount[1] + 1
                                 else dataCount[1], 0);

rec volumeSum;
rec volumeVwapSum;
rec volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

rec v  = if IsNaN(vwap) then v[1]  else price;
rec v1 = if IsNaN(vwap) then v1[1] else price + num1stDevUp * deviation;
rec v2 = if IsNaN(vwap) then v2[1] else price - num1stDevUp * deviation;
rec v3 = if IsNaN(vwap) then v3[1] else price + num2ndDevUp * deviation;
rec v4 = if IsNaN(vwap) then v4[1] else price - num2ndDevUp * deviation;
rec v5 = if IsNaN(vwap) then v5[1] else price + num3rdDevUp * deviation;
rec v6 = if IsNaN(vwap) then v6[1] else price - num3rdDevUp * deviation;
plot VWAP;
plot FirstUpperBand;
plot FirstLowerBand;
plot SecondUpperBand;
plot SecondLowerBand;
plot ThirdUpperBand;
plot ThirdLowerBand;
input showlineinchartlength = 5;
input showlines = yes;
if (!errorInAggregation) and
    lines == lines.limited {
    VWAP = if IsNaN(close)
                      then Double.NaN
                      else if IsNaN(close[-showlineinchartlength]) and
                              HighestAll(dataCount) - dataCount <= Count - 1
                      then v
                      else Double.NaN ;
    FirstUpperBand  = if IsNaN(close[-showlineinchartlength]) and
                         HighestAll(dataCount) - dataCount <= Count - 1
                      then v1
                      else Double.NaN ;
    FirstLowerBand  = if IsNaN(close[-showlineinchartlength]) and
                         HighestAll(dataCount) - dataCount <= Count - 1
                      then v2
                      else Double.NaN ;
    SecondUpperBand = if IsNaN(close[-showlineinchartlength]) and
                         HighestAll(dataCount) - dataCount <= Count - 1
                      then v3
                      else Double.NaN ;
    SecondLowerBand = if IsNaN(close[-showlineinchartlength]) and
                         HighestAll(dataCount) - dataCount <= Count - 1
                      then v4
                      else Double.NaN ;
    ThirdUpperBand  = if IsNaN(close[-showlineinchartlength]) and
                         HighestAll(dataCount) - dataCount <= Count - 1
                      then v5
                      else Double.NaN ;
    ThirdLowerBand  = if IsNaN(close[-showlineinchartlength]) and
                         HighestAll(dataCount) - dataCount <= Count - 1
                      then v6
                      else Double.NaN ;
} else if (!errorInAggregation) and
           lines == lines.horizontal  and
           HighestAll(dataCount) - dataCount <= Count - 1 {
    VWAP = HighestAll(if IsNaN(close) then v else Double.NaN );
    FirstUpperBand  = HighestAll(if IsNaN(close) then v1 else Double.NaN );
    FirstLowerBand  = HighestAll(if IsNaN(close) then v2 else Double.NaN );
    SecondUpperBand = HighestAll(if IsNaN(close) then v3 else Double.NaN );
    SecondLowerBand = HighestAll(if IsNaN(close) then v4 else Double.NaN );
    ThirdUpperBand  = HighestAll(if IsNaN(close) then v5 else Double.NaN );
    ThirdLowerBand  = HighestAll(if IsNaN(close) then v6 else Double.NaN );
} else if (!errorInAggregation) and
           lines == lines.lines  and
           HighestAll(dataCount) - dataCount <= Count - 1 {
    VWAP            = price;
    FirstUpperBand  = price + num1stDevUp * deviation;
    FirstLowerBand  = price - num1stDevUp * deviation;
    SecondUpperBand = price + num2ndDevUp * deviation;
    SecondLowerBand = price - num2ndDevUp * deviation;
    ThirdUpperBand  = price + num3rdDevUp * deviation;
    ThirdLowerBand  = price - num3rdDevUp * deviation;
} else {
    VWAP            = Double.NaN;
    FirstUpperBand  = Double.NaN;
    FirstLowerBand  = Double.NaN;
    SecondUpperBand = Double.NaN;
    SecondLowerBand = Double.NaN;
    ThirdUpperBand  = Double.NaN;
    ThirdLowerBand  = Double.NaN;
}

#VWAP.SetDefaultColor(Color.BLUE);
VWAP.AssignValueColor(if VWAP > VWAP[1]
                      then Color.GREEN
                      else Color.RED);
FirstUpperBand.SetDefaultColor(Color.BLUE);
FirstLowerBand.SetDefaultColor(Color.BLUE);
SecondUpperBand.SetDefaultColor(Color.BLUE);
SecondLowerBand.SetDefaultColor(Color.BLUE);
ThirdUpperBand.SetDefaultColor(Color.BLUE);
ThirdLowerBand.SetDefaultColor(Color.BLUE);

VWAP.SetPaintingStrategy(PaintingStrategy.LINE);
FirstUpperBand.SetStyle(Curve.SHORT_DASH);
FirstLowerBand.SetStyle(Curve.SHORT_DASH);
SecondUpperBand.SetStyle(Curve.SHORT_DASH);
SecondLowerBand.SetStyle(Curve.SHORT_DASH);
ThirdUpperBand.SetStyle(Curve.SHORT_DASH);
ThirdLowerBand.SetStyle(Curve.SHORT_DASH);

VWAP.SetLineWeight(2);
FirstUpperBand.SetLineWeight(1);
FirstLowerBand.SetLineWeight(1);
SecondUpperBand.SetLineWeight(1);
SecondLowerBand.SetLineWeight(1);
ThirdUpperBand.SetLineWeight(1);
ThirdLowerBand.SetLineWeight(1);

VWAP.HideBubble();
FirstUpperBand.HideBubble();
FirstLowerBand.HideBubble();
SecondUpperBand.HideBubble();
SecondLowerBand.HideBubble();
ThirdUpperBand.HideBubble();
ThirdLowerBand.HideBubble();

FirstUpperBand.SetHiding(!showlines);
FirstLowerBand.SetHiding(!showlines);
SecondUpperBand.SetHiding(!showlines);
SecondLowerBand.SetHiding(!showlines);
ThirdUpperBand.SetHiding(!showlines);
ThirdLowerBand.SetHiding(!showlines);

input showbubblesVSTD = yes;
input bubblemoverVSTD = 5;#Hint bubblemoverVSTD: Number of Spaces VSTD bubble offset in expansion
def p = bubblemoverVSTD;
def p1 = p + 1;

AddChartBubble(showbubblesVSTD and IsNaN(close[p]) and !IsNaN(close[p1]) ,
               close[p1],
              "VSTD" + "\n" + AsPercent((close[p1] - price[p1]) / deviation[p1] / 100) +
              "\n" + Round(close[p1], 2) ,
               if close[p1] > VWAP[p1]
               then if close[p1] > close[p1 + 1]
                    then Color.GREEN
                    else Color.LIGHT_GREEN
               else if close[p1] > close[p1 + 1]
                    then Color.LIGHT_RED
               else Color.RED );

input showclouds = yes;
def green = if low >= VWAP and close > open
            then 1
            else if green[1] == 1 and high >= VWAP
            then 1
            else if green[1] == 1 and close > open   
            then 1
            else 0;

def g = !isnan(green);

AddCloud(if showclouds and g
         then ThirdUpperBand
         else Double.NaN,
         VWAP,
         Color.LIGHT_GRAY, Color.LIGHT_GRAY);
AddCloud(if showclouds and !g
         then VWAP
         else Double.NaN,
         ThirdLowerBand,
         Color.PINK, Color.PINK);
plot x = if showclouds
        then if g
             then ThirdUpperBand
             else ThirdLowerBand
        else Double.NaN;
x.AssignValueColor(if g
                   then Color.GREEN
                   else Color.RED);
input showbubblescurrent = no;
input bubblemovercurrent = 5;#Hint bubblemoverVSTD: Number of Spaces Above/Below VWAP bubble offset in expansion
def q = bubblemovercurrent;
def q1 = q + 1;

AddChartBubble(showbubblescurrent and IsNaN(close[q]) and !IsNaN(close[q1]) ,
               close[q1],
              "V" ,
               if g[q1]
               then Color.GREEN
               else Color.RED );

input usealerts = yes;
Alert(usealerts and g[1] != g, "VWAP - " + if g == 1 then "Green" else "Red", Alert.BAR, Sound.Chimes);
# end of VWAP Study
#Vertical Line @VWAP timeframe
input showverticalline = yes;
input begin   = 0930;
input end     = 1600;
def start     = if (timeFrame == timeFrame.TWOHOUR or timeFrame == timeFrame.FOURHOUR)
                then SecondsTillTime(0800) == 0 and
                     SecondsFromTime(0800) == 0
                else if timeFrame == timeFrame.HOUR
                then SecondsTillTime(0900) == 0 and
                     SecondsFromTime(0900) == 0
                else SecondsTillTime(0930) == 0 and
                     SecondsFromTime(0930) == 0;
def bar       = if start
                then 0
                else bar[1] + 1;

AddVerticalLine(if showverticalline and GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0
                then bar % ((Ceil(minutes) * multiplier) / (GetAggregationPeriod() / 60000)) == 0
                else Double.NaN,
                color = Color.BLUE, stroke = Curve.FIRM);
 
Astro_Phx,

I'm new, but I copied your like and pasted into safari thinking this is a link but nothing. Can you help a newbie out? Can you paste your TOS link chart layout with this indicator you all have been working on here? Thank you so much and I appreciate this web site and help.

Grateful2Bhere
hello grateful2bhere, I just checked the link. It's working. Maybe you can try some other browser.
 
Thank you Germanburrito for the custom VWAP. I copied and pasted into TOS as a study, but I'm not sure if everything populates as designed. Is it possible to post a screen shot and helpful information about what settings? What I'm seeing is VWAP only on last 5 bars?
Thank you kindly.
Grateful2Bhere
 
Thank you Germanburrito for the custom VWAP. I copied and pasted into TOS as a study, but I'm not sure if everything populates as designed. Is it possible to post a screen shot and helpful information about what settings? What I'm seeing is VWAP only on last 5 bars?
Thank you kindly.
Grateful2Bhere
@Grateful2Bhere
(fyi, you need to put an @ sign in front of a member's name for them to get an alert that you are asking them a question :))

Yes, the @germanburrito's VWAP script plots the last 5 bars. I find the default settings work well. But the only way you will know what works best for you is to play with the settings and see how the indicator line up w/ your strategy and with your other indicators. To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
a1.png
 
Last edited:
In honor of GME going to 300 I'm sharing a script that uses the RSI instead of price for the VWAP. I use it on the today 5 minute graph if anyone knows how to set it up daily, weekly or monthly it would be great.

Mdr7RZp.png


Code:
declare lower;

input length = 14;
input price = close;
input averageType = AverageType.simple;
input ratio = 2.236;
DefineGlobalColor("RisingMA", color.uptick);
DefineGlobalColor("FallingMA", color.downtick);

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);


def o = (RSI + RSI[1]) / 2;

def h = Max(RSI, RSI[1]);

def l = Min(RSI, RSI[1]);

def c = RSI;

def hl2 = (h+l)/2;
AddChart(high = h, low = l, open = o, close = c, type = ChartType.CANDLE, Color.WHITE);
input charttype = ChartType.CANDLE;


def Data = BarNumber();
input Number_Of_Bar = 1;

def bar =  Data >= Number_Of_Bar;
def pv = if bar then pv[1] + hl2 * volume else 0;
def cumvolume = if bar then cumvolume[1] + volume else 0;
plot vw = pv / cumvolume;
def bars = Data - Number_Of_Bar;
def sample = if bar then sample[1] + Sqr(hl2 - vw) else 0;
def var = sample / bars;
def dev = Sqrt(var);

plot dev1 =  vw + (dev * ratio);
plot dev2 = vw - (dev * ratio);

vw.setdefaultColor(color.yellow);
dev1.SetDefaultColor(Color.White);
dev2.SetDefaultColor(Color.White);


dev1.Setlineweight(2);
dev2.Setlineweight(2);


vw.SetLineWeight(3);
#vw.AssignValueColor(if rsi > vw
                           #then color.light_GREEN
                           #else color.light_RED);
@germanburrito, great indicators. Can you please share the code of lower indicator RSI_atr? Thanks!
 
@germanburrito what is the updated code of Vwap rsi? if there is one, would it work on all time frames


theres no updated code and yes it would, the problem is not time frames the problem ihow far back you are looking meaning are you looking at a week, month or year, you know, because after a while it wont make since to look back, maybe a day "today" chart is the best to look at in this indicator.
 

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
318 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