Category Trend  Published on 05/07/2023

VWAP with Upper and Lowerbands

Description

This is the basic VWAP Indicator. It resets daily and has 3 Upper and 3 Lower bands.



If you enjoy this Indicator feel free to buy me a coffee ^^. I wish you a great day!

 

 


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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class VWAPIndicator : Indicator
    {
        [Output("VWAP", LineColor = "Blue")]
        public IndicatorDataSeries VWAP { get; set; }

        [Output("UpperBand1", LineColor = "Green")]
        public IndicatorDataSeries UpperBand1 { get; set; }

        [Output("LowerBand1", LineColor = "Green")]
        public IndicatorDataSeries LowerBand1 { get; set; }
        
        [Output("LowerBand2", LineColor = "Olive")]
        public IndicatorDataSeries LowerBand2 { get; set; }
        
        [Output("UpperBand2", LineColor = "Olive")]
        public IndicatorDataSeries UpperBand2 { get; set; }
        
        [Output("LowerBand3", LineColor = "Teal")]
        public IndicatorDataSeries LowerBand3 { get; set; }
        
        [Output("UpperBand3", LineColor = "Teal")]
        public IndicatorDataSeries UpperBand3 { get; set; }
      

        private double cumulativeTradedValue;
        private double cumulativeVolume;
        private double cumulativeTPVDev;

        public override void Calculate(int index)
        {
            // Reset cumulative values at the start of each new day
            if (index > 0 && MarketSeries.OpenTime[index].Date != MarketSeries.OpenTime[index - 1].Date)
            {
                cumulativeTradedValue = 0;
                cumulativeVolume = 0;
                cumulativeTPVDev = 0;
            }

            double high = MarketSeries.High[index];
            double low = MarketSeries.Low[index];
            double close = MarketSeries.Close[index];
            double volume = MarketSeries.TickVolume[index];

            double tp = (high + low + close) / 3;
            double tradedValue = tp * volume;

            cumulativeTradedValue += tradedValue;
            cumulativeVolume += volume;

            VWAP[index] = cumulativeTradedValue / cumulativeVolume;

            double typPriceDev = (close - VWAP[index]) * (close - VWAP[index]);
            double tpvDev = typPriceDev * volume;

            cumulativeTPVDev += tpvDev;

            double vwapStdDev = Double.IsNaN(cumulativeTPVDev / cumulativeVolume) ? 0 : Math.Sqrt(cumulativeTPVDev / cumulativeVolume);

            UpperBand1[index] = VWAP[index] + vwapStdDev;
            LowerBand1[index] = VWAP[index] - vwapStdDev;
            UpperBand2[index] = VWAP[index] + (2*vwapStdDev);
            LowerBand2[index] = VWAP[index] - (2*vwapStdDev);
            UpperBand3[index] = VWAP[index] + (3*vwapStdDev);
            LowerBand3[index] = VWAP[index] - (3*vwapStdDev);
        }
    }
}


SC
schennis.dielke

Joined on 01.07.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: VWAP.algo
  • Rating: 5
  • Installs: 1019
Comments
Log in to add a comment.
xabbu's avatar
xabbu · 11 months ago

Danke, hab mich dort mal angemeldet.

Ich habe hier auf cTrader wohl vor 2 - 2,5 Jahren den letzten Indikator / Beitrag gepostet. Ich mache seitdem eigentlich nur noch strategyquant - aber das Programmieren in c#, wozu ich damals über nnfx gekommen bin, hat mich immer noch nicht ganz losgelassen... ;-)

 

SC
schennis.dielke · 11 months ago

Ich bin aktuell selber eigentlich nur auf den Discord server von den Subreddit r/algotrading unterwegs. Musst du einfach googlen ist leicht zu finden. Außerdem hat cTrader eine Telegram Gruppe die ich dir empfehlen kann falls du mehr auf dieser Plattform unterwegs bist.

Ich hoffe das hilft dir weiter!

xabbu's avatar
xabbu · 11 months ago

Danke - da bin ich seit langem nicht mehr aktiv... ;-)

Kennst Du vllt eine cTrader / cAlgo Discord Gruppe, gerne auch auf englisch?

Grüße,

 

Chris

SC
schennis.dielke · 11 months ago

Hey!

Nein ich komme nicht aus Solingen aber wohne in NRW und nicht allzu weit entfernt davon :). 
Ich bin leider nicht wirklich aktiv auf LinkedIn aber kann dir gerne mein Xing geben ^^.

Xing: https://www.xing.com/profile/Dennis_Schielke3

Grüße

Dennis

xabbu's avatar
xabbu · 11 months ago

Hey Dennis, are from Solingen (LinkedIn info ;-) - I'm from Cologne / Bonn... Regards Chris