MRPLOverlay free

by srm_bcn in category Trend at 21/02/2021
Description

Ladies and gentlemen, welcome.

Today I propose as a curiosity an indicator based on two concepts: Mean reversion and time noise filtering.

Designed for TFm1.

Instead of price, the trend lines are calculated from the white line that tries to simulate a renko chart.

I hope you like it and enjoy it.

Dedicated to trading heroes.

Affectionately,

Sergio Raimi

 

This is how it looks on TFt1. The core.

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 cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MRPLOverlay : Indicator
    {
        [Output("Result1", LineColor = "lightGreen")]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("Result2", LineColor = "Red")]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("Result3", LineColor = "DodgerBlue")]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("Result4", LineColor = "DodgerBlue")]
        public IndicatorDataSeries Result4 { get; set; }

        [Output("Result5", LineColor = "DodgerBlue")]
        public IndicatorDataSeries Result5 { get; set; }

        [Output("Result6", LineColor = "White")]
        public IndicatorDataSeries Result6 { get; set; }

        private Bars tf;

        private int idx;
        private int previousIdx;
        private int buyPeriod;
        private int sellPeriod;

        private double buyAverage;
        private double sellAverage;
        private int savedbp;
        private int savedsp;
        private double CenterMean, UpperMean, LowerMean;

        private double price, previousLevel;
        private IndicatorDataSeries level;

        protected override void Initialize()
        {
            tf = MarketData.GetBars(Bars.TimeFrame);
            level = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            idx = tf.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (idx > previousIdx)
            {
                buyPeriod++;
                savedbp = buyPeriod;
                sellPeriod++;
                savedsp = sellPeriod;
            }

            if (buyPeriod == 0)
                buyPeriod = savedbp;

            if (sellPeriod == 0)
                sellPeriod = savedsp;

            //---------------------------------------------------------------------------------------------------------------------------------------------------------

            price = Bars.ClosePrices[index];
            level[index] = Math.Round(price, 4);

            if (level[index] > previousLevel)
                if (price < level[index])
                    level[index] = level[index] - 0.0001;

            if (level[index] < previousLevel)
                if (price > level[index])
                    level[index] = level[index] + 0.0001;

            //---------------------------------------------------------------------------------------------------------------------------------------------------------


            buyAverage = level.Sum(buyPeriod) / buyPeriod;
            sellAverage = level.Sum(sellPeriod) / sellPeriod;

            if (level[index] > buyAverage)
            {
                buyAverage = level[index];
                buyPeriod = 0;
            }

            if (level[index] < sellAverage)
            {
                sellAverage = level[index];
                sellPeriod = 0;
            }

            CenterMean = (buyAverage + sellAverage) / 2;
            UpperMean = (buyAverage + CenterMean) / 2;
            LowerMean = (CenterMean + sellAverage) / 2;

            Result1[index] = sellAverage;
            Result2[index] = buyAverage;
            Result3[index] = CenterMean;
            Result4[index] = UpperMean;
            Result5[index] = LowerMean;
            Result6[index] = level[index];

            previousIdx = idx;
            previousLevel = level[index];
        }
    }
}
Comments
0