VWAP  [SOLVED]

Questions about MultiCharts and user contributed studies.
stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

VWAP

Postby stefanols » 10 May 2016

Hi,

I am using a multiday VWAP but I not get the settings right.

I jwould like to create a 2 day VWAP. E.g. for yesterday and today.

Hope someone can help me.

Settings enclosed

Best regards

Stefan
Attachments
Skärmklipp.PNG
(8.36 KiB) Downloaded 3704 times

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 10 May 2016

Here is how the chart looks like.

It should be like a 2 day avg of intraday vwap. Volume weighted of course.

Or what am I missing.

Have to tried to fill in correct days in the beginning and in the end.
Attachments
2 day vwap OMX fut.png
(80.26 KiB) Downloaded 3697 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: VWAP

Postby TJ » 10 May 2016

Here is how the chart looks like.

It should be like a 2 day avg of intraday vwap. Volume weighted of course.

Or what am I missing.

Have to tried to fill in correct days in the beginning and in the end.
Go to format study,

Make sure the scaling is the same as instrument.

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 10 May 2016

In the enclosed image the instrument is set as you suggest.

Must be something else.

Best regards

Stefan

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: VWAP

Postby TJ » 10 May 2016

In the enclosed image the instrument is set as you suggest.

Must be something else.

Best regards

Stefan
Which code are you using?
Did you do any modifications?
Have you tried with more data?

I can't help you with so little information.


There are many discussions on VWAP. You can do a search on this forum.

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 10 May 2016

Hi,
Appreciate your help. Probably something simple on my side.
I have increased to 250 days back. Some issue.
Below you find the code. No modifications.

Code: Select all

input:
Price(AvgPrice),
LocalHrsOffset(0),
date1(1160509),
time1(0900),
date2(1160510),
time2(1730),
date3(0),
time3(0),
date4(0),
time4(0),
date5(0),
time5(0),
upColor(Cyan),
dnColor(Magenta);

var:
var0(0);
var0 = VWAPResettableDT(Price,LocalHrsOffset,date1,time1,date2,time2,date3,time3,date4,time4,date5,time5);
plot1(var0,"vwap_reset");

var: var1(yellow);
if var0 > var0[1] then var1 = upColor;
if var0 < var0[1] then var1 = dnColor;
SetPlotColor(1,var1);
Thanks in advance.

Best regards Stefan

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 13 May 2016

.... not tested solution :

Function : MultiDayVwap

Code: Select all

input : StartDate(numericsimple);

var : PriceD(0), ShareD(0), MDV(0);

If Date < StartDate then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate then
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;

If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;
Indicator : VWAP_MultiDay (v0.1)

Code: Select all

input: Startdate(1160511);

var: var1(0);

var1 = MultidayVwap(StartDate);

Plot1(var1);
Indicator : VWAP_MultiDay (v0.2)

Code: Select all

input: Startdate(1160511);

var: var1(0);

var1 = MultidayVwap(StartDate);

if date >= startdate then
begin
Plot1(var1);
end;
May this helps.

Regards.

Ben

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 13 May 2016

Hi Ben,

Thanks for your help.

Works like a charm.

I first forgot to make sure the settings are same as instrument.

Always something.

Anyhow just as I wanted it.

Have a great week-end.

Best regards

Stefan

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 13 May 2016

Hello Stefan,

glad it works for you. Have a nice weekend. be well.

Regards.

Ben

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 15 Oct 2016

Hi,

Would appreciate if someone could tell me how to set starttime to be the same as for the startdate.
Now it does not work. E.g. if I could like to have a 2 day vwap starting the day before yesterday 1161013 and time 19:00 (the same day 20161113).

Below is the code for the function.

Thanks in advance. Stefan

Code: Select all

input : StartDate(numericsimple),StartTime(numericsimple);

var : PriceD(0), ShareD(0), MDV(0);

