Description
Hgcfcgh
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;
}
}
}
SM
smalandrey63
Joined on 12.02.2024
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: PVT Trend Hunter.algo
- Rating: 0
- Installs: 296
- Modified: 12/02/2024 22:52
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
COVES ANDREY.
TINT TO ADROLLA.
AFOLT EVZ RAMINER.
HTS.