Price Crosses Above VWAP Indicator for ThinkorSwim

S

Sonny

Active member
VIP
Hi,

I want to submit the following chart study code that shows when the price crosses above VWAP. A blue arrow and sound is generated on the chart when this happens. This is useful when tracking a stock for a red to green move, especially a low float, low priced stock with a catalyst in the early time frame (9:30am to 11am). Please pass this on!

Thanks,
Sonny



Code:
#Price crosses above VWAP
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};
def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def 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));
plot vwapValue = price;
plot crossingAbove = close[1] < vwapValue[1] and close > vwapValue;
crossingAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossingAbove.SetDefaultColor(Color.CYAN);
crossingAbove.SetLineWeight(1);
Alert(crossingAbove[1], "Cross Above VWAP", Alert.BAR, Sound.Bell);
 
Last edited by a moderator:
T

TXJ111

New member
Thanks for the code. Is there anyway to get an alert via email or text using a 1 or 5 minute time frame if you are not at your computer?
 
S

Sonny

Active member
VIP
Thanks for the code. Is there anyway to get an alert via email or text using a 1 or 5 minute time frame if you are not at your computer?

You can get the alert only if you set it to a particular stock.
 
BenTen

BenTen

Administrative
Staff
VIP
Adding to what @Sonny said, you can also create a scanner for this indicator, save it as a watclist, and then get alerted for new changes within that watchlist.
 
T

TXJ111

New member
Thank you @BenTen and @Sonny!! When I set up the scan and the alert, after I select the study from the study list, do I select “is true” and then select “by one bar” or something else? Also how do I set this up on a 5 minute timeframe? Thank you!!
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@TXJ111 Yes, you would use the "true" option. The within X bars is the lookback value. You can set to 1 if you want to or you can play around with this value.
 
T

TXJ111

New member
Hello,

When I try to set this up as an alert I get an error that says Vwap920(what I named the study)() . “VwapValue” is true within 2 bars. The name of my study and the words “is true” are in red. The number two is blue. I set this on a one minute time frame. Any assistance with this would be greatly appreciated.

I also see a message that says expected double at 1:23. Thanks
 
rad14733

rad14733

Well-known member
VIP
Hello,

When I try to set this up as an alert I get an error that says Vwap920(what I named the study)() . “VwapValue” is true within 2 bars. The name of my study and the words “is true” are in red. The number two is blue. I set this on a one minute time frame. Any assistance with this would be greatly appreciated.
I just copied and pasted the code above into a new Study and it worked flawlessly... Try copy and pasting the code again... Perhaps you missed some of the code...
 
T

TXJ111

New member
Thank you for your response. It works as a watchlist and when I add it to my chart but when I try to set it up as an alert is when I get the error message.
 
rad14733

rad14733

Well-known member
VIP
Thank you for your response. It works as a watchlist and when I add it to my chart but when I try to set it up as an alert is when I get the error message.
Ok... So, how are you trying to set it up as an alert as there are several methods of doing so...??? The easiest method would be to add an Alert() to the Chart Study...
 
T

TXJ111

New member
Hi @rad14733 I right clicked on the chart, selected create alerts, study, edit, changed the time frame to 1 min, selected edit, study, then I selected the name of the study and is true. Thank you for your help!!
 
rad14733

rad14733

Well-known member
VIP
Hi @rad14733 I right clicked on the chart, selected create alerts, study, edit, changed the time frame to 1 min, selected edit, study, then I selected the name of the study and is true. Thank you for your help!!
@TXJ111 That works, even without the study on the chart... ;) (y)
 
D

Daniel

Member
VIP
I just copied and pasted the code above into a new Study and it worked flawlessly... Try copy and pasting the code again... Perhaps you missed some of the code...

Hi, I set it up in my studies and renamed it. I try to set it into the scan by "add condition" and select study. I selected "is true with one min bar " But i can not save it. Can someone help .

Thank you,
Daniel
 
Last edited by a moderator:
rad14733

rad14733

Well-known member
VIP
@dzizzi No... Watchlists can only reference licensed built-in Studies... You would need to use the Thinkscript editor and add the Study code in and then you would need to make a lot of edits... Only one plot in the code is one edit... Removing the Alert might be another... And whatever else is throwing errors... You can't just Copy and Paste code in different modules of Thinkorswim because each module works differently...

@Daniel See my previous post regarding Watchlists as it also pertains to your issues as well...
 
Last edited by a moderator:

Similar threads

Top