If Date < StartDate and Time < StartTime then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate and Time >= StartTime then
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;

If ShareD > 0 then MDV = PriceD/ShareD;

SO_VWAPmultiDay = MDV;


User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 15 Oct 2016

Hi,

Would appreciate if someone could tell me how to set starttime to be the same as for the startdate.
Now it does not work. E.g. if I could like to have a 2 day vwap starting the day before yesterday 1161013 and time 19:00 (the same day 20161113).

Below is the code for the function.

Thanks in advance. Stefan

Code: Select all

input : StartDate(numericsimple),StartTime(numericsimple);

var : PriceD(0), ShareD(0), MDV(0);

If Date < StartDate and Time < StartTime then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate and Time >= StartTime then
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;

If ShareD > 0 then MDV = PriceD/ShareD;

SO_VWAPmultiDay = MDV;

Your code does not reach your goal because in that code you can have a condition with a date >= startdate and a time < StartTime. In that case the function does not work as you would like it does.
You should define multiple condition with date > STartDate and at the same time Time< StartTime and Time >= StartTime to make it work

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 15 Oct 2016

Is following code going into the direction you want ?

Modified function of MultiDayVWAP named MultiDayVwap_1

Code: Select all

input : StartDate(numericsimple), StartTime(numericsimple);

var : PriceD(0), ShareD(0), PrevPriceD(0), PrevShareD(0), MDV(0), barcount(0);

If Date < StartDate then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date = StartDate and Time >= StartTime then // Start calculating VWAP for StartDate only(!!!) with
begin // Time >= Starttime as defined
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;

barCount = barCount + 1;

If Date > StartDate then // Start calculating VWAP younger than Startdate without
begin // restriction for StartTime
barCount = barCount + 1; // Count bars for current day
PrevPriceD = PriceD[1]; // Move over last PriceD value from prev day to current day
PrevPriceD = ShareD[1]; // Move over last ShareD value from prev day to current day
if Mod(barCount,1) = 0 then // Start calculations on current day
begin
if barcount <=1 then // Include prev day end data for PriceD & ShareD
begin // only for the 1st bar of the session !!!!!
PriceD = PriceD + PrevPriceD;
ShareD = ShareD + PrevShareD;
end
else
if barcount > 1 then // Start normal calculation vor VWAP data
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;
end;

end;



If ShareD > 0 then MDV = PriceD/ShareD; // Calculation of VWAP

MultiDayVwap_1 = MDV;
modified Indicator w/Time input

Code: Select all

input: Startdate(1160511), Starttime(1130);

var: var1(0), barcount(0);

var1 = MultidayVwap_1(StartDate, StartTime);

Plot1(var1);
Screenshot
Image

If you have any question please do not hesitate to ask.


Kind Regards.

Ben

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 15 Oct 2016

Hi Ben,

Thanks this is just what I meant.

It almost works as planned.

Have troubles to get it to work before the date e.g 1161013 and 0900.

Before that time it compress the chart and it looks like it calculates backwards.
It should start to calculate from the time and date and nothing backwards.

I enclose an image. Probably something simple.

Made no changes to function but the indicator small formatting. See below.
same problem if I take your original code with no changes.

Thanks again and best regards

Stefan

Code: Select all


input: Startdate(1161013), Starttime(1130),upColor(Cyan),dnColor(Magenta);

var: var1(0), barcount(0);

var1 = SO_VWAP01(StartDate, StartTime);

var: var2(yellow);


Plot1(var1);


if var1 > var1[1] then var2 = upColor;
if var1 < var1[1] then var2 = dnColor;
SetPlotColor(1,var2);

If (close crosses over var1) then alert ("VWAP cross up");
If (close crosses below var1) then alert ("VWAP cross down");
Attachments
vwap before start date yellow line1.png
(54 KiB) Downloaded 3575 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 15 Oct 2016

You need to load higher data range in your chart setup. Load 10 days back to start with.

