Description
Interesting trend indicator using ATR as filter.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class BraidFilter : Indicator
{
[Parameter("Period1", DefaultValue = 3)]
public int per1 { get; set; }
[Parameter("Period2", DefaultValue = 7)]
public int per2 { get; set; }
[Parameter("Period3", DefaultValue = 14)]
public int per3 { get; set; }
[Parameter("PipsMinSepPercent", DefaultValue = 40)]
public int pipPerc { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType maType { get; set; }
[Output("Up Histogram", LineColor = "Aqua", PlotType = PlotType.Histogram)]
public IndicatorDataSeries up { get; set; }
[Output("Down Histogram", PlotType = PlotType.Histogram, LineColor = "Red")]
public IndicatorDataSeries down { get; set; }
[Output("Neutral Histogram", PlotType = PlotType.Histogram, LineColor = "Grey")]
public IndicatorDataSeries neutral { get; set; }
[Output("Filter", Color = Colors.Gray)]
public IndicatorDataSeries filter { get; set; }
private IndicatorDataSeries max, min, dif;
private MovingAverage ma1, ma2, ma3;
private AverageTrueRange atr;
protected override void Initialize()
{
ma1 = Indicators.MovingAverage(Bars.ClosePrices, per1, maType);
ma2 = Indicators.MovingAverage(Bars.OpenPrices, per2, maType);
ma3 = Indicators.MovingAverage(Bars.ClosePrices, per3, maType);
atr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
max = CreateDataSeries();
min = CreateDataSeries();
dif = CreateDataSeries();
}
public override void Calculate(int index)
{
max[index] = Math.Max(Math.Max(ma1.Result[index], ma2.Result[index]), ma3.Result[index]);
min[index] = Math.Min(Math.Min(ma1.Result[index], ma2.Result[index]), ma3.Result[index]);
dif[index] = max[index] - min[index];
filter[index] = atr.Result[index] * pipPerc / 100;
//ma1.Result[index] > ma2.Result[index] & dif[index] > filter[index] ? up[index] = dif[index] : ma2.Result[index] > ma1.Result[index] & dif[index] > filter[index] ? down[index] = dif[index] : neutral[index] = dif[index];
if (dif[index] > filter[index])
{
if (ma1.Result[index] > ma2.Result[index])
{
up[index] = dif[index];
down[index] = 0;
neutral[index] = 0;
}
else
{
down[index] = dif[index];
up[index] = 0;
neutral[index] = 0;
}
}
else
{
neutral[index] = dif[index];
up[index] = 0;
down[index] = 0;
}
}
}
}
KA
kaneida84
Joined on 25.04.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Braid Filter.algo
- Rating: 5
- Installs: 1292
- Modified: 13/10/2021 09:54
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.
Dear kaneida84 - I would like to say thank you for your indicator - cheers