Description
This trading indicator, called DonchianSmoothMaAllInOneScored, integrates multiple Donchian channels, smoothing techniques, and scoring systems to provide a comprehensive analysis of market trends. Here’s a simplified explanation of how it works:
Main Parameters:
- NbrsLoad: The number of Donchian channels to load.
- EnvleoppePeriod: The base period for the envelopes.
- PeriodsMultiplicator: A multiplier for the Donchian periods.
- MaTypeBoll: The type of moving average used for Bollinger calculations.
- Smooth1, Smooth2, Smooth3: Smoothing parameters.
- Shift: The shift applied to the deviation.
- SmoothingPeriod: The period for smoothing the main result.
- MaTypeSmoothing: The type of moving average used for smoothing.
- SignalPeriod: The period for the signal line.
- MaTypeSignal: The type of moving average used for the signal line.
- SetLevelExtraHigh, SetLevelHigh, SetLevelMiddle: Level settings for indicator thresholds.
- UseBarsColors: A flag to use bar coloring based on indicator levels.
- LevelBarsColor1, LevelBarsColor2, LevelBarsColor3, LevelBarsColor4, LevelBarsColor5: Levels for bar coloring.
Indicator Outputs:
- LevelExtraHigh, LevelHigh, LevelMiddle, LevelLow, LevelExtraLow: Different threshold levels plotted on the chart.
- Result: The main indicator result line.
- Signal: The signal line used for trading decisions.
How It Works
Initialization:
- Create Data Structures: Initialize arrays to store intermediate results and Donchian smoothing indicators.
- Set Periods and Smoothing Values: Calculate periods using the multiplicator and initialize smoothing parameters.
- Initialize Moving Averages: Set up moving averages for the result and signal lines.
Calculation on Each Update:
- Set Level Thresholds: Define the levels for extra high, high, middle, low, and extra low.
- Compute Donchian Channels: For each period and smoothing combination, calculate whether the current price is above or below various thresholds (high, middle, low).
- Aggregate Results: Sum the results from all Donchian calculations to derive an overall indicator score.
- Smooth Results: Apply moving averages to smooth the aggregated result and calculate the signal line.
- Color Bars: Optionally color the bars based on the result's position relative to the predefined levels.
- Loading Progress: Display the loading progress of indicators and chart elements.
Usage
This indicator is useful for a comprehensive analysis of market trends, providing multiple levels of smoothing and scoring to help identify market conditions. It is designed to handle various periods and smoothing techniques, making it adaptable to different trading strategies. The color-coded bars and detailed level settings assist in quickly interpreting market signals and making informed trading decisions.
Donchian Smoothed Ma is necessary for this algo: https://ctrader.com/algos/indicators/show/4410/
Enjoy for Free =)
Previous account here : https://ctrader.com/users/profile/70920
Contact telegram : https://t.me/nimi012
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, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class DonchianSmoothMaAllInOneScored : Indicator
{
[Parameter("Nbrs Donchian Load ", DefaultValue = 10, Group = "Donchian Period Setting")]
public int NbrsLoad { get; set; }
[Parameter("EnvleoppePeriod", DefaultValue = 55, Group = "Donchian Period Setting")]
public int EnvleoppePeriod { get; set; }
[Parameter("Periods Multiplicator", DefaultValue = 1.618, Group = "Donchian Period Setting")]
public double PeriodsMultiplicator { get; set; }
[Parameter("Ma Type Boll", DefaultValue = MovingAverageType.Hull, Group = "Donchian Period Setting")]
public MovingAverageType MaTypeBoll { get; set; }
[Parameter("Smooth 1", DefaultValue = 34, Group = "Deviation")]
public double Smooth1 { get; set; }
[Parameter("Smooth 1", DefaultValue = 55, Group = "Deviation")]
public double Smooth2 { get; set; }
[Parameter("Smooth 1", DefaultValue = 89, Group = "Deviation")]
public double Smooth3 { get; set; }
[Parameter("Shift Deviation ", DefaultValue = 0, Group = "Sensibility")]
public int Shift { get; set; }
[Parameter("Periods Multiplicator", DefaultValue = 3, Group = "Smoothing & Signal")]
public int SmoothingPeriod { get; set; }
[Parameter("Ma Type Smooth", DefaultValue = MovingAverageType.Simple, Group = "Smoothing & Signal")]
public MovingAverageType MaTypeSmoothing { get; set; }
[Parameter("Periods Multiplicator", DefaultValue = 9, Group = "Smoothing & Signal")]
public int SignalPeriod { get; set; }
[Parameter("Ma Type Smooth", DefaultValue = MovingAverageType.Simple, Group = "Smoothing & Signal")]
public MovingAverageType MaTypeSignal { get; set; }
[Parameter("Level Extra High ", DefaultValue = 80, Group = " Level Setting")]
public double SetLevelExtraHigh { get; set; }
[Parameter("Level High", DefaultValue = 50, Group = " Level Setting")]
public double SetLevelHigh { get; set; }
[Parameter("Level Middle ", DefaultValue = 0, Group = " Level Setting")]
public double SetLevelMiddle { get; set; }
[Parameter("Use Bars Color", DefaultValue = true, Group = "Bars Colors")]
public bool UseBarsColors { get; set; }
[Parameter("Level 1 Max ", DefaultValue = 83.33, Group = "Bars Colors")]
public int LevelBarsColor1 { get; set; }
[Parameter("Level 2 ", DefaultValue = 66.66, Group = "Bars Colors")]
public int LevelBarsColor2 { get; set; }
[Parameter("Level 3 ", DefaultValue = 50, Group = "Bars Colors")]
public int LevelBarsColor3 { get; set; }
[Parameter("Level 4 ", DefaultValue = 33.33, Group = "Bars Colors")]
public int LevelBarsColor4 { get; set; }
[Parameter("Level 5 Min", DefaultValue = 16.66, Group = "Bars Colors")]
public int LevelBarsColor5 { get; set; }
[Output("Level Extra High", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "7BFF0000", Thickness = 1)]
public IndicatorDataSeries LevelExtraHigh { get; set; }
[Output("Level High", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "81FFA500", Thickness = 1)]
public IndicatorDataSeries LevelHigh { get; set; }
[Output("Level Middle", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "Gray", Thickness = 1)]
public IndicatorDataSeries LevelMiddle { get; set; }
[Output("Level Low", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "81FFA500", Thickness = 1)]
public IndicatorDataSeries LevelLow { get; set; }
[Output("Level ExtraLow", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "7BFF0000", Thickness = 1)]
public IndicatorDataSeries LevelExtraLow { get; set; }
[Output("Result", PlotType = PlotType.Line, LineColor = "Lime", Thickness = 1)]
public IndicatorDataSeries Result { get; set; }
[Output("Signal", PlotType = PlotType.Line, LineColor = "Red", Thickness = 1)]
public IndicatorDataSeries Signal { get; set; }
private DonchianSmoothingMa[,] dsm;
private IndicatorDataSeries[,] res;
private int[] periods;
private double[] smooth;
private double resIndicator;
private IndicatorDataSeries result;
private MovingAverage smoothing, signal;
private double barsCount;
public IndicatorDataSeries totalLoad;
private double indicatorsLoad;
private double indicatorsNeedLoad;
private double barCount;
private int pct = 0;
protected override void Initialize()
{
res = new IndicatorDataSeries[NbrsLoad, 3];
dsm = new DonchianSmoothingMa[NbrsLoad, 3];
periods = new int[NbrsLoad];
smooth = new double[3];
smooth[0] = Smooth1;
smooth[1] = Smooth2;
smooth[2] = Smooth3;
result = CreateDataSeries();
smoothing = Indicators.MovingAverage(result, SmoothingPeriod, MaTypeSmoothing);
signal = Indicators.MovingAverage(Result, SignalPeriod, MaTypeSignal);
totalLoad = CreateDataSeries();
resIndicator = 0.00;
barsCount = Bars.Count;
indicatorsLoad = 0;
indicatorsNeedLoad = 0;
pct = 0;
barCount = Bars.Count;
for (int i = 0; i < periods.Length; i++)
{
periods[i] = (int)(Math.Round(Math.Pow(PeriodsMultiplicator, i) * EnvleoppePeriod));
for (int j = 0; j < smooth.Length; j++)
{
res[i, j] = CreateDataSeries();
dsm[i, j] = Indicators.GetIndicator<DonchianSmoothingMa>(periods[i], smooth[j], MaTypeBoll);
}
}
}
public override void Calculate(int index)
{
LevelExtraHigh[index] = SetLevelExtraHigh;
LevelHigh[index] = SetLevelHigh;
LevelMiddle[index] = SetLevelMiddle;
LevelLow[index] = -SetLevelHigh;
LevelExtraLow[index] = -SetLevelExtraHigh;
resIndicator = 0.00;
barsCount = Bars.Count;
for (int i = 0; i < periods.Length; i++)
{
for (int j = 0; j < smooth.Length; j++)
{
res[i, j][index] = Bars.ClosePrices[index] >= dsm[i, j].ResultUp[index - Shift] ? 2
: Bars.ClosePrices[index] >= dsm[i, j].ResultMidd[index] ? 1
: Bars.ClosePrices[index] <= dsm[i, j].ResultDown[index - Shift] ? -2
: Bars.ClosePrices[index] <= dsm[i, j].ResultMidd[index] ? -1
: 0;
resIndicator += res[i, j][index];
}
if (barsCount > (periods[i]))
indicatorsLoad = i + 1;
}
indicatorsNeedLoad = NbrsLoad - indicatorsLoad;
totalLoad[index] = indicatorsLoad * smooth.Length;
result[index] = ((resIndicator / (totalLoad[index])) * periods.Length * smooth.Length) / (periods.Length * smooth.Length * 2) * 100;
Result[index] = smoothing.Result[index];
Signal[index] = signal.Result[index];
if (UseBarsColors)
{
if (Result[index] > LevelBarsColor1)
Chart.SetBarColor(index, "White");
else if (Result[index] <= LevelBarsColor1 && Result[index] > LevelBarsColor2)
Chart.SetBarColor(index, "Yellow");
else if (Result[index] <= LevelBarsColor2 && Result[index] > LevelBarsColor3)
Chart.SetBarColor(index, "FF01FF01");
else if (Result[index] <= LevelBarsColor3 && Result[index] > LevelBarsColor4)
Chart.SetBarColor(index, "FF00BF00");
else if (Result[index] <= LevelBarsColor4 && Result[index] > LevelBarsColor5)
Chart.SetBarColor(index, "FF00843B");
//Middle
else if (Result[index] <= LevelBarsColor5 && Result[index] > -LevelBarsColor5)
Chart.SetBarColor(index, "FF262626");
//Down
else if (Result[index] <= -LevelBarsColor5 && Result[index] > -LevelBarsColor4)
Chart.SetBarColor(index, "FF5B0003");
else if (Result[index] <= -LevelBarsColor4 && Result[index] > -LevelBarsColor3)
Chart.SetBarColor(index, "FF890002");
else if (Result[index] <= -LevelBarsColor3 && Result[index] > -LevelBarsColor2)
Chart.SetBarColor(index, "FFFE0000");
else if (Result[index] <= -LevelBarsColor2 && Result[index] > -LevelBarsColor1)
Chart.SetBarColor(index, "Orange");
else if (Result[index] <= -LevelBarsColor1)
Chart.SetBarColor(index, "FFFF00C5");
}
// Loading info on log
double loading = index / barCount * 100;
if (pct < loading + 0.1 && pct < 105)
{
Print("Load : " + loading.ToString("F0") + " %");
pct += 10;
}
// Loading info on Chart
if (index == periods[NbrsLoad - 1])
{
Chart.DrawVerticalLine("Load All Vertical Ligne" + index, index, Color.Lime, 1);
IndicatorArea.DrawText("Load All Indicators" + index, "100 % Loading", index, 90, Color.Lime);
IndicatorArea.DrawText("Load All Indicators 2" + index, "100 % Loading", index, 0, Color.White);
IndicatorArea.DrawText("Load All Indicators 3" + index, "100 % Loading", index, -90, Color.Red);
}
if (indicatorsNeedLoad != 0)
{
Chart.DrawStaticText("Indicators", indicatorsLoad + "/" + NbrsLoad + " Indicators are Load (" + (indicatorsLoad / NbrsLoad * 100).ToString("F0") + "%)" + "\nScroll and Load more Bars for " + indicatorsNeedLoad + " Indicators (100%)"
, VerticalAlignment.Bottom, HorizontalAlignment.Right, Color.Red);
}
else
{
Chart.RemoveObject("Indicators");
Chart.DrawStaticText("Indicators Load Ok", " Indicators Load : " + indicatorsLoad + "/" + NbrsLoad + "\n" + "Higher Period : " + periods[NbrsLoad - 1] + "\n" + " Bars at 100% : " + (barCount - periods[NbrsLoad - 1]).ToString("F0"), VerticalAlignment.Bottom, HorizontalAlignment.Right, Color.Green);
}
}
}
}
YesOrNot2
Joined on 17.05.2024
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Donchian Smooth Ma AllInOne Scored.algo
- Rating: 5
- Installs: 362
- Modified: 30/07/2024 00:02