Category Trend  Published on 24/11/2022

Double Ema Trend

Description
Let me present it briefly.
This is the trend for the chart from 2H and above.

The Turquoise line is for the current trend if it crosses the Black line.

The purpose of the indicator is for you to identify the exact trend

 



using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class DoubleEMAtrend : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", DefaultValue = 50)]
        public int PeriodsTrend { get; set; }

        [Parameter("Periods", DefaultValue = 100)]
        public int PeriodsBase { get; set; }

        [Output("trend", LineColor = "Turquoise", LineStyle = LineStyle.LinesDots,Thickness = 2)]
        public IndicatorDataSeries Result { get; set; }

        [Output("base",IsHistogram =false, LineColor = "Black", LineStyle = LineStyle.LinesDots ,Thickness = 2)]
        public IndicatorDataSeries ResultBase { get; set; }

        private double expTrend;
        private double expBase;
     
        protected override void Initialize()
        {
            expTrend = 2.0 / (PeriodsTrend + 1);
            expBase = 2.0 / (PeriodsBase + 1);
       
        }

        public override void Calculate(int index)
        {
       
            var previousValue = Result[index - 1];

            if (double.IsNaN(previousValue))
                Result[index] = Source[index];
            else
                Result[index] = Source[index] * expTrend + previousValue * (1 - expTrend);
                
                
            var previousValueBase = ResultBase[index - 1];
            
            if (double.IsNaN(previousValueBase))
                ResultBase[index] = Source[index];
            else
                ResultBase[index] = Source[index] * expBase + previousValueBase * (1 - expBase);
        }
    }
}


DU
duongss.trade

Joined on 20.11.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Double EMA trend.algo
  • Rating: 0
  • Installs: 873
Comments
Log in to add a comment.
No comments found.