Category Oscilators  Published on 25/01/2023

Price Difference indicator

Description

PDI (Price Difference) is a simple signal indicator of the price difference between the previous and the current bars. It displays as signal marks the candlesticks, on which the previous Applied price is higher than the current one by the pre-defined Price difference. If the price difference is positive, the mark will be placed on the Low price of the current candlesticks. If it is negative - on the High price.



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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mPDI : Indicator
    {
        [Parameter("Difference (100)", DefaultValue = 100)]
        public int inpDifference { get; set; }
        [Parameter("Data Source", DefaultValue = "Close")]
        public DataSeries inpDataSource { get; set; }

        [Output("PDI Up", LineColor = "Red", PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries outUp { get; set; }
        [Output("PDI Down", LineColor = "Green", PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries outDn { get; set; }
        
        private MovingAverage _ma;
        private double diff;
        
        
        protected override void Initialize()
        {
            _ma = Indicators.MovingAverage(inpDataSource, 1, MovingAverageType.Simple);
            diff = inpDifference * Symbol.PipSize;
        }

        public override void Calculate(int i)
        {
            outUp[i] = i>1 && _ma.Result[i]-_ma.Result[i-1] > diff ? Bars.LowPrices[i] : double.NaN;
            outDn[i] = i>1 && _ma.Result[i]-_ma.Result[i-1] < -diff ? Bars.HighPrices[i] : double.NaN;
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mPDI.algo
  • Rating: 5
  • Installs: 816
Comments
Log in to add a comment.
FA
faisbeam · 1 year ago

The Price Rate of Change (ROC) is a momentum-based technical indicator that measures the percentage change in price between the current price and the price a certain number of periods ago, also you can get it on aurora store 

FA
faisbeam · 1 year ago

PDI is a simple signal indicator of the price difference between the previous and the current bars. It displays as signal marks the candlesticks, on which the previous etcher price is higher than the current one by the pre-defined Price difference.