T3 Dynamics (T3 Moving Average Dynamics)

by Jan in category Other at 31/10/2019
Description

T3 Dynamics indicator attempts to measure T3 acceleration and velocity within the lookback period.

Histogram: Acceleration 

Line: Velocity

 

--- ! You should first be familiar with Tilson T3 indicator logic and behaviour before you try to use this indicator ! ---
 

References: 

T3 Moving Average https://ctrader.com/algos/indicators/show/2044. 
Dynamics calculation logic is the same as in MA Dynamics indicator https://ctrader.com/algos/indicators/show/2008


 

Download
79 downloads
How to install
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

// ------------------------------------------------------------------------------------
//                                   About T3
// ------------------------------------------------------------------------------------
//    T3 MA is a weighted sum of single EMA, double EMA, triple EMA etc
//    Original indicator Developed by Tim Tillson
//    Color & Min Threshold % features added by @Fibonacci2011 (Telegarm)
// ------------------------------------------------------------------------------------
//
//   The Triple Exponential Moving Average (T3) developed by Tim Tillson attempts to offers
//   a moving average with better smoothing then traditional exponential moving average.
//   It incorporates a smoothing technique which allows it to plot curves more gradual than
//   ordinary moving averages and with a smaller lag. 
//   Its smoothness is derived from the fact that it is a weighted sum of a single EMA, 
//   is formed, the price action will stay above or below the trend during most of its 
//   progression and will hardly be touched by any swings. Thus, a confirmed penetration of 
//   the T3 MA and the lack of a following reversal often indicates the end of a trend.
//
//   Added up & down colors and a Min Treshold % factor to filter out T3 “flat” periods. 
//   Min Treshold %  calculates the minimum accepter slope % change between start & stop bars.
//
// ------------------------------------------------------------------------------------
//                                 About T3 Dynamics
// ------------------------------------------------------------------------------------
// T3 Dynamics indicator attemps to measure T3 Acceleration and velocity within the lookback period
//
// References: 
//
// T3 Moving Average https://ctrader.com/algos/indicators/show/2044. 
// Dynamics calculation logic same as in MA Dynamics https://ctrader.com/algos/indicators/show/2008
//
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------



using System;
using System.Linq;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using System.Reflection;
using System.Globalization;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

using System.IO;
namespace cAlgo.Indicators
{

