Description
This indicator allows adding 6 Moving Average to the chart. The periods of each Moving Average depend on the Moving Average Period Start x Period Multiplier.
A sensitivity parameter is added to filter High trends from Slow trends.
Enjoy for Free =)
Previous account here : https://ctrader.com/users/profile/70920
Contact telegram : https://t.me/nimi012
using System;
using System.Linq;
using System.Reflection;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MaMultiTrend : Indicator
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("MA Period Start", DefaultValue = 13)]
public double MAPeriodStart { get; set; }
[Parameter("Period Multiplicator", DefaultValue = 1.34)]
public double MAPeriodMulti { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
public MovingAverageType MaType { get; set; }
[Parameter("Sensibility Ma Trend ", DefaultValue = 10)]
public double SensibilityMaTrend { get; set; }
[Output("MA 1", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma1 { get; set; }
[Output("MA 2", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma2 { get; set; }
[Output("MA 3", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma3 { get; set; }
[Output("MA 4", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma4 { get; set; }
[Output("MA 5", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma5 { get; set; }
[Output("MA 6", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma6 { get; set; }
[Output("MA 1High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma1High { get; set; }
[Output("MA 2High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma2High { get; set; }
[Output("MA 3High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma3High { get; set; }
[Output("MA 4High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma4High { get; set; }
[Output("MA 5High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma5High { get; set; }
[Output("MA 6High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma6High { get; set; }
[Output("MA 1Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma1Low { get; set; }
[Output("MA 2Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma2Low { get; set; }
[Output("MA 3Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma3Low { get; set; }
[Output("MA 4Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma4Low { get; set; }
[Output("MA 5Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma5Low { get; set; }
[Output("MA 6Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries Ma6Low { get; set; }
private IndicatorDataSeries[] res, resHigh, resLow;
private MovingAverage[] ma;
private int[] periods;
protected override void Initialize()
{
resHigh = new IndicatorDataSeries[6];
resHigh[0] = Ma1High;
resHigh[1] = Ma2High;
resHigh[2] = Ma3High;
resHigh[3] = Ma4High;
resHigh[4] = Ma5High;
resHigh[5] = Ma6High;
resLow = new IndicatorDataSeries[6];
resLow[0] = Ma1Low;
resLow[1] = Ma2Low;
resLow[2] = Ma3Low;
resLow[3] = Ma4Low;
resLow[4] = Ma5Low;
resLow[5] = Ma6Low;
res = new IndicatorDataSeries[6];
res[0] = Ma1;
res[1] = Ma2;
res[2] = Ma3;
res[3] = Ma4;
res[4] = Ma5;
res[5] = Ma6;
ma = new MovingAverage[6];
periods = new int[6];
for (int i = 0; i < ma.Length; i++)
{
periods[i] = (int)(Math.Round(Math.Pow(MAPeriodMulti, i) * MAPeriodStart));
ma[i] = Indicators.MovingAverage(Bars.HighPrices, periods[i], MaType);
}
}
public override void Calculate(int index)
{
int maAboveTotal = 0;
for (int i = 0; i < ma.Length; i++)
{
maAboveTotal += GetNumMaAbove(i, index);
}
for (int i = 0; i < ma.Length; i++)
{
res[i][index] = ma[i].Result[index];
resHigh[i][index] = (200.0 * maAboveTotal / (ma.Length * (ma.Length - 1.0))) < SensibilityMaTrend ? ma[i].Result[index] : double.NaN;
resLow[i][index] = (200.0 * maAboveTotal / (ma.Length * (ma.Length - 1.0))) > 100 - SensibilityMaTrend ? ma[i].Result[index] : double.NaN;
}
}
private int GetNumMaAbove(int reference, int index)
{
int count = 0;
for (int i = reference + 1; i < ma.Length; i++)
{
if (ma[i].Result[index] > ma[reference].Result[index])
count++;
}
return count;
}
}
}
YE
YesOrNot2
Joined on 17.05.2024
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Multi Ma Trend.algo
- Rating: 5
- Installs: 464
- Modified: 04/07/2024 13:10
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.
No comments found.