Hi,
I´m looking for a indicator that show 2-day VWAP on the chart. I know you can use booth the original VWAP and the anchored one and change settings to 2-days but that´s not how i think about it. The original one should show 2- days at the time, and the anchored you have to manually anchor at every day.
What I’m looking for is a model that starts a VWAP from today’s open just as the original one but doesn’t close the calculation before tomorrow´s close.
On a historical chart, you would then see the VWAP starting from each day’s opening but not closing until the next day’s close. In other words, it overlaps each other all the time. Then you can perhaps also color day 1 in one color and day 2 in another to easily separate them visually.
I´ve tried to code it myself but failed. My beginner skills is limited at the moment!
Hi
Try this
if opendate <> opendate[1] and newday=0 then
newday = 1
startbar1 = 1
elsif opendate <> opendate[1] and newday=1 then
newday = 0
startbar2 = 1
else
newday = newday
startbar1 = startbar1+1
startbar2 = startbar2+1
endif
///VWAP 1
d1 = max(1, startbar1)
VWAP1 = SUMMATION[d1](volume*typicalprice)/SUMMATION[d1](volume)
///VWAP 2
d2 = max(1, startbar2)
VWAP2 = SUMMATION[d2](volume*typicalprice)/SUMMATION[d2](volume)
RETURN VWAP2 as "Vwap2" coloured("red"), vwap1 as "Vwap1"coloured("blue")
Excellent @Iván !
Now i should try to use this indicator in a strategy with some other tools.
In a strategy for example, if i only want to to use the second day of both this vwap´s as an entry oportunity when a crossover arises (Because it´s acctuly then a 2- day VWAP arises).
How should that snippet looks like? I know the acctuly CROSSES OVER code.
Thanks in advance!
If you want for example check the cross between both vwap you could try this:
if vwap2 crosses over vwap1 then
buy 1 contract at market
endif
Thanks, but I’m aware of that.
The part of the code I’m looking for is to be able to specify so it only includes the second day. If price crosses the vwap on the first day, it is not a 2-day vwap cross but a regular one, thats not intresting. It is the second day of the 2-day vwap that is the interesting thing here.
Otherwise, you could have used the standard indicator for vwap and then that price or whatever you want crosses over with the code you attached last.
Thus, a code string that only includes crosses on the second day. That is the part of the code that is difficult for me.
Hope this make it clearer. If not, i could attach a pic to make it easier to understand.
Hi @Iván
Attached is a picture that shows what i mean.
Hope that helps.
Thank you