Easycator's VWAP Trading Indicator/Strategy

Status
Not open for further replies.

rad14733

Well-known member
VIP
I've searched the forums and haven't found anything like the VWAP Trading Strategy that Easycators has for sale and wondered if we have any of the components already created before I roll up my sleeves and have a go at a similar one... It is almost identical to what I had been envisioning before I stumbled across a video today... I am primarily interested in a lower study similar to his as well as the scan and watchlist column... I'm sure I can write what I want but don't want to reinvent the wheel from scratch if I don't have to... Any input would be greatly appreciated...

If I'm not too tired this evening I'd like to start scripting... I like having multiple trading systems at my disposal and have been playing with VWAP in recent days, comparing it to other indicators and systems that I currently employ... I have already modified the Acrylic VWAP Study to have multiple deviations and it seems to work to my liking...

Here are links to his YouTube Video and his Z-Score Distance From VWAP system for anyone not familiar with what I am talking about...
 
@rad14733 Done. How is it different? I didn't get a chance to dive in on the video, but I thought they look the same.

Also, here is another VWAP script called V-Score. Hopefully that helps.

Code:
#TOS Indicators - Home of the Volatility Box
#Full YouTube Tutorial: https://youtu.be/mAPEodczf-k
#
#**10/6/19 - Feature Added: Ability for Users to Set Custom Standard Deviation in Label Output

declare lower;
input anchorDate = 20180901;
input barsGoBack = 120;
input showStopLabel = yes;
input devStop = {default One, Two, Three, Zero, NegOne, NegTwo, NegThree, Custom};
input customDev = 0.15;
def chosenDev;
switch(devStop){
case One:
    chosenDev = 1;
case Two:
    chosenDev = 2;
case Three:
    chosenDev = 3;
case Zero:
    chosenDev = 0;
case NegOne:
    chosenDev = -1;
case NegTwo:
    chosenDev = -2;
case NegThree:
    chosenDev = -3;
case Custom:
    chosenDev = customDev;
}



def postAnchorDate = if GetYYYYMMDD() >= anchorDate then 1 else 0;


def yyyyMmDd = getYyyyMmDd();
def periodIndx = if getAggregationPeriod() < AggregationPeriod.HOUR then yyyyMMDD else postAnchorDate;
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 VScore = if (((price - close)*(-1))/deviation) > 5 or (((price - close)*(-1))/deviation) < -5 then 0 else (((price - close)*(-1))/(deviation));
plot zero = 0;
plot one = 1;
plot two = 2;
plot three = 3;
plot negOne = -1;
plot negTwo = -2;
plot negThree = -3;
plot posInt = 0.3;
plot negInt = -0.3;

def stopPrice = (chosenDev)*(deviation) + (price);
AddLabel(showStopLabel, "Price at ["+chosenDev+"] SD: "+AsPrice(Round(stopPrice,2)),color.white);
def zeroAndOne = if VScore > zero and VScore <= one then 1 else 0;
def oneAndTwo = if VScore > one and VScore <= two then 1 else 0;
def twoAndThree = if VScore > two and VScore <= three then 1 else 0;

def negZeroAndOne = if VScore > negOne and VScore < zero then 1 else 0;
def negOneAndTwo = if VScore > negTwo and VScore <= negOne then 1 else 0;
def negTwoAndThree = if VScore > negThree and VScore <= negTwo then 1 else 0;

def cloud1;
def cloud2;
if Sum(zeroAndOne, barsGoBack) > Sum(OneAndTwo,barsGoBack) and Sum(zeroAndOne, barsGoBack) > Sum(twoAndThree,barsGoBack) and Sum(zeroAndOne, barsGoBack) > Sum(negZeroAndOne,barsGoBack) and Sum(zeroAndOne, barsGoBack) > Sum(negoneAndTwo,barsGoBack) and Sum(zeroAndOne, barsGoBack) > Sum(negtwoAndThree,barsGoBack){
    cloud1 = zero;
    cloud2 = one;
}
else if Sum(OneAndTwo, barsGoBack) > Sum(zeroAndOne,barsGoBack) and Sum(OneAndTwo, barsGoBack) > Sum(twoAndThree,barsGoBack) and Sum(OneAndTwo, barsGoBack) > Sum(negZeroAndOne,barsGoBack) and Sum(OneAndTwo, barsGoBack) > Sum(negoneAndTwo,barsGoBack) and Sum(OneAndTwo, barsGoBack) > Sum(negtwoAndThree,barsGoBack){
    cloud1 = one;
    cloud2 = two;
}
else if Sum(twoAndThree, barsGoBack) > Sum(zeroAndOne,barsGoBack) and Sum(twoAndThree, barsGoBack) > Sum(oneAndTwo,barsGoBack) and Sum(twoAndThree, barsGoBack) > Sum(negZeroAndOne,barsGoBack) and Sum(twoAndThree, barsGoBack) > Sum(negoneAndTwo,barsGoBack) and Sum(twoAndThree, barsGoBack) > Sum(negtwoAndThree,barsGoBack){
    cloud1 = two;
    cloud2 = three;
}
else if Sum(negZeroAndOne, barsGoBack) > Sum(zeroAndOne,barsGoBack) and Sum(negZeroAndOne, barsGoBack) > Sum(oneAndTwo,barsGoBack) and Sum(negZeroAndOne, barsGoBack) > Sum(twoAndThree,barsGoBack) and Sum(negZeroAndOne, barsGoBack) > Sum(negoneAndTwo,barsGoBack) and Sum(negZeroAndOne, barsGoBack) > Sum(negtwoAndThree,barsGoBack){
    cloud1 = zero;
    cloud2 = negOne;
}
else if Sum(negoneAndTwo, barsGoBack) > Sum(zeroAndOne,barsGoBack) and Sum(negoneAndTwo, barsGoBack) > Sum(oneAndTwo,barsGoBack) and Sum(negoneAndTwo, barsGoBack) > Sum(twoAndThree,barsGoBack) and Sum(negoneAndTwo, barsGoBack) > Sum(negZeroAndOne,barsGoBack) and Sum(negoneAndTwo, barsGoBack) > Sum(negtwoAndThree,barsGoBack){
    cloud1 = negOne;
    cloud2 = negTwo;
}
else if Sum(negtwoAndThree, barsGoBack) > Sum(zeroAndOne,barsGoBack) and Sum(negtwoAndThree, barsGoBack) > Sum(oneAndTwo,barsGoBack) and Sum(negtwoAndThree, barsGoBack) > Sum(twoAndThree,barsGoBack) and Sum(negtwoAndThree, barsGoBack) > Sum(negZeroAndOne,barsGoBack) and Sum(negtwoAndThree, barsGoBack) > Sum(negOneAndTwo,barsGoBack){
    cloud1 = negTwo;
    cloud2 = negThree;
}
else {
    cloud1 = Double.nan;
    cloud2 = Double.nan;
}
AddCloud(cloud1, cloud2, color.light_red, color.light_green);


