Double Ema Trend free

by duongss.trade in category Trend at 20/11/2022
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

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
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);
        }
    }
}
Comments
0