Adding moving average to Tick Volume

Created at 19 Aug 2020, 18:39
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SA

samuelbreezey

Joined 10.04.2019

Adding moving average to Tick Volume
19 Aug 2020, 18:39


Hi guys

I am wanting to add the moving average indicator to my tick volume indicator which calculates the average tick volume price.

Is this possible? My code is below:

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeMM : Indicator
    {

        [Output("UpVolume", Color = Colors.Green, PlotType = PlotType.Histogram, Thickness = 1)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", Color = Colors.Red, PlotType = PlotType.Histogram, Thickness = 1)]
        public IndicatorDataSeries DownVolume { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = MarketSeries.TickVolume[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
        }
    }
}

 

I would love some help on the code or if someone could send me in the right direction.

I look forward to hearing from you guys

Sam

 


@samuelbreezey
Replies

samuelbreezey
20 Aug 2020, 00:57

RE:

samuelbreezey said:

Hi guys

I am wanting to add the moving average indicator to my tick volume indicator which calculates the average tick volume price.

Is this possible? My code is below:

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeMM : Indicator
    {

        [Output("UpVolume", Color = Colors.Green, PlotType = PlotType.Histogram, Thickness = 1)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", Color = Colors.Red, PlotType = PlotType.Histogram, Thickness = 1)]
        public IndicatorDataSeries DownVolume { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = MarketSeries.TickVolume[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
        }
    }
}

 

I would love some help on the code or if someone could send me in the right direction.

I look forward to hearing from you guys

Sam

 

Just need the calculation...

 

Have added the MA:

 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeTheMinimalTrader : Indicator
    {

        [Output("UpVolume", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries DownVolume { get; set; }

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

        [Output("Moving Average Colour", LineColor = "Turquoise")]
        public IndicatorDataSeries MAColour { get; set; }

        private IndicatorDataSeries MAVol;
        private MovingAverage volumeMA;

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            MAVol = CreateDataSeries();
            volumeMA = Indicators.MovingAverage(MAVol, Periods, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = Bars.TickVolumes[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
        }
    }
}

 


@samuelbreezey

PanagiotisCharalampous
20 Aug 2020, 08:06

Hi Sam,

See an example below

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeTheMinimalTrader : Indicator
    {

        [Output("UpVolume", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries DownVolume { get; set; }

        [Output("MA", LineColor = "Blue", PlotType = PlotType.Line, Thickness = 4)]
        public IndicatorDataSeries MA { get; set; }

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

        private MovingAverage volumeMA;

        protected override void Initialize()
        {
            // Initialize and create nested indicators    
            volumeMA = Indicators.MovingAverage(Bars.TickVolumes, Periods, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = Bars.TickVolumes[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
            MA[index] = volumeMA.Result[index];
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

samuelbreezey
20 Aug 2020, 10:49

RE:

PanagiotisCharalampous said:

Hi Sam,

See an example below

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeTheMinimalTrader : Indicator
    {

        [Output("UpVolume", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries DownVolume { get; set; }

        [Output("MA", LineColor = "Blue", PlotType = PlotType.Line, Thickness = 4)]
        public IndicatorDataSeries MA { get; set; }

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

        private MovingAverage volumeMA;

        protected override void Initialize()
        {
            // Initialize and create nested indicators    
            volumeMA = Indicators.MovingAverage(Bars.TickVolumes, Periods, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = Bars.TickVolumes[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
            MA[index] = volumeMA.Result[index];
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 

Thank you Panagiotis,

Is there a way to show the indicator on the actual chart?

Sam


@samuelbreezey

ctid5083541
16 Mar 2023, 21:03

RE: RE:Is there a way to show the indicator on the actual chart?

samuelbreezey said:

PanagiotisCharalampous said:

Hi Sam,

See an example below

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TickVolumeTheMinimalTrader : Indicator
    {

        [Output("UpVolume", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries UpVolume { get; set; }

        [Output("DownVolume", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 4)]
        public IndicatorDataSeries DownVolume { get; set; }

        [Output("MA", LineColor = "Blue", PlotType = PlotType.Line, Thickness = 4)]
        public IndicatorDataSeries MA { get; set; }

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

        private MovingAverage volumeMA;

        protected override void Initialize()
        {
            // Initialize and create nested indicators    
            volumeMA = Indicators.MovingAverage(Bars.TickVolumes, Periods, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            UpVolume[index] = Bars.TickVolumes[index];
            if (UpVolume[index] < UpVolume[index - 1])
                DownVolume[index] = UpVolume[index];
            else
                DownVolume[index] = 0;
            MA[index] = volumeMA.Result[index];
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 

Thank you Panagiotis,

Is there a way to show the indicator on the actual chart?

Sam

It works if you have the indicator on the "Target Framework: .NET Framework 4.x".


@ctid5083541