NexusFi: Find Your Edge


Home Menu

 





TradingView help in improving Anchored Vwap


Discussion in TradingView

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




 
Search this Thread
  #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: 39

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:	257
Size:	82.2 KB
ID:	315338  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
Commodities
Expiration Day: Wall Street Rallies on Peace Hopes While …
Prediction Markets & Event Contracts
The Ceasefire Curve: 2pct Peace by Next Week, 60pct by S …
Prediction Markets & Event Contracts
Khamenei Vetoes Uranium Transfer as Peace Odds Surge to …
Prediction Markets & Event Contracts
Powell in 48 Hours: Word Markets Give 78% on Inflation, …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
The Confluence Meter: A Multi-Layered Signal Framework B …
17 thanks
NT8 color choices
11 thanks
MES Trader Journal & Market Structure Discussion
9 thanks
500 MES points a week
8 thanks
  #2 (permalink)
 JayMay 
Toronto Ontario/Canada
 
Experience: Beginner
Platform: Tradingview
Trading: stocks, gold
Posts: 2 since Sep 2012
Thanks Given: 0
Thanks Received: 2

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


© 2026 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 - Downloads - Top
no new posts