TX Color free

by cW22Trader in category Trend at 04/09/2021
Description

This is a generalized version of the T3 indciator by Tim Tillson. It is based on an indicator published by user jani:

In this version it is possible to set any order since the coefficients are caluculated based on the binomial formula. Setting the order to 6 will produce the same result as the orginal indicator by Tim Tillson.

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 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
{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]

    public class TXMA : Indicator
    {

        [Parameter()]
        public DataSeries Source { get; set; }

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

        [Parameter("Order ", DefaultValue = 6, MinValue = 3)]
        public int Order { get; set; }

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

        [Parameter("Show Direction ", DefaultValue = true)]
        public bool showDirection { get; set; }


        [Parameter("Min Threshold ", DefaultValue = 0.0, Step = 0.001, MinValue = 0)]
        public double minthr { get; set; }

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

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


        [Output("TXMA steady", LineColor = "Gray", PlotType = PlotType.DiscontinuousLine, Thickness = 3)]
        public IndicatorDataSeries steady { get; set; }

        [Output("TXMA rise", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, Thickness = 3)]
        public IndicatorDataSeries rise { get; set; }

        [Output("TXMA fall", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 3)]
        public IndicatorDataSeries fall { get; set; }

        private ExponentialMovingAverage[] ema;
        private double[] coeff;


        protected override void Initialize()
        {
            ema = new ExponentialMovingAverage[Order];

            ema[0] = Indicators.ExponentialMovingAverage(Source, Period);

            for (int i = 1; i < Order; i++)
            {
                ema[i] = Indicators.ExponentialMovingAverage(ema[i - 1].Result, Period);
            }

            double a, b;

            b = Volume_Factor;
            a = 1.0 + b;

            coeff = new double[Order - 2];

            for (int i = 0; i < Order - 2; i++)
            {
                coeff[i] = binomialCoeff(Order - 3, i) * Math.Pow(a, Order - 3 - i) * Math.Pow(-b, i);
            }
        }


        public override void Calculate(int index)
        {
            double val = maketema(index);

            if (showDirection)
            {
                double avg = averageslope(startbar, stopbar, index);

                int mode = (avg > minthr) ? 1 : (avg < -minthr) ? -1 : 0;

                rise[index] = (mode == 1) ? val : double.NaN;
                fall[index] = (mode == -1) ? val : double.NaN;
            }

            steady[index] = val;
        }


        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 maketema(int index)
        {
            double result = 0.0;

            for (int i = 0; i < Order - 2; i++)
            {
                result += coeff[i] * ema[i + 2].Result[index];
            }

            return result;

        }

        // Returns value of Binomial Coefficient C(n, k)
        int binomialCoeff(int n, int k)
        {
            // Base Cases
            if (k > n)
                return 0;
            if (k == 0 || k == n)
                return 1;

            // Recur
            return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
        }
    }
}
Comments
0