Category Oscilators  Published on 02/08/2023

Price Polarity of Positive&Negative Volume Index

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

"Price Polarity of Positive & Negative Volume Index" is a custom indicator. In general, this indicator smooths price polarity for bullish and bearish sentiment, using the positive volume with price confluence into negative volume size.

In other words, when the indicator value is above the zero level, the bar sentiment is bullish. Likewise, when the indicator value is below the zero level, the bar sentiment is bearish.

In another way, this custom indicator is a synthetic price smoothing method using volume.

This indicator is developed based on my mentor Iba's documentation.




mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mPNVIpol.algo
  • Rating: 5
  • Installs: 541
  • Modified: 02/08/2023 11:27
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, AccessRights = AccessRights.None)]
    public class mPNVIpol : Indicator
    {
        [Parameter("Period (5)", DefaultValue = 5)]
        public int inpPeriod { get; set; }

        [Output("Close", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outPolarity { get; set; }
        
        private PositiveVolumeIndex _pvi;
        private NegativeVolumeIndex _nvi;
        private IndicatorDataSeries _result, _pos, _neg;
        

        protected override void Initialize()
        {
            _pvi = Indicators.PositiveVolumeIndex(Bars.ClosePrices);
            _nvi = Indicators.NegativeVolumeIndex(Bars.ClosePrices);
            _result = CreateDataSeries();
            _pos = CreateDataSeries();
            _neg = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _result[i] = i>1 && _pvi.Result[i] >= _pvi.Result[i-1] 
                        ? Bars.LowPrices.Minimum(inpPeriod) - (Bars.HighPrices[i] - Bars.LowPrices[i])
                        : Bars.HighPrices.Maximum(inpPeriod) + (Bars.HighPrices[i] - Bars.LowPrices[i]);
                        
            _pos[i] = i>1 && _nvi.Result[i] >= _nvi.Result[i-1] 
                        ? Bars.LowPrices.Minimum(inpPeriod) - (Bars.HighPrices[i] - Bars.LowPrices[i])
                        : Bars.HighPrices.Maximum(inpPeriod) + (Bars.HighPrices[i] - Bars.LowPrices[i]);
                        
            _neg[i] = i>1 && _nvi.Result[i] >= _nvi.Result[i-1] 
                        ? Bars.HighPrices.Maximum(inpPeriod) + (Bars.HighPrices[i] - Bars.LowPrices[i])
                        : Bars.LowPrices.Minimum(inpPeriod) - (Bars.HighPrices[i] - Bars.LowPrices[i]);
                        
            outPolarity[i] = 
                          Bars.ClosePrices[i] > _result[i] && Bars.ClosePrices[i] > _pos[i] ? +1
                        : Bars.ClosePrices[i] < _result[i] && Bars.ClosePrices[i] < _neg[i] ? -1
                        : 0;
        }
    }
}