Category Other  Published on 23/08/2021

Supporting VWAP

Description

This indicator is a dependency for TrendTrader6


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 VWAPs : Indicator
    {
        [Parameter("VWAP", DefaultValue = true)]
        public bool vwap { get; set; }


        [Output("Main", Color = Colors.Gray, Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
        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 = 3;

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



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


AN
andurei

Joined on 30.09.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: VWAPs.algo
  • Rating: 0
  • Installs: 1885
Comments
Log in to add a comment.
No comments found.