Category Oscilators  Published on 13/08/2023

Compare Price Momentum Oscillator

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

In the article The Compare Price Momentum Oscillator (CPMO), author Vitali Apirine reintroduces us to the DecisionPoint PMO, originally developed by Carl Swenlin, and presents a new way to use it for comparing the relative momentum of two different securities. 

Trading signals can be derived in several ways, including momentum, signal line, and zero-line crossovers.

One of the most advanced and statistically productive strategies is to utilize the cross components for going Long when above the zero value, and for going Short when below the zero value.

You can also find the Volume Price Momentum indicator at the following link: https://ctrader.com/algos/indicators/show/3543




mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mComparePriceMomentumOscillator.algo
  • Rating: 5
  • Installs: 500
  • Modified: 13/08/2023 11:30
Comments
Log in to add a comment.
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mComparePriceMomentumOscillator : Indicator
    {
        [Parameter("Fast Period (20)", DefaultValue = 20)]
        public int inpPeriodFast { get; set; }
        [Parameter("Slow Period (35)", DefaultValue = 35)]
        public int inpPeriodSlow { get; set; }
        [Parameter("Signal Period (10)", DefaultValue = 10)]
        public int inpPeriodSignal { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }
        [Parameter("Output Result (fast)", DefaultValue = enumOutputResult.Smooth)]
        public enumOutputResult inpOutputResult { get; set; }

        [Output("Price Momentum", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outPMO { get; set; }
        [Output("Price Signal", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outSignal { get; set; }
        
        private IndicatorDataSeries _price, _pmo;
        private PriceROC _roc;
        private ExponentialMovingAverage _rocsmooth1, _rocsmooth2, _pmosignal;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _roc = Indicators.PriceROC(_price, 1);
            _rocsmooth1 = Indicators.ExponentialMovingAverage(_roc.Result, inpPeriodSlow);
            _rocsmooth2 = Indicators.ExponentialMovingAverage(_rocsmooth1.Result, inpPeriodFast);
            _pmosignal = Indicators.ExponentialMovingAverage((inpOutputResult == enumOutputResult.Fast ? _rocsmooth1.Result : _rocsmooth2.Result), inpPeriodSignal);
            _pmo = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            
            outPMO[i] = (inpOutputResult == enumOutputResult.Fast ? _rocsmooth1.Result[i] : _rocsmooth2.Result[i]) / Symbol.PipSize;
            outSignal[i] = _pmosignal.Result[i] / Symbol.PipSize;
        }
    }

    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
    
    public enum enumOutputResult
    {
        Fast,
        Smooth
    }
}