Kind Regards.

Ben

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 15 Oct 2016

You can simplify the code in a shorten way without needed to load several days to plot it.
you don't need a counter or other conditions. "Keep it simple" and it will work anyway

MultiDayVWAP function

Code: Select all

input : StartDate(numericsimple), startTime(numericsimple);

var : PriceD(0), ShareD(0), MDV(0);


If Date < StartDate and Time_s < StartTime then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate and Time_s >= StartTime then // first day of VWAP with Time_s > StartTime
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;
if (Date > StartDate and Time_s <= StartTime) or
(Date > StartDate and Time_s >= StartTime) then begin // days after first dateTime

PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;


If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;
Multiday VWAP Indicator

Code: Select all

input: Startdate(1160511), StartTime(80000); // time mus be in TiME_S format

var: MultiDay.VWAP(0);

MultiDay.VWAP = MultidayVwap(StartDate, startTime);

if date >= startdate and
time_s >= startTime then
begin
Plot1(MultiDay.VWAP);
end;
Image
Attachments
2016-10-15_18-11-15.jpg
(290.27 KiB) Downloaded 3572 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 15 Oct 2016

You can simplify the code in a shorten way without needed to load several days to plot it.
you don't need a counter or other conditions. "Keep it simple" and it will work anyway

MultiDayVWAP function

Code: Select all

input : StartDate(numericsimple), startTime(numericsimple);

var : PriceD(0), ShareD(0), MDV(0);


If Date < StartDate and Time_s < StartTime then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate and Time_s >= StartTime then // first day of VWAP with Time_s > StartTime
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;
if (Date > StartDate and Time_s <= StartTime) or
(Date > StartDate and Time_s >= StartTime) then begin // days after first dateTime

PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;


If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;
Multiday VWAP Indicator

Code: Select all

input: Startdate(1160511), StartTime(80000); // time mus be in TiME_S format

var: MultiDay.VWAP(0);

MultiDay.VWAP = MultidayVwap(StartDate, startTime);

if date >= startdate and
time_s >= startTime then
begin
Plot1(MultiDay.VWAP);
end;
CrazyNasdaq, with all respect to your hard work and reprehension, please think about your logic in the code again not only in regards to simplicity and shortness, but correctness in terms of solving the issue and please try your code on your own platform. On mine it looks like this :

Image

Maybe I am just wrong. For sure there will be shorter, more elegant solutions to solve the thread openers issue. No doubt about that.

Kind Regards

Ben

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 15 Oct 2016

CrazyNasdaq, with all respect to your hard work and reprehension, please think about your logic in the code again and please try your code on your own platform.
You have to use "Time_s" format NOT "Time" format, as I've specified in the code

Code: Select all

input: Startdate(1160511), StartTime(80000); // time must be in TiME_S format
so 21:00 become 210000 NOT 2100 in the inputs settings

Yes, you're right that after the first day you can set the condition string as

Code: Select all

if Date > StartDate then begin .....
Without time settings

On my end, if I set the time in the "TIME_S" format the indicator works right as I've posted in my previous post and image.

My Final function shorter then before (No counter or other condition) is:

Code: Select all

input : StartDate(numericsimple), startTime(numericsimple); // time in Time_s format

var : PriceD(0), ShareD(0), MDV(0);

If Date < StartDate and Time_s < StartTime then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate and Time_s >= StartTime then // first day of VWAP with Time_s > StartTime
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;
if Date > StartDate then begin // days after first dateTime
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;

If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 15 Oct 2016

CrazyNasdaq, with all respect to your hard work and reprehension, please think about your logic in the code again and please try your code on your own platform.
You have to use "Time_s" format NOT "Time" format, as I've specified in the code

Code: Select all

input: Startdate(1160511), StartTime(80000); // time must be in TiME_S format
so 21:00 become 210000 NOT 2100 in the inputs settings

