Category Oscilators  Published on 06/06/2023

Midpoint Oscillator

Description

The MPO (Midpoint Oscillator) indicator displays price movement without the trend component around its centerpoint. It is represented by two lines: the price movement line and the signal line. The centerline (midpoint) represents the zero level of the oscillator.

This indicator is used to trigger events for every cross where the main component (black) is above the signal component (red). If the cross happens above zero, the bullish trigger occurs. Similarly, for every cross where the main component (black) is below the signal component (red), if the cross happens below zero, the bearish trigger occurs.

Similar indicator: ctrader.com/algos/indicators/show/3458


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

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mMPO : Indicator
    {
        [Parameter("Period (26)", DefaultValue = 26)]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Period (5)", DefaultValue = 5)]
        public int inpPeriodSmooth { get; set; }
        [Parameter("Smooth Type (sma)", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType { get; set; }

        [Output("MPO", LineColor = "Black", Thickness = 1)]
        public IndicatorDataSeries outMPO { get; set; }
        [Output("Signal", LineColor = "Red", Thickness = 1)]
        public IndicatorDataSeries outSignal { get; set; }

        private IndicatorDataSeries _hh, _ll, _mp;
        private MovingAverage _smooth;


        protected override void Initialize()
        {
            _hh = CreateDataSeries();
            _ll = CreateDataSeries();
            _mp = CreateDataSeries();
            _smooth = Indicators.MovingAverage(_mp, inpPeriodSmooth, inpSmoothType);
        }

        public override void Calculate(int i)
        {
            _hh[i] = i>inpPeriod ? Bars.HighPrices.Maximum(inpPeriod) : Bars.HighPrices[i];
            _ll[i] = i>inpPeriod ? Bars.LowPrices.Minimum(inpPeriod) : Bars.LowPrices[i];
            _mp[i] = _hh[i] != _ll[i] ? 100.0 * (2 * Bars.ClosePrices[i] - _hh[i] - _ll[i]) / (_hh[i] - _ll[i]) : 0;

            outMPO[i] = _mp[i];
            outSignal[i] = i>inpPeriod ? _smooth.Result[i] : _mp[i];
        }
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mMPO.algo
  • Rating: 5
  • Installs: 348
Comments
Log in to add a comment.
No comments found.