VWAP Periodic Close [LuxAlgo] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
bMEXloe.png


Author Message:

The VWAP Periodic Close script offers an advanced tool for analyzing the Volume Weighted Average Price (VWAP) across various timeframes.

This tool enables traders to visualize VWAP close levels for daily, weekly, monthly, quarterly, and yearly periods, offering a comprehensive view of price behavior across different time frames. It helps in identifying key levels where the VWAP closes at the end of each specified period.

CODE:

CSS:
#// Indicator for TOS
#// © LuxAlgo
#indicator("VWAP Periodic Close [LuxAlgo]", 'LuxAlgo - VWAP Periodic Close', true)
# Converted by Sam4Cok@Samer800     - 09/2024

input LineLabelOffse = 5;
input showDailyLabels = yes;
input showDailyVwapOrigin = yes;
input dailySource = hlc3;
input noOfDailyVwap = 3;
input showWeeklyLabels = yes;
input showWeeklyVwapOrigin = yes;
input weeklySource = hlc3;
input noOfWeeklyVwap = 2;
input showMonthlyLabels = yes;
input showMonthlyVwapOrigin = yes;
input monthlySource = hlc3;
input noOfMonthlyVwap = 1;

def na = Double.NaN;
def last = IsNaN(open);
def x = (if isNaN(x[1]) then 0 else x[1]) + 1;
def noD = Min(Max(noOfDailyVwap, 0), 3);
def noW = Min(Max(noOfWeeklyVwap, 0), 3);
def noM = Min(Max(noOfMonthlyVwap, 0), 3);
def dayClose = open(Period = "DAY");
def weekClose = open(Period = "WEEK");
def monthClose = open(Period = "MONTH");
def closeDay = if !last then dayClose else closeDay[1];
def closeWEEK = if !last then weekClose else closeWEEK[1];
def closeMONTH = if !last then monthClose else closeMONTH[1];
def day = closeDay != closeDay[1];
def week = closeWEEK != closeWEEK[1];
def month = closeMONTH != closeMONTH[1];

script f_Vwap {
    input source = hlc3;
    input anchor = yes;
    def src = source;
    def src_v = if isNaN(volume) then 1 else volume;
    def volSrc = src_v * src;
    def volumeSum = if anchor then src_v else
                    if(!volumeSum[1], src_v, volumeSum[1]) + src_v;
    def volumeVwapSum = if anchor then volSrc else
                    if(!volumeVwapSum[1],volSrc, volumeVwapSum[1]) + volSrc;
    def price = volumeVwapSum / volumeSum;
    plot wap = price;
}
def vwapDay = f_Vwap(dailySource, day);
def vwapWeek = f_Vwap(weeklySource, week);
def vwapMonth = f_Vwap(monthlySource, month);

