category Trend  at 09/02/2020

VWAP

Description

// -------------------------------------------------------------------------------------------------

//

//    VWAP (Volume Weighted Average Price) = Cumulative(Typical Price x Volume) / Cumulative(Volume)

//    by Zaknafein Z

//

//    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.EasternStandardTime, 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...");

        }

    }

}


using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Blank : Indicator
    {
        protected override void Initialize()
        {
            ChartObjects.DrawText("AlgoDeveloper", "Please download this indicator from AlgoDeveloper.com", StaticPosition.Center, Colors.Red);
        }

        public override void Calculate(int index)
        {
        }
    }
}


LP
lp_tp

Joined 11.02.2019

  • Type: free
  • Language: C#
  • Trading Platform: cTrader Automate
  • Filename: Blank.algo
  • Rating: 5
  • Downloads: 1596
Comments
Only logged in users can post a comment
Comments not found