Category Trend  Published on 05/02/2024

PVT TREND HUNTER

Description

PVT Trend Hunter is an indicator that analyzes the Price Volume Trend using a range and a moving average.

Explanation:

  1. Period LookBack = Analyzes the maximum and minimum within a period. If the PVTis outside the Range, then the range zone changes; otherwise, it remains the same.
  2. Period Smooth = The option to smooth the PVT.
  3. Range = Defines the complete range zone from High to Low.
  4. Signal Period = Moving average of the PVT.
  5. Extra Range = Range + High and Low - Range.

How to use it: 

In the Up Zone, look for crossovers of the Pvt above the moving average. 

In the Down Zone, look for crossovers of the Pvt below the moving average.

 

Have fun, and for any collaboration, contact me !!!

On telegram : https://t.me/nimi012 (direct messaging)



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class PVTTrendHunter : Indicator
    {
        [Parameter(DefaultValue = 34)]
        public int PeriodLookBack { get; set; }
        [Parameter(DefaultValue = 5)]
        public int PeriodSmooth { get; set; }
        [Parameter(DefaultValue = MovingAverageType.Weighted)]
        public MovingAverageType MaTypeSmooth { get; set; }

        [Parameter(DefaultValue = 100)]
        public double Range { get; set; }

        [Parameter(DefaultValue = 34)]
        public int PeriodSignal { get; set; }
        [Parameter(DefaultValue = MovingAverageType.Weighted)]
        public MovingAverageType MaTypeSignal { get; set; }

        [Parameter(DefaultValue = "true")]
        public bool ExtraRange { get; set; }

        [Output("High", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "B000FF00")]
        public IndicatorDataSeries High { get; set; }
        [Output("Mid", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "Gray")]
        public IndicatorDataSeries Mid { get; set; }
        [Output("Low", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "B3FF0000")]
        public IndicatorDataSeries Low { get; set; }

        [Output("UpZone", PlotType = PlotType.DiscontinuousLine, LineColor = "Lime")]
        public IndicatorDataSeries UpZone { get; set; }
        [Output("DownZone", PlotType = PlotType.DiscontinuousLine, LineColor = "Red")]
        public IndicatorDataSeries DownZone { get; set; }

        [Output("HighMid", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "AEFFD700")]
        public IndicatorDataSeries HighMid { get; set; }
        [Output("LowMid", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "AEFFD700")]
        public IndicatorDataSeries LowMid { get; set; }

        [Output("RangeSup", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "Gray")]
        public IndicatorDataSeries RangeSup { get; set; }
        [Output("RangeInf", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "Gray")]
        public IndicatorDataSeries RangeInf { get; set; }

        [Output("Res", LineColor = "DeepSkyBlue")]
        public IndicatorDataSeries Res { get; set; }
        [Output("Signal", LineColor = "Magenta")]
        public IndicatorDataSeries Signal { get; set; }

        private IndicatorDataSeries high, low, range;
        private PriceVolumeTrend pvt;
        private MovingAverage ma, smoothPvt;
        private int direction;

        protected override void Initialize()
        {
            high = CreateDataSeries();
            low = CreateDataSeries();
            range = CreateDataSeries();
            pvt = Indicators.PriceVolumeTrend(Bars.ClosePrices);
            smoothPvt = Indicators.MovingAverage(pvt.Result, PeriodSmooth, MaTypeSmooth);
            ma = Indicators.MovingAverage(smoothPvt.Result, PeriodSignal, MaTypeSignal);
        }

        public override void Calculate(int index)
        {
            high[index] = smoothPvt.Result.Maximum(PeriodLookBack);
            low[index] = smoothPvt.Result.Minimum(PeriodLookBack);
            range[index] = Range;
            Res[index] = smoothPvt.Result.Last(0);
            Signal[index] = ma.Result.Last(0);

            if (smoothPvt.Result.Last(0) > (double.IsNaN(High[index - 1]) ? high[index - 1] : High[index - 1]))
            {
                High[index] = smoothPvt.Result.Last(0);
                Low[index] = smoothPvt.Result.Last(0) - range[index];
                Mid[index] = (High[index] - Low[index]) / 2 + Low[index];
                HighMid[index] = High[index] - ((High[index] - Mid[index]) / 4);
                LowMid[index] = ((Mid[index] - Low[index]) / 4) + Low[index];

                if (ExtraRange)
                {
                    RangeSup[index] = HighMid[index] + range[index];
                    RangeInf[index] = LowMid[index] - range[index];
                }
            }

            else if (smoothPvt.Result.Last(0) < (double.IsNaN(Low[index - 1]) ? low[index - 1] : Low[index - 1]))
            {
                Low[index] = smoothPvt.Result.Last(0);
                High[index] = smoothPvt.Result.Last(0) + range[index];
                Mid[index] = (High[index] - Low[index]) / 2 + Low[index];
                HighMid[index] = High[index] - ((High[index] - Mid[index]) / 4);
                LowMid[index] = ((Mid[index] - Low[index]) / 4) + Low[index];
                if (ExtraRange)
                {
                    RangeSup[index] = HighMid[index] + range[index];
                    RangeInf[index] = LowMid[index] - range[index];
                }
            }

            else
            {
                High[index] = High[index - 1];
                Low[index] = Low[index - 1];
                Mid[index] = Mid[index - 1];
                HighMid[index] = HighMid[index - 1];
                LowMid[index] = LowMid[index - 1];
                if (ExtraRange)
                {
                    RangeSup[index] = RangeSup[index - 1];
                    RangeInf[index] = RangeInf[index - 1];

                }
            }

            direction = Mid[index] > Mid[index - 1] ? 1 : Mid[index] < Mid[index - 1] ? -1 : direction;
            UpZone[index] = direction == 1 ? Mid[index] : double.NaN;
            DownZone[index] = direction == -1 ? Mid[index] : double.NaN;
        }
    }
}

YE
YesOrNot

Joined on 10.10.2022 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: PVT Trend Hunter.algo
  • Rating: 5
  • Installs: 541
  • Modified: 05/02/2024 18:13
Comments
Log in to add a comment.
No comments found.