Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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:
Can you help answer these questions from other members on NexusFi?
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.