VWAP (Volume Weighted Average Price)

by ctid418503 in category Trend at 05/05/2018
Description

I couldn't find a VWAP indicator for Ctrader so programmed one and am sharing it with the community.  There is lots of information about this indicator on-line. VWAP indicator not to be confused with VWAP execution.

Parameters deserve some explanation:

  • One day only?  If this is set to true/yes then the VWAP is only calculated and shown on the chart for the current day.  I would suggest using this setting if you are using this indicator in a cbot because performance (speed) will be improved in backtesting and optimisation.  Default: false.  When set to false you will see the VWAP day by day.  The calculation resets each day.
  • Periods.  Default: 0.  If you set a value other than 0 for this parameter it completely overrides the day or 'day by day' calculation and calculates the VWAP on a rolling basis for the the number of periods you choose.

I'll try to respond to any comments.  Also please share any good strategies you have using this indicator.

Donations welcome to:
BTC: 33gjtYhKVqFxmcbcko63WnwiVJvew3PauQ
ETH: 0xb54dF35117D94a43Ca25A3A348Ac20DF7F667F7b
LTC: M8YRuyH5USv2MvJyyF55U5ik1yMfm6TtMH

Cheers,

Meester PooPoop

Download
149 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
// -------------------------------------------------------------------------------------------------
//
//    VWAP (Volume Weighted Average Price) = Cumulative(Typical Price x Volume) / Cumulative(Volume)
//    by Meester PooPoop
//
//    Donations welcome to:
//    
//    BTC: 33gjtYhKVqFxmcbcko63WnwiVJvew3PauQ
//    ETH: 0xb54dF35117D94a43Ca25A3A348Ac20DF7F667F7b
//    LTC: M8YRuyH5USv2MvJyyF55U5ik1yMfm6TtMH
//
//    v1.0 Inital version 04/05/18
// -------------------------------------------------------------------------------------------------

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class VWAP : Indicator
    {
        [Parameter(DefaultValue = 0)]
        public int Periods { get; set; }

        [Parameter("One day only?", DefaultValue = false)]
        public bool Odo { get; set; }

        [Output("Main", Color = Colors.DarkOrchid)]
        public IndicatorDataSeries Result { get; set; }

        public override void Calculate(int index)
        {
            int ii = index;
            double CumTypPrice = 0;
            double CumVol = 0;

            if (Periods == 0)
            {
                while (MarketSeries.OpenTime[ii] >= (Odo == false ? MarketSeries.OpenTime[ii].Date : DateTime.Now.Date) && ii != 0)
                {
                    CumTypPrice += MarketSeries.Typical[ii] * MarketSeries.TickVolume[ii];
                    CumVol += MarketSeries.TickVolume[ii];
                    ii--;
                    if (MarketSeries.OpenTime[ii].Hour == 0 && MarketSeries.OpenTime[ii].Minute == 0)
                        break;
                }
            }
            else
            {
                for (; ii >= MarketSeries.OpenTime.Count - Periods; ii--)
                {
                    CumTypPrice += MarketSeries.Typical[ii] * MarketSeries.TickVolume[ii];
                    CumVol += MarketSeries.TickVolume[ii];
                }
            }

            Result[index] = CumTypPrice / CumVol;

        }

        protected override void Initialize()
        {
            Print("VWAP indicator started...");
        }
    }
}
Comments
0