Category Volatility  Published on 12/10/2018

vWap + Deviation + History-cut

Description

this is a cut-out of our indicator SwingFish-Intra.. showing the vWap only.

PLEASE NOTE, This Indicator is an Older version !!
the new version is available for Free at https://www.swingfish.trade/vwap-forex

you can also get there the SwingFish-Intra Indicator (also free): https://www.swingfish.trade/swingfish-intra

the main feature is to cut the history down to the charts do not shrink during the day.

plus vWap is for entries/exits, so seeing historical data makes little sense anyway.

Standard vWap


here is a sample of the SwingFish-Intra Indicator that includes the vWap (among other things)


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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    //TimeZone = TimeZones.UTC
    public class IntraDayStandardDeviation : Indicator
    {
        [Parameter("Offset Reset time", DefaultValue = 0)]
        public int TimeOffset { get; set; }

        [Output("Upper SD", Color = Colors.Gray, PlotType = PlotType.Points)]
        public IndicatorDataSeries SD3Pos { get; set; }

        [Output("Lower SD", Color = Colors.Gray, PlotType = PlotType.Points)]
        public IndicatorDataSeries SD3Neg { get; set; }

        [Output("VWAP", LineStyle = LineStyle.Dots, Thickness = 2, Color = Colors.Yellow)]
        public IndicatorDataSeries VWAP { get; set; }

        [Parameter("Show Diviation Lines", DefaultValue = false)]
        public bool ShowDiviation { get; set; }

        [Parameter("Show vWap History", DefaultValue = false)]
        public bool ShowHistoricalvWap { get; set; }

        //       [Parameter("Use OHLC", DefaultValue = false)]
        //       public bool UseOHLC { get; set; }

        [Parameter("Corner for Infos", DefaultValue = 1, MinValue = 0, MaxValue = 4)]
        public int corner { get; set; }

        //       private int end_bar = 0;
        private int start_bar = 0;
        private int oldCurrentDay = 0;

        public StaticPosition corner_position;
        public int CurrentDay = 0;

        public override void Calculate(int index)
        {
            switch (corner)
            {
                case 1:
                    corner_position = StaticPosition.TopLeft;
                    break;
                case 2:
                    corner_position = StaticPosition.TopRight;
                    break;
                case 3:
                    corner_position = StaticPosition.BottomLeft;
                    break;
                case 4:
                    corner_position = StaticPosition.BottomRight;
                    break;
            }
            int end_bar = index;
            int CurrentDay = MarketSeries.OpenTime[end_bar].DayOfYear;
            double TotalPV = 0;
            double TotalVolume = 0;
            double highest = 0;
            double lowest = 999999;
            double close = MarketSeries.Close[index];

            if (CurrentDay == oldCurrentDay)
            {
                for (int i = start_bar; i <= end_bar; i++)
                {
                    TotalPV += MarketSeries.TickVolume[i] * ((MarketSeries.Low[i] + MarketSeries.High[i] + MarketSeries.Close[i]) / 3);
                    TotalVolume += MarketSeries.TickVolume[i];
                    VWAP[i] = TotalPV / TotalVolume;

                    if (MarketSeries.High[i] > highest)
                    {
                        highest = MarketSeries.High[i];
                    }
                    if (MarketSeries.Low[i] < lowest)
                    {
                        lowest = MarketSeries.Low[i];
                    }

                    double SD = 0;
                    for (int k = start_bar; k <= i; k++)
                    {

                        double HLC = (MarketSeries.High[k] + MarketSeries.Low[k] + MarketSeries.Close[k]) / 3;
                        double OHLC = (MarketSeries.High[k] + MarketSeries.Low[k] + MarketSeries.Open[k] + MarketSeries.Close[k]) / 4;

                        double avg = HLC;
                        double diff = avg - VWAP[i];
                        SD += (MarketSeries.TickVolume[k] / TotalVolume) * (diff * diff);
                    }

                    SD = Math.Sqrt(SD);

                    if (corner != 0)
                        ChartObjects.DrawText("show", "vWap " + Math.Round(VWAP[index], 5), corner_position);

                    if (ShowDiviation)
                    {
//                        ChartObjects.DrawText("sda", "SD: " + (SD), 0);
//                        ChartObjects.DrawText("sdb", "SD: " + (VWAP[index]), 0);
//                        ChartObjects.DrawText("sdc", "SD: " + (close), 0);

                        double SD_Pos = VWAP[i] + SD;
                        double SD_Neg = VWAP[i] - SD;
                        double SD2Pos = SD_Pos + SD;
                        double SD2Neg = SD_Neg - SD;

                        SD3Pos[i] = SD2Pos + SD;
                        SD3Neg[i] = SD2Neg - SD;
                    }
                    if (!ShowHistoricalvWap)
                    {
                        //  VWAP[index] = sum / start_bar - i;
                        if (i < index - 15)
                        {
                            VWAP[i] = double.NaN;
                        }
                    }
                }
            }
            else
            {
                if (!ShowHistoricalvWap)
                {
                    for (int i = index - 16; i <= index; i++)
                    {
                        VWAP[i] = double.NaN;
                    }
                }
                oldCurrentDay = MarketSeries.OpenTime[end_bar].DayOfYear;
                start_bar = end_bar - TimeOffset;
            }

            return;
        }
    }
}


swingfish's avatar
swingfish

Joined on 25.06.2016

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