Yes, you're right that after the first day you can set the condition string as

Code: Select all

if Date > StartDate then begin .....
Without time settings

On my end, if I set the time in the "TIME_S" format the indicator works right as I've posted in my previous post and image.

My Final function shorter then before (No counter or other condition) is:

Code: Select all

input : StartDate(numericsimple), startTime(numericsimple); // time in Time_s format

var : PriceD(0), ShareD(0), MDV(0);

If Date < StartDate and Time_s < StartTime then
Begin
PriceD = 0;
ShareD = 0;
End;

If Date >= StartDate and Time_s >= StartTime then // first day of VWAP with Time_s > StartTime
begin
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;
if Date > StartDate then begin // days after first dateTime
PriceD = PriceD + (AvgPrice*(UpTicks+DownTicks));
ShareD = ShareD + (UpTicks+DownTicks);
end;

If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;

I deleted my comments about specific parts of your code in my previous comment.

Regarding your new code I still do not see why it should work correctly. First why it is necessary to use Time_s if there is no specific request for it (tick, range charts etc). You still overwrite one if >= then with another if > then statement, so it won't work at all .... You have to take over the data from the end of the <Startday> to the dates after the <Startday> with different conditions. I do not see it in your code.

Still looks not correct after copying your code ....

Image

Best Regards

Ben

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 16 Oct 2016

Thanks Ben for your effort.

I tried you updated code and it works when I set scaling to movement size but not same as instrument.
With same as instrument it has the same behaviour that before the starting date where the indicator should not show anything it is compressing the chart and has a line off the expected value.

I already had 100 days of data loaded so that was not the cause that is did not work.

Thanks again best regards Stefan

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 16 Oct 2016

Still looks not correct after copying your code ....
Ben
With all respect Bensat, maybe (1) or you have a wrong setting of your chart or (2) you have copied in a wrong way the code or (3) you set in a wrong way the inputs settings af date and time, because in your charts my code start always at the beginning of the day ad it's impossible because the code sets a specific start condition :
- date must be equal or higher of begin date (date in format 1161011 for October the 11 of 2016)
- time must be equal or higher of start day on the first day and time could be each time on the days after the first date (startDate). (time in time_s format to use seconds and not only minutes)
The start condition is the same as your code

Code: Select all

If Date >= StartDate and Time_s >= StartTime then begin
So the question is: " why on your charts my code starts always at the beginning of the day/session ?"
Here is a link to a video https://sendvid.com/rn63mu3a where you can watch that the code starts perfectly at the beginng of the start time. The magenta line/Vwap is my code, the Blue/Vwap is Bensat code and is evident that the blue code does not weight correctly the market movments because the average of the price marktes weighted for the volume does not follow the market movments and create a difference.
I use Time_s (in seconds) instead of Time (in minutes) because your code does not work on charts different from time basis (contract bars, Volume bars, tick bars, range bars and so on). With "Time" instead of "Time_s" you can use your code only on minutes or hourly charts.
The logic is very simple ....... a start condition based on a specific time and date and the same cumulative calculation after that starting point. No any other conditions are required, so why make it more complicated than what it should be ? Few lines of code for the "core conditions".
It's only a cumulative weighted moving average which starts after a starting point sets with a Date/time

Code: Select all

If Date < StartDate and Time_s < StartTime then //rest conditon to zero
Begin
PriceD = 0;
ShareD = 0;
End;
If Date >= StartDate and Time_s >= StartTime then //Start condition
begin
PriceD = PriceD + (AvgPrice*ticks);
ShareD = ShareD + ticks;
end;
If Date > StartDate then //each bar after the DATE start condition
begin
PriceD = PriceD + (AvgPrice*ticks);
ShareD = ShareD + ticks;
end;
If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;
Image

VIDEO Link https://sendvid.com/rn63mu3a
My Best regards
CrazyNasdaq
Attachments
2016-10-16_09-51-24.jpg
(339 KiB) Downloaded 3566 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 16 Oct 2016

