Category Oscilators  at 02/08/2023

Price Polarity of Positive&Negative Volume Index

Notice. There is an update for this algorithm which is awaiting moderation. Please check back soon to view the latest version of this algorithm.
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 25.01.2022

  • Type: Free
  • Language: C#
  • Trading Platform: cTrader Automate
  • Filename: mPNVIpol.algo
  • Rating: 5
  • Installs: 172
Comments
Only logged in users can post a comment
mfejza's avatar
mfejza · 4 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 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;
        }
    }
}