plot BullSignal = if (cloud1 == one or cloud2 == one or cloud1 == two or cloud2 == two or cloud1 == three or cloud2 ==three) and (VScore <= 0.3 and Vscore[1] >0) and CCI() > -100 then -2 else Double.nan;

plot BearSignal = if (cloud1 == negOne or cloud2 == negOne or cloud1 == negTwo or cloud2 == negTwo or cloud1 == negThree or cloud2 ==negThree) and (VScore >= 0.3 and Vscore[1] < 0) and CCI() < 100 then 2 else Double.nan;

BullSignal.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
BearSignal.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
BullSignal.SetLineWeight(3);
BearSignal.SetLineWeight(3);

input soundAlertsOn = no;
Alert((cloud1 == one or cloud2 == one or cloud1 == two or cloud2 == two or cloud1 == three or cloud2 == three) and (VScore <= 0 and VScore[1] > 0) and (SoundAlertsOn), "Bullish VScore Entry", Alert.BAR);
Alert((cloud1 == negOne or cloud2 == negone or cloud1 == negtwo or cloud2 == negtwo or cloud1 == negthree or cloud2 == negthree) and (VScore >= 0 and VScore[1] < 0)and (SoundAlertsOn), "Bearish VScore Entry", Alert.BAR);
 
Thanks, BenTen... Yes, I have also seen that script and video... Both the code by Mobius and TOS Indicators gives ideas to work from but I need to add some additional bells and whistles... I'll plug away at it but I'm in no rush...
 
Thanks, BenTen... Yes, I have also seen that script and video... Both the code by Mobius and TOS Indicators gives ideas to work from but I need to add some additional bells and whistles... I'll plug away at it but I'm in no rush...

Very anxious to see what you come up with. Tempted to do it myself as well as I like this idea for trading, but I'll wait for your undoubtedly superior product to what I'd make.

In case you haven't thought of it, you might want to start with the bollinger band code and just change the middle line to be VWAP, then add additional outside lines for different deviations away from vwap. At least, that's how I'd do it, but I'm pretty new to coding.
 
@TraderKevin Thanks for the comments... I'm actually taking ideas from several different scripts and adding in some useful features... One item that I am currently testing is clipping extremes to maintain scale of the lower indicator... I'm not as concerned about how far the extremes go, just that they have reached my maximum intended levels... I am most interested in 1 - 2 deviations and currently have clipping limits set at 3 deviations but will be making the deviation levels user-adjustable...

I am including an image of a very rough first draft that needs a lot more work... As you can see, when the Zscore line reaches +3 it is clipped and flat-lines along the top... For my needs I don't need to see if it spikes to 4 or 5 deviations, just that it has reached my preferred maximum... I may include the ability to turn clipping off however...

12FMo3x.jpg
 
Looks like a good start! The clipping is a good feature. Personally, I will probably only use the indicator on the chart itself, rather than a lower study... that way I can see more directly when price reaches certain levels and never lose focus on what matters most: price action.

For anyone interested, I went ahead and edited the built in VWAP study to include plots of 3 different standard deviations from VWAP, as seen in the OP's video. The 3 standard deviation band seems incredibly strong, as one would expect, though it's rarely touched.

Code:
input numDevDn = -1.0;
input numDevUp = 1.0;
input numDevDn2 = -2.0;
input numDevUp2 = 2.0;
input numDevDn3 = -3.0;
input numDevUp3 = 3.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 VWAP = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;
plot UpperBand2 = price + numDevUp2 * deviation;
plot LowerBand2 = price + numDevDn2 * deviation;
plot UpperBand3 = price + numDevUp3 * deviation;
plot LowerBand3 = price + numDevDn3 * deviation;

VWAP.setDefaultColor(Color.CYAN);
UpperBand.setDefaultColor(Color.LIGHT_GRAY);
LowerBand.setDefaultColor(Color.LIGHT_GRAY);
UpperBand2.setDefaultColor(Color.RED);
LowerBand2.setDefaultColor(Color.LIGHT_GREEN);
UpperBand3.setDefaultColor(Color.DARK_RED);
LowerBand3.setDefaultColor(Color.DARK_GREEN);
 
Status
Not open for further replies.

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

Thread starter Similar threads Forum Replies Date
T VWAP MA Trades -1st 2hrs Questions 0
S Close greater than VWAP ETH Questions 2
W Advanced VWAP Questions 8
Z Moving Average Cross When Above VWAP Questions 1
P Prior Day VWAP Questions 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
250 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