Still looks not correct after copying your code ....
Ben
With all respect Bensat, maybe (1) or you have a wrong setting of your chart or (2) you have copied in a wrong way the code or (3) you set in a wrong way the inputs settings af date and time, because in your charts my code start always at the beginning of the day ad it's impossible because the code sets a specific start condition :
- date must be equal or higher of begin date (date in format 1161011 for October the 11 of 2016)
- time must be equal or higher of start day on the first day and time could be each time on the days after the first date (startDate). (time in time_s format to use seconds and not only minutes)
The start condition is the same as your code

Code: Select all

If Date >= StartDate and Time_s >= StartTime then begin
So the question is: " why on your charts my code starts always at the beginning of the day/session ?"
Here is a link to a video https://sendvid.com/rn63mu3a where you can watch that the code starts perfectly at the beginng of the start time. The magenta line/Vwap is my code, the Blue/Vwap is Bensat code and is evident that the blue code does not weight correctly the market movments because the average of the price marktes weighted for the volume does not follow the market movments and create a difference.
I use Time_s (in seconds) instead of Time (in minutes) because your code does not work on charts different from time basis (contract bars, Volume bars, tick bars, range bars and so on). With "Time" instead of "Time_s" you can use your code only on minutes or hourly charts.
The logic is very simple ....... a start condition based on a specific time and date and the same cumulative calculation after that starting point. No any other conditions are required, so why make it more complicated than what it should be ? Few lines of code for the "core conditions".
It's only a cumulative weighted moving average which starts after a starting point sets with a Date/time

Code: Select all

If Date < StartDate and Time_s < StartTime then //rest conditon to zero
Begin
PriceD = 0;
ShareD = 0;
End;
If Date >= StartDate and Time_s >= StartTime then //Start condition
begin
PriceD = PriceD + (AvgPrice*ticks);
ShareD = ShareD + ticks;
end;
If Date > StartDate then //each bar after the DATE start condition
begin
PriceD = PriceD + (AvgPrice*ticks);
ShareD = ShareD + ticks;
end;
If ShareD > 0 then MDV = PriceD/ShareD;

MultiDayVwap = MDV;
Image

VIDEO Link https://sendvid.com/rn63mu3a
My Best regards
CrazyNasdaq
I tested it again. This time I set the <Starttime> at 113000 with <Startdate> 1161011.

If your code is correct than please explain why your code weights the current <ShareD> and <PriceD> twice every morning from <Starttime> 113000 till session end beginning from the day after <Startdate> ??? From this day after the startday at 1130 the difference between our VWAPS starts and increases till session end. At the following day, without your code weighting the current <ShareD> & <PriceD) twice till 1130, the difference between our VWAP values decreases and starts to increase again after 1130. My code does not weigh the <PriceD> and <ShareD> beginning from day after the Startdate twice, which should be correct.

Your MultiDayVWAP still delivers false values. This explains the different weightings from your VWAP. You could already recognize the source of the difference from your screenshot. I know the solution and you may find it as well quickly . You had many chances to overlook your code preciesly and check the results from the VWAP values, so I think the error was not forced by accident. Yes, your code is shorter and as I said no doubt about that. I use my solution in other projects with including/excluding bars, weighing different sessions and bars etc.

Screenshot 1
Image

Screenshot 2
Image

Screenshot 3
Image

Screenshot 4
Image

Screenshot 5
Image

I maybe look embarrassing at the end and I am really wrong. But I take the shot.

Kind Regards.

Ben

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 16 Oct 2016

There is a very "simple, short and easy" correction to do in the code which solve all the problems without introducing to many complications and counter or others.......
Take out the major simbol ( " > ") from the start condition and use only the equal condition (" = ") for the first day.
So the first line of the start condition from this

Code: Select all

