Description
Simply the Angle Trend Force (°)
(With some futurs add)
*** Update 08/09/2023 ***
1.Histogram Calculation
Test it before adopting it!
Have fun, and for any collaboration, contact me !!!
On telegram : https://t.me/nimi012 (direct messaging)
On Discord: https://discord.gg/jNg7BSCh (I advise you to come and see, Money management strategies and Signals Strategies !)
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Cloud("Ma Signal Fast", "Ma Signal Fast 2", FirstColor = "Lime", SecondColor = "Crimson")]
[Cloud("Ma Signal Low", "Ma Signal Low 2", FirstColor = "Lime", SecondColor = "Crimson")]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AngleMATrendForce : Indicator
{
[Parameter("Loockback Periods", DefaultValue = 1, MinValue = 1, Group = "Base Setting")]
public int LoockbackPeriods { get; set; }
[Parameter("MA Periods", DefaultValue = 34, MinValue = 1, Group = "Base Setting")]
public int EmaPeriods { get; set; }
[Parameter("MA Sensitivity", DefaultValue = 1, Group = "Base Setting")]
public double EmaSensitivity { get; set; }
[Parameter("Ma Periods Source", DefaultValue = "Close", Group = "Base Setting")]
public DataSeries Source { get; set; }
[Parameter("Ma Type", DefaultValue = MovingAverageType.Exponential, Group = "Base Setting")]
public MovingAverageType MaType1 { get; set; }
[Parameter("Use Smooth Trend", DefaultValue = "False", Group = "Trend Setting")]
public bool UseSmoothTrend { get; set; }
[Parameter("Ma Smooth Period", DefaultValue = 1, Group = "Trend Setting")]
public int MaPeriodSmooth { get; set; }
[Parameter("Ma Smooth Type", DefaultValue = MovingAverageType.Simple, Group = "Trend Setting")]
public MovingAverageType MaTypeSmooth { get; set; }
[Parameter("Use Histogram", DefaultValue = "true", Group = "Using Histogram")]
public bool UseHistogram { get; set; }
[Parameter("MA Signal Fast", DefaultValue = 1, MinValue = 1, Group = "Using Histogram")]
public int maSignalFastHisto { get; set; }
[Parameter("Ma Type Fast", DefaultValue = MovingAverageType.Weighted, Group = "Using Histogram")]
public MovingAverageType MaTypeSignalFastHisto { get; set; }
[Parameter("MA Signal Fast 2", DefaultValue = 13, MinValue = 1, Group = "Using Histogram")]
public int maSignalFast2Histo { get; set; }
[Parameter("Ma Type Fast 2", DefaultValue = MovingAverageType.Weighted, Group = "Using Histogram")]
public MovingAverageType MaTypeSignalFast2Histo { get; set; }
[Parameter("Use Signal", DefaultValue = "False", Group = "Signal Setting")]
public bool UseSignal { get; set; }
[Parameter("MA Signal Fast", DefaultValue = 5, MinValue = 1, Group = "Signal Setting")]
public int maSignalFast { get; set; }
[Parameter("Ma Type Fast", DefaultValue = MovingAverageType.Exponential, Group = "Signal Setting")]
public MovingAverageType MaTypeSignalFast { get; set; }
[Parameter("MA Signal Fast 2", DefaultValue = 13, MinValue = 1, Group = "Signal Setting")]
public int maSignalFast2 { get; set; }
[Parameter("Ma Type Fast 2", DefaultValue = MovingAverageType.Exponential, Group = "Signal Setting")]
public MovingAverageType MaTypeSignalFast2 { get; set; }
[Parameter("MA Signal Low", DefaultValue = 5, MinValue = 1, Group = "Signal Setting")]
public int maSignalLow { get; set; }
[Parameter("Ma Type Low", DefaultValue = MovingAverageType.Exponential, Group = "Signal Setting")]
public MovingAverageType MaTypeSignalLow { get; set; }
[Parameter("MA Signal Low 2", DefaultValue = 13, MinValue = 1, Group = "Signal Setting")]
public int maSignalLow2 { get; set; }
[Parameter("Ma Type Low 2", DefaultValue = MovingAverageType.Exponential, Group = "Signal Setting")]
public MovingAverageType MaTypeSignalLow2 { get; set; }
[Parameter("Use Fractal ", DefaultValue = "False", Group = "Fractal Setting")]
public bool UseFractal { get; set; }
[Parameter(DefaultValue = 3, MinValue = 1, Group = "Fractal Setting")]
public int Period { get; set; }
[Parameter("Use Bollinger Bands", DefaultValue = "False", Group = "Boll Setting")]
public bool UseBoll { get; set; }
[Parameter("Periode Boll", DefaultValue = 13, MinValue = 1, Group = "Boll Setting")]
public int PeriodeBoll { get; set; }
[Parameter("DevBoll", DefaultValue = 1, MinValue = 0.01, Group = "Boll Setting")]
public double DevBoll { get; set; }
[Parameter("DevBoll 2", DefaultValue = 1.5, MinValue = 0.01, Group = "Boll Setting")]
public double DevBoll2 { get; set; }
[Parameter("DevBoll 3", DefaultValue = 2, MinValue = 0.01, Group = "Boll Setting")]
public double DevBoll3 { get; set; }
[Parameter("Ma Boll", DefaultValue = MovingAverageType.Triangular, Group = "Boll Setting")]
public MovingAverageType MaTypeBoll { get; set; }
[Parameter("Use Level Bands", DefaultValue = "true", Group = "Level Setting")]
public bool UseLevel { get; set; }
[Parameter("levelup 1", DefaultValue = 25, MinValue = 0, Group = "Level Setting")]
public int levelupSet { get; set; }
[Parameter("leveldown 1", DefaultValue = -25, MaxValue = 0, Group = "Level Setting")]
public int leveldownSet { get; set; }
[Parameter("levelup 2", DefaultValue = 50, MinValue = 0, Group = "Level Setting")]
public int levelup2Set { get; set; }
[Parameter("leveldown 2", DefaultValue = -50, MaxValue = 0, Group = "Level Setting")]
public int leveldown2Set { get; set; }
[Parameter("levelup 3", DefaultValue = 75, MinValue = 0, Group = "Level Setting")]
public int levelup3Set { get; set; }
[Parameter("leveldown 3", DefaultValue = -75, MaxValue = 0, Group = "Level Setting")]
public int leveldown3Set { get; set; }
[Parameter("leveldown 0", DefaultValue = 0, MinValue = -1, Group = "Level Setting")]
public int leveldown0Set { get; set; }
[Output("Result °", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, LineColor = "White", Thickness = 1)]
public IndicatorDataSeries Result { get; set; }
[Output("Tendance High", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries Tendance2 { get; set; }
[Output("Tendance Low", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries Tendance3 { get; set; }
[Output("Ma Signal Fast", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, LineColor = "Green", Thickness = 1)]
public IndicatorDataSeries MaSignalFast { get; set; }
[Output("Ma Signal Fast 2", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, LineColor = "Red", Thickness = 1)]
public IndicatorDataSeries MaSignalFast2 { get; set; }
[Output("Ma Signal Low", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, LineColor = "Green", Thickness = 1)]
public IndicatorDataSeries MaSignalLow { get; set; }
[Output("Ma Signal Low 2", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, LineColor = "Red", Thickness = 1)]
public IndicatorDataSeries MaSignalLow2 { get; set; }
[Output("White", PlotType = PlotType.Histogram, LineColor = "White", Thickness = 4)]
public IndicatorDataSeries White { get; set; }
[Output("Up Bullish", PlotType = PlotType.Histogram, LineColor = "Lime", Thickness = 4)]
public IndicatorDataSeries StrongBullish { get; set; }
[Output("Down Bullish", PlotType = PlotType.Histogram, LineColor = "Green", Thickness = 4)]
public IndicatorDataSeries WeakBullish { get; set; }
[Output("Down Bearish", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 4)]
public IndicatorDataSeries StrongBearish { get; set; }
[Output("Up Bearish", PlotType = PlotType.Histogram, LineColor = "DarkSalmon", Thickness = 4)]
public IndicatorDataSeries WeakBearish { get; set; }
[Output("Up Fractal", LineColor = "Lime", PlotType = PlotType.Points, Thickness = 5)]
public IndicatorDataSeries UpFractal { get; set; }
[Output("Down Fractal", LineColor = "Red", PlotType = PlotType.Points, Thickness = 5)]
public IndicatorDataSeries DownFractal { get; set; }
[Output("MA top Dev 1", LineColor = "Lime", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma1T { get; set; }
[Output("MA midd Dev 1", LineColor = "White", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma1M { get; set; }
[Output("MA low Dev 1", LineColor = "Red", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma1L { get; set; }
[Output("MA top Dev 2", LineColor = "3CFFFF00", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma2T { get; set; }
[Output("MA low Dev 2", LineColor = "3CFFFF00", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma2L { get; set; }
[Output("MA top Dev 3", LineColor = "3CFFFF00", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma3T { get; set; }
[Output("MA low Dev 3", LineColor = "3CFFFF00", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries Ma3L { get; set; }
[Output("levelup", LineColor = "7EC0C0C0", LineStyle = LineStyle.DotsRare, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries levelup { get; set; }
[Output("leveldown", LineColor = "7EC0C0C0", LineStyle = LineStyle.DotsRare, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries leveldown { get; set; }
[Output("levelup2", LineColor = "4AFFFF00", LineStyle = LineStyle.DotsRare, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries levelup2 { get; set; }
[Output("leveldown2", LineColor = "4AFFFF00", LineStyle = LineStyle.DotsRare, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries leveldown2 { get; set; }
[Output("levelup3", LineColor = "Red", LineStyle = LineStyle.DotsRare, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries levelup3 { get; set; }
[Output("leveldown3", LineColor = "Red", LineStyle = LineStyle.DotsRare, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries leveldown3 { get; set; }
[Output("leveldown0", LineColor = "7EC0C0C0", LineStyle = LineStyle.Solid, PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries leveldown0 { get; set; }
private MovingAverage sma, maSmoothTrend, maSignalF, maSignalF2, maSignalL, maSignalL2, maSignalFHisto, maSignalF2Histo;
private BollingerBands boll, boll2, boll3;
private AverageTrueRange atr;
private IndicatorDataSeries trend, maTrend;
protected override void Initialize()
{
trend = CreateDataSeries();
maTrend = CreateDataSeries();
sma = Indicators.MovingAverage(Source, EmaPeriods, MaType1);
maSmoothTrend = Indicators.MovingAverage(Result, MaPeriodSmooth, MaTypeSmooth);
maSignalFHisto = Indicators.MovingAverage(Result, maSignalFastHisto, MaTypeSignalFastHisto);
maSignalF2Histo = Indicators.MovingAverage(Result, maSignalFast2Histo, MaTypeSignalFast2Histo);
atr = Indicators.AverageTrueRange(500, MovingAverageType.Simple);
maSignalF = Indicators.MovingAverage(Result, maSignalFast, MaTypeSignalFast);
maSignalF2 = Indicators.MovingAverage(Result, maSignalFast2, MaTypeSignalFast2);
maSignalL = Indicators.MovingAverage(Result, maSignalLow, MaTypeSignalLow);
maSignalL2 = Indicators.MovingAverage(Result, maSignalLow2, MaTypeSignalLow2);
boll = Indicators.BollingerBands(Result, PeriodeBoll, DevBoll, MaTypeBoll);
boll2 = Indicators.BollingerBands(Result, PeriodeBoll, DevBoll2, MaTypeBoll);
boll3 = Indicators.BollingerBands(Result, PeriodeBoll, DevBoll3, MaTypeBoll);
}
public override void Calculate(int index)
{
var atrRange = atr.Result[index];
var CoteOpposePlus = ((sma.Result[index]) - (sma.Result[index - (LoockbackPeriods)]));
var CoteOpposeMinus = (sma.Result[index - (LoockbackPeriods)]) - (sma.Result[index]);
var CoteOppose = (sma.Result[index]) > (sma.Result[index - (LoockbackPeriods)]) ? CoteOpposePlus / atrRange : CoteOpposeMinus / atrRange;
var Hypothenuse = Math.Sqrt((CoteOppose * CoteOppose) + (LoockbackPeriods * LoockbackPeriods));
var cos = (LoockbackPeriods / Hypothenuse);
Result[index] = (sma.Result[index]) > (sma.Result[index - (LoockbackPeriods)]) ? (0 + (Math.Acos(cos) * 100)) * EmaSensitivity : (0 - (Math.Acos(cos) * 100)) * EmaSensitivity;
if (UseSignal)
{
MaSignalFast[index] = maSignalF.Result[index];
MaSignalFast2[index] = maSignalF2.Result[index];
MaSignalLow[index] = maSignalL.Result[index];
MaSignalLow2[index] = maSignalL2.Result[index];
}
if (UseSmoothTrend)
{
trend[index] = trend[index - 1];
maTrend[index] = maSmoothTrend.Result[index];
if (maTrend[index] - maTrend[index - 1] > 0)
{
trend[index] = 1;
}
if (maTrend[index - 1] - maTrend[index] > 0)
{
trend[index] = -1;
}
if ((trend[index] > 0.0))
{
Tendance2[index] = maTrend[index];
if (trend[index - 1] < 0.0)
{
Tendance2[index - 1] = maTrend[index - 1];
}
Tendance3[index] = double.NaN;
}
if ((trend[index] < 0.0))
{
Tendance3[index] = maTrend[index];
if (trend[index - 1] > 0.0)
{
Tendance3[index - 1] = maTrend[index - 1];
}
Tendance2[index] = double.NaN;
}
}
if (UseHistogram)
{
double HistogramValue = maSignalFHisto.Result[index] - maSignalF2Histo.Result[index];
double prevHistogramValue = maSignalFHisto.Result[index - 1] - maSignalF2Histo.Result[index - 1];
if (HistogramValue > 0)
{
if (prevHistogramValue >= HistogramValue)
{
WeakBullish[index] = HistogramValue;
StrongBullish[index] = 0;
WeakBearish[index] = 0;
StrongBearish[index] = 0;
White[index] = 0;
}
else
{
StrongBullish[index] = HistogramValue;
WeakBullish[index] = 0;
WeakBearish[index] = 0;
StrongBearish[index] = 0;
White[index] = 0;
}
}
else if (HistogramValue < -0)
{
if (HistogramValue <= prevHistogramValue)
{
StrongBearish[index] = HistogramValue;
WeakBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
White[index] = 0;
}
else
{
WeakBearish[index] = HistogramValue;
StrongBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
White[index] = 0;
}
}
else
{
if (HistogramValue <= prevHistogramValue)
{
White[index] = HistogramValue;
WeakBearish[index] = 0;
WeakBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
}
else
{
WeakBearish[index] = 0;
White[index] = HistogramValue;
StrongBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
}
}
}
if (UseLevel)
{
var aa = levelupSet;
var bb = levelup2Set;
var cc = leveldown0Set;
var dd = leveldownSet;
var ee = leveldown2Set;
var ff = levelup3Set;
var gg = leveldown3Set;
levelup[index] = aa;
levelup2[index] = bb;
leveldown0[index] = cc;
leveldown[index] = dd;
leveldown2[index] = ee;
levelup3[index] = ff;
leveldown3[index] = gg;
}
if (UseBoll)
{
Ma1T[index] = boll.Top.Last(0);
Ma1M[index] = boll.Main.Last(0);
Ma1L[index] = boll.Bottom.Last(0);
Ma2T[index] = boll2.Top.Last(0);
Ma2L[index] = boll2.Bottom.Last(0);
Ma3T[index] = boll3.Top.Last(0);
Ma3L[index] = boll3.Bottom.Last(0);
}
if (UseFractal)
{
if (index < Period)
return;
DrawUpFractal(index);
DrawDownFractal(index);
}
}
public void DrawUpFractal(int index)
{
int period = Period % 2 == 0 ? Period - 1 : Period;
int middleIndex = index - period / 2;
double middleValue = Result[middleIndex];
bool up = true;
for (int i = 0; i < period; i++)
{
if (middleValue < Result[index - i])
{
up = false;
break;
}
}
if (up)
UpFractal[middleIndex] = middleValue;
}
public void DrawDownFractal(int index)
{
int period = Period % 2 == 0 ? Period - 1 : Period;
int middleIndex = index - period / 2;
double middleValue = Result[middleIndex];
bool down = true;
for (int i = 0; i < period; i++)
{
if (middleValue > Result[index - i])
{
down = false;
break;
}
}
if (down)
DownFractal[middleIndex] = middleValue;
}
}
}
YesOrNot
Joined on 10.10.2022 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: [000] Angle MA Trend Force v 3.0 Histo Retracement.algo
- Rating: 5
- Installs: 410
- Modified: 08/09/2023 05:56
Comments
The "Angle Trend Force" indicator seems to be quite an intricate tool designed to assist traders in analyzing trends and potential trading opportunities. But I think that the code involves a way too complex interplay of different moving averages. If you're considering using this indicator, I'd highly recommend testing it on historical data or a demo account to understand its behavior and potential impact on your trading decisions. Remember that indicators can provide valuable insights, but they should be part of a broader trading strategy that takes into account market conditions and risk management.
Hi, @crawfordevans499 thank you for your comment!
If it is complicated to understand then I explain to you :
1. The trend force uses a moving average and calculates its degree of inclination with respect to the selected lookback period. so you can know if the ma has a significant curve or not
2. the formula is a trigonometry rule. If you put a lookback 1, you will have the angle on a single period, on lookback 10, you will have the angle between the previous 10th bar and the last one.
3. To understand the result, I invite you to put a lookback of 1, and put the same moving average on the chart, so you can understand how it works, its advantages, and its disadvantages.
Have a nice study =) and why not, tell us what you find ! =D