VWAP bands study

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

VWAP bands study

Postby arnie » 27 Apr 2013

Since there's no real VWAP study built in MC, this is a workable one.
Only for RTH sessions.
Bands are identical to Investor/RT and SC.

Code: Select all

{This study is derived from the one found here:
   http://www.tradersxchange.com/viewtopic.php?f=51&t=538}
   
// http://www.multicharts.com/discussion/viewtopic.php?f=5&t=16154

// VWAP Bands

// For RTH session only

// 04-15-2013: added color inputs
// 04-20-2013: added ShowHistory input
// 04-27-2013: added previous VWAP and previoud VWAP "value area"

Inputs:
   ShowVWAPhistory         (false),
   ColorVWAP            (rgb(178,34,34)),
   Show1stDev            (true),
   Color1stDev            (rgb(13,40,16)),
   Show2ndDev            (true),
   Color2ndDev            (rgb(205,102,0)),
   Show3rdDev            (true),
   Color3rdDev            (rgb(51,51,51)),
   Show4thDev            (true),
   Color4thDev            (rgb(139,119,101)),
   ShowPrevVWAP            (false),
   ShowPrevVWAPHistory         (false),
   PrevVWAPColor            (rgb(178,34,34)),      
   PrevDevColor            (rgb(205,102,0));      
   
Variables:
   haveStart             (false),
   PriceW               (0),
   ShareW               (0),
   Vari               (0),
   VolWAPVariance         (0),
   VolWAPsd            (0),
   VWAPval            (0),
   VolWAPValue            (0),
   stdDev1stUp            (0),
   stdDev1stDn            (0),
   stdDev2ndUp            (0),
   stdDev2ndDn            (0),
   stdDev3rdUp            (0),
   stdDev3rdDn            (0),
   stdDev4thUp            (0),
   stdDev4thDn            (0),
   prevVWAPValue            (0),
   prevstdDev2ndUp         (0),
   prevstdDev2ndDn         (0);
   
If Date <> Date[1] then begin
   haveStart = true;
   PriceW = 0;
   ShareW = 0;
   VolWAPValue = 0;
   vari = 0;
      
   prevVWAPValue = VWAPval;
   prevstdDev2ndUp = stdDev2ndUp;
   prevstdDev2ndDn = stdDev2ndDn;
end;

If haveStart then begin
   Pricew = PriceW + (Close * (UpTicks + DownTicks));
   ShareW = ShareW + (UpTicks + DownTicks);

   if ShareW > 0 then
       VolWAPValue = PriceW / ShareW;

   VWAPval = VolWAPValue;

   Vari = Vari + (UpTicks + DownTicks) * (close - VolWAPValue) * (close - VolWAPValue); 
   VolWAPVariance = Vari * (.25 / ShareW) ;

   VolWAPsd = SquareRoot(VolWAPVariance);

   stdDev1stUp = VolWAPValue + VolWAPSD;
   stdDev1stDn = VolWAPValue - VolWAPSD;
   stdDev2ndUp = VolWAPValue + (2 * VolWAPSD);
   stdDev2ndDn = VolWAPValue - (2 * VolWAPSD);
   stdDev3rdUp = VolWAPValue + (3 * VolWAPSD);
   stdDev3rdDn = VolWAPValue - (3 * VolWAPSD);
   stdDev4thUp = VolWAPValue + (4 * VolWAPSD);
   stdDev4thDn = VolWAPValue - (4 * VolWAPSD);
      
   if ShowVWAPHistory = true or (ShowVWAPHistory = false and (LastCalcDate = Date)) then begin
         Plot1(VolWAPValue, "VWAP", ColorVWAP);
   
      if Show1stDev then begin
         Plot3(stdDev1stUp, "VWAP1SDUp", Color1stDev);
         Plot4(stdDev1stDn, "VWAP1SDDown", Color1stDev);
      end;

      if Show2ndDev then begin
         Plot5(stdDev2ndUp, "VWAP2SDUp", Color2ndDev);
         Plot6(stdDev2ndDn, "VWAP2SDDown", Color2ndDev);
      end;

      if Show3rdDev then begin
         Plot7(stdDev3rdUp, "VWAP3SDDUp", Color3rdDev);
         Plot8(stdDev3rdDn, "VWAP3SDDown", Color3rdDev);
      end;

      if Show4thDev then begin
         Plot9(stdDev4thUp, "VWAP4SDUp", Color4thDev);
         Plot10(stdDev4thDn, "VWAP4SDDown", Color4thDev);
      end;
   end;
      
   if ShowPrevVWAP = true then begin
      if ShowPrevVWAPHistory = true or (ShowPrevVWAPHistory = false and (LastCalcDate = Date)) then begin
         if prevVWAPValue <> 0 then
            plot11(prevVWAPValue, "prevVWAP", PrevVWAPColor);
         if prevstdDev2ndUp <> 0 then
            plot12(prevstdDev2ndUp, "prevDev2ndUp", PrevDevColor);
         if prevstdDev2ndDn <> 0 then
            plot13(prevstdDev2ndDn, "prevDev2ndDn", PrevDevColor);
      end;
   end;
end;




Image
Attachments
VWAP_bands.png
VWAP_bands.png (61.67 KiB) Viewed 1974 times

User avatar
arnie
Posts: 1589
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 478 times
Been thanked: 509 times

Re: VWAP bands study

Postby arnie » 12 Mar 2015

Here is a version that can plot RTH or ETH, depending the session template you choose.

Code: Select all

Inputs:
   VWAPcalc            (close),//close, high, low, avgprice
   ShowPrevVWAP            (true),
   ShowPrevVWAPdev         (true),
   ShowVWAP            (true),
   Show1stDev            (false),
   Show2ndDev            (true),
   Show3rdDev            (false),
   Show4thDev            (false),
   ColorVWAP            (rgb(178,34,34)),
   Color1stDev            (rgb(13,40,16)),
   Color2ndDev            (rgb(170,85,28)),
   Color3rdDev            (rgb(51,51,51)),
   Color4thDev            (rgb(139,119,101)),
   PrevVWAPColor            (rgb(24,116,205)),
   PrevDevColor            (rgb(24,116,205));

      
Variables:
   CurrentSess            (0),
   PriceW               (0),
   ShareW               (0),
   Vari               (0),
   VolWAPVariance         (0),
   VolWAPsd            (0),
   VWAPval            (0),
   VolWAPValue            (0),
   stdDev1stUp            (0),
   stdDev1stDn            (0),
   stdDev2ndUp            (0),
   stdDev2ndDn            (0),
   stdDev3rdUp            (0),
   stdDev3rdDn            (0),
   stdDev4thUp            (0),
   stdDev4thDn            (0),
   prevVWAPValue            (0),
   prevstdDev2ndUp         (0),
   prevstdDev2ndDn         (0);

// track the current session
CurrentSess = CurrentSession(0) ;

// we have a session change
if CurrentSess <> CurrentSess[1] then
begin
   // reset VWAP variables on a new session
   PriceW = 0;
   ShareW = 0;
   VolWAPValue = 0;
   vari = 0;
   
   //set previous session VWAP and 2nd stddev
   prevVWAPValue = VWAPval;
   prevstdDev2ndUp = stdDev2ndUp;
   prevstdDev2ndDn = stdDev2ndDn;
end;
 
 
// VWAP calculations
Pricew = PriceW + (VWAPcalc * (UpTicks + DownTicks));
ShareW = ShareW + (UpTicks + DownTicks);

if ShareW > 0 then
    VolWAPValue = PriceW / ShareW;

VWAPval = VolWAPValue;

Vari = Vari + (UpTicks + DownTicks) * (VWAPcalc - VolWAPValue) * (VWAPcalc - VolWAPValue); 
VolWAPVariance = Vari * (.25 / ShareW) ;

VolWAPsd = SquareRoot(VolWAPVariance);

// VWAP standard deviations bands
stdDev1stUp = VolWAPValue + VolWAPSD;
stdDev1stDn = VolWAPValue - VolWAPSD;
stdDev2ndUp = VolWAPValue + (2 * VolWAPSD);
stdDev2ndDn = VolWAPValue - (2 * VolWAPSD);
stdDev3rdUp = VolWAPValue + (3 * VolWAPSD);
stdDev3rdDn = VolWAPValue - (3 * VolWAPSD);
stdDev4thUp = VolWAPValue + (4 * VolWAPSD);
stdDev4thDn = VolWAPValue - (4 * VolWAPSD);

// Plot VWAP lines
if ShowVWAP then
   Plot1(VolWAPValue, "VWAP", ColorVWAP);

if Show1stDev then begin
   Plot3(stdDev1stUp, "VWAP1SDUp", Color1stDev);
   Plot4(stdDev1stDn, "VWAP1SDDown", Color1stDev);
end;

if Show2ndDev then begin
   Plot5(stdDev2ndUp, "VWAP2SDUp", Color2ndDev);
   Plot6(stdDev2ndDn, "VWAP2SDDown", Color2ndDev);
end;

if Show3rdDev then begin
   Plot7(stdDev3rdUp, "VWAP3SDDUp", Color3rdDev);
   Plot8(stdDev3rdDn, "VWAP3SDDown", Color3rdDev);
end;

if Show4thDev then begin
   Plot9(stdDev4thUp, "VWAP4SDUp", Color4thDev);
   Plot10(stdDev4thDn, "VWAP4SDDown", Color4thDev);
end;

if ShowPrevVWAP = true then begin
   if prevVWAPValue <> 0 then
      plot11(prevVWAPValue,"prevVWAP",PrevVWAPColor);
end;

if ShowPrevVWAPdev = true then begin   
   if prevstdDev2ndUp <> 0 then
      plot12(prevstdDev2ndUp,"prevDevUp",PrevDevColor);
   if prevstdDev2ndDn <> 0 then
      plot13(prevstdDev2ndDn,"prevDevDn",PrevDevColor);
end;

trade4life
Posts: 1
Joined: 21 Mar 2015

Re: VWAP bands study

Postby trade4life » 21 Mar 2015

This looks just the ticket but i cannot compile it in MC.NET

I get errors line 1 and 44 for some reason and i am not a programmer so dont have a clue.
Can you advise how to get working?

Cheers

A

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: VWAP bands study

Postby TJ » 21 Mar 2015

trade4life wrote:This looks just the ticket but i cannot compile it in MC.NET
I get errors line 1 and 44 for some reason and i am not a programmer so dont have a clue.
Can you advise how to get working?
Cheers
A

This is not for MC.NET.

This code is written in EasyLanguage, it is for the regular version of MultiCharts.


Return to “User Contributed Studies and Indicator Library”