Script vwapLines {
input vwapDay = vwap;
input anchor = no;
input show = 3;
    def x = (if isNaN(x[1]) then 0 else x[1]) + 1;
    def daily1; def daily2; def daily3;
    def dailyX1; def dailyX2; def dailyX3;def dailyX4;
if anchor {
    daily3 = daily2[1];
    daily2 = daily1[1];
    daily1 = vwapDay;
    dailyX4 = dailyX3[1];
    dailyX3 = dailyX2[1];
    dailyX2 = dailyX1[1];
    dailyX1 = X;
    } else {
    daily3 = daily3[1];
    daily2 = daily2[1];
    daily1 = daily1[1];
    dailyX4 = dailyX4[1];
    dailyX3 = dailyX3[1];
    dailyX2 = dailyX2[1];
    dailyX1 = dailyX1[1];
}
    plot l1 = if show>0 then daily1 else Double.NaN;
    plot l2 = if show>1 then highestAll(InertiaAll(daily2, 2)) else Double.NaN;
    plot l3 = if show>2 then highestAll(InertiaAll(daily3, 2)) else Double.NaN;
    plot x1 = if show>0 then dailyX1 else Double.NaN;
    plot x2 = if show>0 then dailyX2 else Double.NaN;
    plot x3 = if show>1 then dailyX3 else Double.NaN;
    plot x4 = if show>2 then dailyX4 else Double.NaN;
}
#-- Daily
def daily1 = vwapLines(vwapDay[1], day, noD).l1;
def daily2 = vwapLines(vwapDay[1], day, noD).l2;
def daily3 = vwapLines(vwapDay[1], day, noD).l3;
def dailyX1 = vwapLines(vwapDay[1], day, noD).x1;
def dailyX2 = vwapLines(vwapDay[1], day, noD).x2;
def dailyX3 = vwapLines(vwapDay[1], day, noD).x3;
def dailyX4 = vwapLines(vwapDay[1], day, noD).x4;
def condDaily1 = x >= highestAll(dailyX1);
def condDaily2 = x >= highestAll(dailyX2);
def condDaily3 = x >= highestAll(dailyX3);
def condDaily4 = x >= highestAll(dailyX4);
def condDaily11 = !condDaily1 and condDaily2;
def condDaily22 = !condDaily2 and condDaily3;
def condDaily33 = !condDaily3 and condDaily4;
#-- weekly
def weekly1 = vwapLines(vwapWeek[1], week, noW).l1;
def weekly2 = vwapLines(vwapWeek[1], week, noW).l2;
def weekly3 = vwapLines(vwapWeek[1], week, noW).l3;
def weeklyX1 = vwapLines(vwapWeek[1], week, noW).x1;
def weeklyX2 = vwapLines(vwapWeek[1], week, noW).x2;
def weeklyX3 = vwapLines(vwapWeek[1], week, noW).x3;
def weeklyX4 = vwapLines(vwapWeek[1], week, noW).x4;
def condWeekly1 = x >= highestAll(weeklyX1);
def condWeekly2 = x >= highestAll(weeklyX2);
def condWeekly3 = x >= highestAll(weeklyX3);
def condWeekly4 = x >= highestAll(weeklyX4);
def condWeekly11 = !condWeekly1 and condWeekly2;
def condWeekly22 = !condWeekly2 and condWeekly3;
def condWeekly33 = !condWeekly3 and condWeekly4;
#-- Monthly
def monthly1 = vwapLines(vwapMonth[1], month, noM).l1;
def monthly2 = vwapLines(vwapMonth[1], month, noM).l2;
def monthly3 = vwapLines(vwapMonth[1], month, noM).l3;
def monthlyX1 = vwapLines(vwapMonth[1], month, noM).x1;
def monthlyX2 = vwapLines(vwapMonth[1], month, noM).x2;
def monthlyX3 = vwapLines(vwapMonth[1], month, noM).x3;
def monthlyX4 = vwapLines(vwapMonth[1], month, noM).x4;
def condMonthly1 = x >= highestAll(monthlyX1);
def condMonthly2 = x >= highestAll(monthlyX2);
def condMonthly3 = x >= highestAll(monthlyX3);
def condMonthly4 = x >= highestAll(monthlyX4);
def condMonthly11 = !condMonthly1 and condMonthly2;
def condMonthly22 = !condMonthly2 and condMonthly3;
def condMonthly33 = !condMonthly3 and condMonthly4;


plot d1 = if !last[LineLabelOffse] then if condDaily1[-1] and daily1[-1] then daily1[-1] else na else na;
plot d2 = if !last[LineLabelOffse] then if condDaily2[-1] then daily2[-1] else na else na;
plot d3 = if !last[LineLabelOffse] then if condDaily3[-1] then daily3[-1] else na else na;
plot d11 = if showDailyVwapOrigin then if condDaily11 then vwapDay else na else na;
plot d22 = if showDailyVwapOrigin then if condDaily22 then vwapDay else na else na;
plot d33 = if showDailyVwapOrigin then if condDaily33 then vwapDay else na else na;