If Date >= StartDate and Time_s >= StartTime then begin
became this

Code: Select all

If Date = StartDate and Time_s >= StartTime then begin
The rest is the same as above, easy, simple and quick without the need to make some research through datafeed then through excel and spend unnecessary time to solve. Just a look at the code one more time to avoid the twice weighted. My first logic is " make it simple if you can ".
All my respect to your work and contribute

Kind Regards
CrazyNasdaq

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 16 Oct 2016

There is a very "simple, short and easy" correction to do in the code which solve all the problems without introducing to many complications and counter or others.......
Take out the major simbol ( " > ") from the start condition and use only the equal condition (" = ") for the first day.
So the first line of the start condition from this

Code: Select all

If Date >= StartDate and Time_s >= StartTime then begin
became this

Code: Select all

If Date = StartDate and Time_s >= StartTime then begin
The rest is the same as above, easy, simple and quick without the need to make some research through datafeed then through excel and spend unnecessary time to solve. Just a look at the code one more time to avoid the twice weighted. My first logic is " make it simple if you can ".
All my respect to your work and contribute

Kind Regards
CrazyNasdaq
I for sure disagree !!!

With the '-easy -simple -short -quick -I don't care' attitude I would have to falsely accept my VWAP solution is wrong, yours is right and the thread opener would have a wrong solution with a wrong VWAP and might would have taken wrong decisions in trading with real money. And how I would have the chance to provide you the evidence that your code had errors ? With words .... ?

So there is always the need to make extra research and take extra time to solve problems and to have evidence that our solutions are correct. To accept this is an '-easy -simple -short -quick' concession to make.

I look like an ass for you guys, but it paid off not to give up and to check it several times. Have a nice Sunday guys and thank you for the great discussion 'CrazyNasdaq'. I really appreciate it.

Kind Regards

Ben


PS: During the research I came up with the question why the PriceD calculated qith the equation AvgPrice * ticks or (upticks + downticks) in most cases does not show the value it should provide us? Avgprice is set as (O+H+L+C)*0.25 .... Maybe no one realized so far

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 16 Oct 2016

All my respect to your work and contribute

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

VWAP

Postby stefanols » 18 Oct 2016

Thanks for your effort and explanations. Much appreciated.
Seems that VWAP multiday can be a bit tricky.

I am slowly getting there.

Have one ussue though.

I have enclosd a short film clip showing when I put time from e.g yesterday after current time today it does not include this data.

I am using 110000 for 11:00. Should be correct for time_s?

Best regards

Stefan
Attachments
VWAP_2016-10-18_0858.zip
(776.83 KiB) Downloaded 207 times

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 18 Oct 2016

Sorry Stefanols, but the video doesn't show any time scale or other. it's cropped to watch only a portion of the screen and this way it's incompresible

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 18 Oct 2016

Hi,

Hope that this shows it better.

it is Bensats code I am using.

Thanks for your effort as well CrNa.

Best regards

Stefan
Attachments
vwap_2016-10-18_1207.zip
(1.58 MiB) Downloaded 193 times

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 18 Oct 2016

Hi,

Hope that this shows it better.

it is Bensats code I am using.

Thanks for your effort as well CrNa.

Best regards

Stefan
Try to plot a VWAP from a starting date before today (example 1161017 or before) and a time after your actual time. For example if your actual time is 12:20 am try to plot the VWAP starting form 1161017 (date before today) and time after the 12:20 (for example 15:00 or later).
Then try the same thing but with a time before your actual time for example 11:10 ore before
If the problem is the same as showed in your video, probably there is something wrong in that code for each bar time after your actual time and date = today date.
It's simply a test

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 18 Oct 2016

Hi,

As you see in the video that is exactly what I have done.

Perhaps Bensat can shed some light on it.

90000=09:00
140000=14:00

It is 12:30 now in Sweden.

Best regards

Stefan

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 18 Oct 2016

