Category Oscilators  Published on 05/08/2023

Volume Price Momentum indicator

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

The Volume Price Momentum Oscillator combines volume and price momentum.

You can use this indicator as a measure of trading sentiment: go Long when above the bands, and go Short when below the bands.

You can also find the Compare Price Momentum Oscillator at the following link: https://ctrader.com/algos/indicators/show/3561




mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mVolumePriceMomentum.algo
  • Rating: 5
  • Installs: 462
Comments
Log in to add a comment.
mfejza's avatar
mfejza · 10 months ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mVolumePriceMomentum : Indicator
    {
        [Parameter("Periods (2)", DefaultValue = 2)]
        public int inpPeriods { get; set; }
        [Parameter("BB Period (200)", DefaultValue = 200, Group = "Bands")]
        public int inpPeriodBB { get; set; }
        [Parameter("BB Deviation (0.618)", DefaultValue = 0.618, Group = "Bands")]
        public double inpStddevBB { get; set; }
        [Parameter("BB Smooth Type (sma)", DefaultValue = MovingAverageType.Simple, Group = "Bands")]
        public MovingAverageType inpSmoothTypeBB { get; set; }

        [Output("Volume Price Momentum Oscillator", IsHistogram = false, LineColor = "Black", LineStyle = LineStyle.Solid, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outVPMo { get; set; }
        [Output("Bands Up", LineColor = "LightBlue", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBup { get; set; }
        [Output("Bands Down", LineColor = "LightBlue", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBdn { get; set; }
        [Output("Bands Middle", LineColor = "LightBlue", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBmid { get; set; }
        
        private IndicatorDataSeries _vpm, _vpmo;
        private MovingAverage _vpmsmooth;
        private BollingerBands _bands;
        

        protected override void Initialize()
        {
            _vpmo = CreateDataSeries();
            _vpm = CreateDataSeries();
            _vpmsmooth = Indicators.MovingAverage(_vpm, inpPeriods, MovingAverageType.Exponential);
            _bands = Indicators.BollingerBands(_vpmsmooth.Result, inpPeriodBB, inpStddevBB, inpSmoothTypeBB);
        }

        public override void Calculate(int i)
        {
            _vpm[i] = Bars.TickVolumes[i] * (i>1 ? Bars.ClosePrices[i] - Bars.ClosePrices[i-1] : Bars.ClosePrices[i] - Bars.TypicalPrices[i]);
            _vpmo[i] = _vpmsmooth.Result[i];
            
            outVPMo[i] = _vpmo[i];
            outBBup[i] = _bands.Top[i];
            outBBdn[i] = _bands.Bottom[i];
            outBBmid[i] = _bands.Main[i];
        }
    }
}