plot w1 = if !last[LineLabelOffse] then if condWeekly1[-1] and weekly1[-1] then weekly1[-1] else na else na;
plot w2 = if !last[LineLabelOffse] then if condWeekly2[-1] then weekly2[-1] else na else na;
plot w3 = if !last[LineLabelOffse] then if condWeekly3[-1] then weekly3[-1] else na else na;
plot w11 = if showWeeklyVwapOrigin then if condWeekly11 then vwapWeek else na else na;
plot w22 = if showWeeklyVwapOrigin then if condWeekly22 then vwapWeek else na else na;
plot w33 = if showWeeklyVwapOrigin then if condWeekly33 then vwapWeek else na else na;

plot m1 = if !last[LineLabelOffse] then if condMonthly1[-1] and monthly1[-1] then monthly1[-1] else na else na;
plot m2 = if !last[LineLabelOffse] then if condMonthly2[-1] then monthly2[-1] else na else na;
plot m3 = if !last[LineLabelOffse] then if condMonthly3[-1] then monthly3[-1] else na else na;
plot m11 = if showMonthlyVwapOrigin then if condMonthly11 then vwapMonth else na else na;
plot m22 = if showMonthlyVwapOrigin then if condMonthly22 then vwapMonth else na else na;
plot m33 = if showMonthlyVwapOrigin then if condMonthly33 then vwapMonth else na else na;

d1.SetLineWeight(2);
d2.SetLineWeight(2);
d3.SetLineWeight(2);
d1.SetDefaultColor(Color.CYAN);
d2.SetDefaultColor(Color.CYAN);
d3.SetDefaultColor(Color.CYAN);
d11.SetDefaultColor(Color.CYAN);
d22.SetDefaultColor(Color.CYAN);
d33.SetDefaultColor(Color.CYAN);

w1.SetLineWeight(2);
w2.SetLineWeight(2);
w3.SetLineWeight(2);
w1.SetDefaultColor(Color.YELLOW);
w2.SetDefaultColor(Color.YELLOW);
w3.SetDefaultColor(Color.YELLOW);
w11.SetDefaultColor(Color.YELLOW);
w22.SetDefaultColor(Color.YELLOW);
w33.SetDefaultColor(Color.YELLOW);

m1.SetLineWeight(2);
m2.SetLineWeight(2);
m3.SetLineWeight(2);
m1.SetDefaultColor(Color.RED);
m2.SetDefaultColor(Color.RED);
m3.SetDefaultColor(Color.RED);
m11.SetDefaultColor(Color.RED);
m22.SetDefaultColor(Color.RED);
m33.SetDefaultColor(Color.RED);

AddChartBubble(showDailyLabels and isNaN(d1) and !isNaN(d1[1]), daily1, "D1", Color.CYAN);
AddChartBubble(showDailyLabels and isNaN(d2) and !isNaN(d2[1]), daily2, "D2", Color.CYAN);
AddChartBubble(showDailyLabels and isNaN(d3) and !isNaN(d3[1]), daily3, "D3", Color.CYAN);

AddChartBubble(showWeeklyLabels and isNaN(w1) and !isNaN(w1[1]), weekly1, "W1", Color.YELLOW);
AddChartBubble(showWeeklyLabels and isNaN(w2) and !isNaN(w2[1]), weekly2, "W2", Color.YELLOW);
AddChartBubble(showWeeklyLabels and isNaN(w3) and !isNaN(w3[1]), weekly3, "W3", Color.YELLOW);

AddChartBubble(showMonthlyLabels and isNaN(m1) and !isNaN(m1[1]), monthly1, "M1", Color.RED);
AddChartBubble(showMonthlyLabels and isNaN(m2) and !isNaN(m2[1]), monthly2, "M2", Color.RED);
AddChartBubble(showMonthlyLabels and isNaN(m3) and !isNaN(m3[1]), monthly3, "M3", Color.RED);
#-- END of CODE
 

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