    [Levels(0)]
    [Indicator(IsOverlay = false, ScalePrecision = 1, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class T3Dynamics : Indicator
    {

        [Parameter()]

        public DataSeries Source { get; set; }


        [Parameter("T3 Period ", DefaultValue = 14)]
        public int Period { get; set; }

        [Parameter("T3 Volume Factor ", DefaultValue = 0.7)]
        public double Volume_Factor { get; set; }


        [Parameter("T3 Min Threshold % ", DefaultValue = 0.0)]
        public double minthr { get; set; }


        [Parameter("T3 Start Bar ", DefaultValue = 1)]
        public int startbar { get; set; }

        [Parameter("T3 Stop Bar ", DefaultValue = 2)]
        public int stopbar { get; set; }


        // ============ VELOCITY & ACCELERATION ==============


        [Parameter("Vel. & Acc. LookBack", DefaultValue = 20)]
        public int Lookback { get; set; }

        [Parameter("Method", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }

        public DataSeries MASource { get; set; }

        [Output("Velocity", LineColor = "Cyan")]
        public IndicatorDataSeries Vel { get; set; }
        [Output("Acceleration", LineColor = "83FFFF01", PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Acc { get; set; }

        // ================== LEVELS =========================
        [Parameter("TLevel 1 ", DefaultValue = 0)]
        public int Level1 { get; set; }


        [Output("Level 1", Color = Colors.Gold, Thickness = 1, PlotType = PlotType.Points)]
        public IndicatorDataSeries level1 { get; set; }

        [Output("Level -1", Color = Colors.Gold, Thickness = 1, PlotType = PlotType.Points)]
        public IndicatorDataSeries mlevel1 { get; set; }


        //   [Output("Level 2", Color = Colors.Gold, Thickness = 1, PlotType = PlotType.Points)]
        //    public IndicatorDataSeries level2 { get; set; }

        //    [Output("Level -2", Color = Colors.Gold, Thickness = 1, PlotType = PlotType.Points)]
        //    public IndicatorDataSeries mlevel2 { get; set; }

        [Output("ZeroLine", Color = Colors.Honeydew)]
        public IndicatorDataSeries zero { get; set; }

        // =============================================
        private ExponentialMovingAverage ema1;
        private ExponentialMovingAverage ema2;
        private ExponentialMovingAverage ema3;
        private ExponentialMovingAverage ema4;
        private ExponentialMovingAverage ema5;
        private ExponentialMovingAverage ema6;

        private MovingAverage MA;

        int lastindex = 0;



        protected override void Initialize()
        {
            MA = Indicators.MovingAverage(Source, Period, MAType);
            if (RunningMode == RunningMode.RealTime)
                IndicatorArea.DrawHorizontalLine("0", 0, Color.FromHex("78FFFFFF"));

            ema1 = Indicators.ExponentialMovingAverage(Source, Period);
            ema2 = Indicators.ExponentialMovingAverage(ema1.Result, Period);
            ema3 = Indicators.ExponentialMovingAverage(ema2.Result, Period);
            ema4 = Indicators.ExponentialMovingAverage(ema3.Result, Period);
            ema5 = Indicators.ExponentialMovingAverage(ema4.Result, Period);
            ema6 = Indicators.ExponentialMovingAverage(ema5.Result, Period);


        }

        public override void Calculate(int index)
        {

            if (IsLastBar)
            {
                if (index != lastindex)
                    lastindex = index;
                else
                    return;
            }

            var val = maketema(index);


            var avg = averageslope(startbar, stopbar, index);

            Vel[index] = (maketema(index) - maketema(index - Lookback)) / Symbol.PipSize;
            Acc[index] = Vel[index] - Vel[index - Lookback];


            //  level2[index] = Level2;
            level1[index] = Level1;

            mlevel1[index] = -Level1;
            //   mlevel2[index] = -Level2;
        }


//===========================================================================================
//                                 FUNCTIONS CALCULATION
//===========================================================================================


        double maketema(int index)
        {
            double b, b2, b3, c1, c2, c3, c4;

            b = Volume_Factor;

            b2 = Math.Pow(b, 2);

// Volume Factor Squared

            b3 = Math.Pow(b, 3);

// Volume Factor Cubed

            c1 = -b3;

            c2 = 3 * b2 + 3 * b3;

            c3 = -6 * b2 - 3 * b - 3 * b3;

            c4 = 1 + 3 * b + b3 + 3 * b2;

            var result = c1 * ema6.Result[index] + c2 * ema5.Result[index] + c3 * ema4.Result[index] + c4 * ema3.Result[index];

            return result;
        }


        double averageslope(int start, int end, int index)
        {

            var sum = 0.0;
            var count = 0;


            for (var i = index - end; i <= index - start; i++)
            {
                var p0 = maketema(i + 1);
                var p1 = maketema(i);
                var per = (p0 - p1) / p0 * 100;

                sum += per;
                count++;

            }

            return sum / count;
        }


        double r(double val)
        {

            return Math.Round(val, 1);
        }

        double rd(double val)
        {

            return Math.Round(val, 2);
        }


        double rdd(double val)
        {

            return Math.Round(val, Symbol.Digits);
        }

        double getdt()
        {
            var x1 = Chart.FirstVisibleBarIndex;
            var x2 = Chart.LastVisibleBarIndex;
            var dx = x2 - x1;
            var dt = MarketSeries.OpenTime[x2 - 1].Subtract(MarketSeries.OpenTime[x1]).TotalHours;

            return dt;

        }
    }
}


Comments
0