@Stefan

My recorded attempt to reproduce the issue > https://vimeo.com/187819147

In the vid I can't reproduce the issue. Please can you provide your current code exported in a pla-file. Only issue can be some copied code got mixed with a version from the discussion and ....

Code: Select all

if Date > Startdate and Time_s <= StartTime .....
Something like that. I will take a look in your code.

Kind Regards

Ben

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 18 Oct 2016

Thanks for your tips. I corrected some but still does not work.

I exported the pla files.

Thanks for looking at it.

Best regards

Stefan
Attachments
MultidayVWAP.pla
(5.52 KiB) Downloaded 464 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 18 Oct 2016

@Stefan

Sorry to say this, but this is not the correct and not my code as you reported.

I mod the function code with <CrazyNasdaq>'s version, as this is shorter code and mod the indicator to the correct version. I tried it here on my end and it works. As suggested the mistake was in the indicator with ....

Code: Select all

.... and time_s <= StartTime then
If you have any further questions just give us a sign.

Kind Regards

Ben
Attachments
modMultiDayVWAP.pla
(5.25 KiB) Downloaded 522 times
Last edited by bensat on 18 Oct 2016, edited 1 time in total.

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 18 Oct 2016

Hi,

It should be your code with some formatting though.

Would appreciate if you could export your code in pla so my base line.

I use ticks so it looks strange further back.

Thanks in advance.

Best regards

Stefan

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP

Postby bensat » 18 Oct 2016

Hi,

:

I use ticks so it looks strange further back.

:
What looks strange ? Please find attached the code you wanted.

Kind Regards

Ben
Attachments
modMultiDayVWAP_1.pla
(7.48 KiB) Downloaded 515 times

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 18 Oct 2016

Hi,

I have imported the file and it caluculates as it should from the date and time.

However if I scroll backwards it sets VWAP to 0 and it makes the charts impossible to read.

It it only my charts that behaves like that or yours as well if you scroll back 2-10 days?

Thanks in advance.

Check the short video to get a better understanding.

Best regards

Stefan
Attachments
vwap_2016-10-18_2023.zip
(1.79 MiB) Downloaded 201 times

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 18 Oct 2016

It it only my charts that behaves like that or yours as well if you scroll back 2-10 days?
Stefan

copy this string where you have the Plot1 statement in the INDICATOR, ( pay attention in the indicator and NOT in the function)

Code: Select all

// Plotting VWAP
if date >= startdate and Time_s >= starttime then
begin
Plot1(MultiDay.VWAP, "MDV", color);
end;
This starts the plot only from the date and time you have specified, NOT before
Regards

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: VWAP

Postby stefanols » 18 Oct 2016

Thanks for the tip.

But then there is a time gap in the last current day.

If feels that you would need a day and time stamp joint together to better control time.

Best regards

Stefan
Attachments
VWAP MultiCharts2.png
(62.98 KiB) Downloaded 3574 times

User avatar
CrazyNasdaq
Posts: 318
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 97 times
Been thanked: 86 times

Re: VWAP

Postby CrazyNasdaq » 18 Oct 2016

Sorry, that's my fault

this is the correct string

Code: Select all

// Plotting VWAP
if date >= startdate then
begin
Plot1(MultiDay.VWAP, "MDV", color);
end;
Sorry

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: VWAP  [SOLVED]

Postby bensat » 18 Oct 2016

@CrazyNasdaq

No it's not your fault as the correct version was discussed earlier and he just copied it wrong and did not change it. Besides that the whole <if .... then> is not necessary, as its already defined in the function.

@Stefan

I lost track. I exported 2 versions for you, both working without any issues here on my end. So please can you explain the new issue again. I do not get it anymore.

Both indicator versions fed from 2 different functions ... Functions are ok, indicator is ok, plots are ok. Must be on your end or implementation.

Image

Kind Regards

Ben


Return to “MultiCharts”