NexusFi: Find Your Edge


Home Menu

 





TradingView help in improving Anchored Vwap


Discussion in Platforms and Indicators

Updated
    1. trending_up 7,279 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 1 attachments




 
Search this Thread

TradingView help in improving Anchored Vwap

  #1 (permalink)
 foreverlearner 
Rio de Janeiro. Brazil.
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Trading: Emini ES
Posts: 30 since Sep 2019
Thanks Given: 10
Thanks Received: 37

I am trying to create a Anchored VWAP for Trading view, but the problem is, it is not consistent when moving to a higher timeframe.

Trading View has a native drawing tool for Anchored Vwap, and it works consistently.

Example: If I plot my AVwap on the 14/April/2021 at 4am (4 hour chart) if I go up to a daily chart my AVwap will move to the 15th, but TV's AVwap Drawing tool works correctly at 14th. If I go to the weekly chart, my AVwap goes to the 19th, but native Drawing tool goes to the week 12th (which is correct).

What should I change in my code for it to work as the native drawing tool does?

This is my code:

 
Code
//@version=4
study("My Midas VWAP TimeStamp", shorttitle="MY MIDAS TS", overlay=true)

showmidas01=input(true, title="Show Midas")

startBar01 = input(timestamp('14 Apr 2021 04:00 -0400'), '#1 Start Time', type=input.time)
mid01=  true //input(true, title=" Show Midas 1 Line" )

startmidas01 = time >= startBar01 and time[1] < startBar01

v01 = na(volume) ? 1 : volume
cumV01= cum(v01)
CumPV01= cum(hl2*v01)

startV01 = valuewhen(startmidas01, cumV01[1], 0)
StartPV01 = valuewhen(startmidas01, CumPV01[1], 0)

Midas01 = (CumPV01-StartPV01)/(cumV01-startV01)

middle01 = plot(mid01 and showmidas01? Midas01:na, title="Midas 1", color=color.aqua,linewidth=2)

Attached Thumbnails
Click image for larger version

Name:	AnchoredVwap-TS.png
Views:	160
Size:	82.2 KB
ID:	315338  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 JayMay 
Toronto Ontario/Canada
 
Experience: Beginner
Platform: Tradingview
Trading: stocks, gold
Posts: 2 since Sep 2012
Thanks Given: 0
Thanks Received: 1

Your script identifies a specific point in time (timestamp) for the plot session to initiate. If a bar opens at the same time as your timestamp then the MIDAS/anchored VWAP will be initiated at the same time as your timestamp. If the bar does not open at the same time as your timestamp then the MIDAS/anchored VWAP will be initiated on the next bar open.
To compensate you should have the script query the timeframe and then initiate the MIDAS/anchored VWAP one bar earlier in time. If you move to a weekly chart the initiating time must be moved back in time by one week.
I have added a line to address your specific request. I have not coded in any exceptions, that is to say, what if the timestamp is exactly at the starting point of a daily and/or weekly bar. The script will still subtract the daily or weekly time equivalent, which is not what you want. You might well be able to address this particular exception by using the following line as an alternate to the one I inserted below: startBar01=timeframe.isweekly?startBar_01 - (1000*7*24*60*60)+ 1000:timeframe.isdaily?startBar_01 - (1000*24*60*60)+1000:startBar_01. I have not tested it.
Also, I changed the plot colour to navy so that you can see the different plots.

// foreverlearner with input by jayy

//@version=4
study("Midas anchored VWAP TimeStamp", shorttitle="MIDAS TS", overlay=true)

showmidas01=input(true, title="Show Midas")

startBar_01 = input(timestamp('14 Apr 2021 04:00 -0400'), '#1 Start Time', type=input.time)
mid01= true //input(true, title=" Show Midas 1 Line" )
startBar01=timeframe.isweekly?startBar_01 - (1000*7*24*60*60):timeframe.isdaily?startBar_01 - (1000*24*60*60):startBar_01
startmidas01 = time >= startBar01 and time[1] < startBar01

v01 = na(volume) ? 1 : volume
cumV01= cum(v01)
CumPV01= cum(hl2*v01)

startV01 = valuewhen(startmidas01, cumV01[1], 0)
StartPV01 = valuewhen(startmidas01, CumPV01[1], 0)

Midas01 = (CumPV01-StartPV01)/(cumV01-startV01)

middle01 = plot(mid01 and showmidas01? Midas01:na, title="Midas 1", color=color.navy,linewidth=2)

Reply With Quote
Thanked by:




Last Updated on August 4, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts