Category Trend  Published on 21/06/2019

VWAP with Daily, Weekly and Monthly WAPS

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them.

This is a modified version of the VWAP that shows also weekly and monthly VWAPS.


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AutoRescale = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class VWAP : Indicator
    {
        [Parameter("VWAP", DefaultValue = true)]
        public bool vwap { get; set; }
        [Parameter("WWAP", DefaultValue = false)]
        public bool wwap { get; set; }
        [Parameter("MWAP", DefaultValue = false)]
        public bool mwap { get; set; }

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

        private TypicalPrice typ;
        public IndicatorDataSeries tpv;

        public double CTPV, CV;

        protected override void Initialize()
        {
            CTPV = 0;
            CV = 0;
            typ = Indicators.TypicalPrice();
            tpv = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            tpv[index] = typ.Result[index] * MarketSeries.TickVolume[index];
            CTPV = 0;
            CV = 0;

            int per = 0;

            if (vwap && !wwap && !mwap)
            {
                int day = MarketSeries.OpenTime[index].Day;
                while (MarketSeries.OpenTime[index - per].Day == day)
                {
                    per++;
                    CTPV += tpv[index - per];
                    CV += MarketSeries.TickVolume[index - per];
                }
            }

            if (wwap && !mwap)
            {
                DayOfWeek currentDay = MarketSeries.OpenTime[index].DayOfWeek;

                while (MarketSeries.OpenTime[index - per].DayOfWeek <= currentDay && index - per > 0)
                {
                    //Print(index - per);
                    currentDay = MarketSeries.OpenTime[index - per].DayOfWeek;
                    per++;
                    CTPV += tpv[index - per];
                    CV += MarketSeries.TickVolume[index - per];
                }
            }

            if (mwap)
            {
                int month = MarketSeries.OpenTime[index].Month;
                while (MarketSeries.OpenTime[index - per].Month == month)
                {
                    per++;
                    CTPV += tpv[index - per];
                    CV += MarketSeries.TickVolume[index - per];
                }
            }

            Result[index] = CTPV / CV;
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: VWAP.algo
  • Rating: 0
  • Installs: 4031
Comments
Log in to add a comment.
shane.scott.pub's avatar
shane.scott.pub · 8 months ago

Doesn't show weekly or monthly on any time frame.

Maybe I'll have a peek at the code and let you know. Any tips welcome as to what you think it might be. I'm a snr C# dev so feel free to geek speak.

Thanks

 

AL
alexsanramon · 5 years ago

This indicator is great if we can only add supporting indicator like the Perfect Trend Line.

The Perfect Trend Line forex indicator is a technical tool that is based on the highest high and lowest low of two distinct periods. The Perfect Trend Line indicator is similar to the Parabolic SAR. Customization options: Variable Fast length, Slow length.

Please build this indicator for ctrader. Thanks for supporting the community.

After researching, I just found out that Telegram is better in regards of security than Discord. So lets go with Telegram.