Trend Regularity Adaptive Moving Average free

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

Adaptive moving average converted from Tradingview by LuxAlgo. Can be use like every other moving average. See link below for more information.

 

 

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
// Trend Regularity Adaptive Moving Average by LuxAlgo
// https://www.tradingview.com/script/p8wGCPi6-Trend-Regularity-Adaptive-Moving-Average-LUX/

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class TRAMA : Indicator
    {
        [Output("TRAMA", LineColor = "Aqua", Thickness = 2)]
        public IndicatorDataSeries Result { get; set; }

        [Parameter("Source", DefaultValue = "Close")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 100)]
        public int Length { get; set; }

        private IndicatorDataSeries high, low, hl;
        private SimpleMovingAverage sma;

        protected override void Initialize()
        {
            high = CreateDataSeries();
            low = CreateDataSeries();
            hl = CreateDataSeries();

            sma = Indicators.SimpleMovingAverage(hl, Length);
        }

        public override void Calculate(int index)
        {
            high[index] = Bars.HighPrices.Maximum(Length);
            low[index] = Bars.LowPrices.Minimum(Length);

            bool hh = high[index] - high[index - 1] > 0 ? true : false;
            bool ll = low[index - 1] - low[index] > 0 ? true : false;

            hl[index] = hh | ll ? 1.0 : 0.0;

            double tc = Math.Pow(sma.Result[index], 2);

            if (double.IsNaN(Result[index - 1]))
            {
                Result[index] = Source[index];
            }
            else
            {
                Result[index] = Result[index - 1] + tc * (Source[index] - Result[index - 1]);
            }
        }
    }
}
Comments

galafrin - September 06, 2021 @ 15:52

Thanks for uploading your code, At first sight it is remainder of ADX volatility , in fact it is quiet near   at double  the period but with a simpler code.

 

Chartshot http://spotware.ctrader.com/c/SwS3n

0