Category Trend  Published on 23/08/2021

TrendTrader6

Description

"The Ultimate Bar Color Indicator". This indicator uses VMA, VWAP, Supertrend and a VARIATION (not original) of a secret indicator ( Rafi, an ADX-based indicator) created by a famous brazillian trader. This indicator is one of the best tools for identify trends or trading ranges. 

Knowledge should not be sold. My mission is provide free and professional tools for all. You dont need to thank me, just get rich.

Dont forget to install a dependency indicator to make this indicator work. Link below:: 

Enjoy :3 

 :3

 


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class AdxVma : Indicator
    {
        private double _k;

        private IndicatorDataSeries _iSeries;
        private IndicatorDataSeries _iSeries2;
        private IndicatorDataSeries _mdiSeries;
        private IndicatorDataSeries _mdmSeries;
        private IndicatorDataSeries _pdiSeries;
        private IndicatorDataSeries _pdmSeries;

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

        [Parameter(DefaultValue = 72)]
        public int Period { get; set; }

        [Parameter(DefaultValue = 1)]
        public int LookBack { get; set; }

        //[Output("Rising", Color = Colors.Green, PlotType = PlotType.Points, Thickness = 4)]
        private IndicatorDataSeries Rising { get; set; }

        //[Output("Falling", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 4)]
        private IndicatorDataSeries Falling { get; set; }

        //[Output("Flat", Color = Colors.DarkGray, PlotType = PlotType.Points, Thickness = 2)]
        private IndicatorDataSeries Flat { get; set; }

        //[Output("Result", Color = Colors.Black)]
        private IndicatorDataSeries Result { get; set; }

        //[Output("Result2", Color = Colors.Black)]
        private IndicatorDataSeries Result2 { get; set; }

        private Supertrend strend;

        private DirectionalMovementSystem adx;

        private IndicatorDataSeries temp_ADX { get; set; }

        private IndicatorDataSeries MACD_ADX { get; set; }

        private IndicatorDataSeries Signal_ADX { get; set; }

        private IndicatorDataSeries ResultMACD { get; set; }

        private IndicatorDataSeries ResultSignal { get; set; }

        private MovingAverage Slow_ADX;

        private MovingAverage Fast_ADX;

        private MovingAverage Signal;

        private VWAPs vwap;

        private int lastIndex = 0;

        protected override void Initialize()
        {

            _pdmSeries = CreateDataSeries();
            _mdmSeries = CreateDataSeries();
            _pdiSeries = CreateDataSeries();
            _mdiSeries = CreateDataSeries();
            _iSeries = CreateDataSeries();
            _iSeries2 = CreateDataSeries();

            Rising = CreateDataSeries();
            Falling = CreateDataSeries();
            Flat = CreateDataSeries();
            Result = CreateDataSeries();
            Result2 = CreateDataSeries();

            temp_ADX = CreateDataSeries();
            MACD_ADX = CreateDataSeries();
            Signal_ADX = CreateDataSeries();

            adx = Indicators.DirectionalMovementSystem(14);

            Fast_ADX = Indicators.MovingAverage(temp_ADX, 6, MovingAverageType.Exponential);
            Slow_ADX = Indicators.MovingAverage(temp_ADX, 13, MovingAverageType.Exponential);

            Signal = Indicators.MovingAverage(MACD_ADX, 9, MovingAverageType.Exponential);

            vwap = Indicators.GetIndicator<VWAPs>(true);

            ResultMACD = CreateDataSeries();

            ResultSignal = CreateDataSeries();

            _k = 1.0 / Period;

            strend = Indicators.Supertrend(100, 10);
        }


        public override void Calculate(int index)
        {
            if (index > lastIndex)
            {
                OnBarClosed(lastIndex);
                lastIndex = index;
            }
        }

        private void OnBarClosed(int index)
        {
            if (index < LookBack)
            {
                _pdmSeries[index] = 0;
                _mdmSeries[index] = 0;
                _pdiSeries[index] = 0;
                _mdiSeries[index] = 0;
                _iSeries[index] = 0;
                _iSeries2[index] = 0;
                _pdmSeries[index] = 0;
                Result[index] = Source[index];
                return;
            }

            double pdm = Math.Max((Source[index] - Source[index - 1]), 0);
            double mdm = Math.Max((Source[index - 1] - Source[index]), 0);

            _pdmSeries[index] = ((1 - _k) * _pdmSeries[index - 1] + _k * pdm);
            _mdmSeries[index] = ((1 - _k) * _mdmSeries[index - 1] + _k * mdm);

            double sum = _pdmSeries[index] + _mdmSeries[index];
            double pdi = 0.0;
            double mdi = 0.0;

            if (sum > double.Epsilon)
            {
                pdi = _pdmSeries[index] / sum;
                mdi = _mdmSeries[index] / sum;
            }

            _pdiSeries[index] = ((1 - _k) * _pdiSeries[index - 1] + _k * pdi);
            _mdiSeries[index] = ((1 - _k) * _mdiSeries[index - 1] + _k * mdi);

            double diff = Math.Abs(_pdiSeries[index] - _mdiSeries[index]);

            sum = _pdiSeries[index] + _mdiSeries[index];

            if (sum > double.Epsilon)
                _iSeries[index] = ((1 - _k) * _iSeries[index - LookBack] + _k * diff / sum);

            if (sum > double.Epsilon)
                _iSeries2[index] = ((1 - _k) * _iSeries2[index - 1] + _k * diff / sum);


            double hhv = Math.Max(_iSeries[index], _iSeries.Maximum(Period));
            double llv = Math.Min(_iSeries[index], _iSeries.Minimum(Period));

            double hhv2 = Math.Max(_iSeries2[index], _iSeries2.Maximum(Period));
            double llv2 = Math.Min(_iSeries2[index], _iSeries2.Minimum(Period));

            diff = hhv - llv;

            double diff2 = hhv2 - llv2;

            double vIndex = 0;

            double vIndex2 = 0;

            if (diff > double.Epsilon)
                vIndex = (_iSeries[index] - llv) / diff;

            Result[index] = (1 - _k * vIndex) * Result[index - 1] + _k * vIndex * Source[index];

            if (diff2 > double.Epsilon)
                vIndex2 = (_iSeries2[index] - llv2) / diff2;

            Result2[index] = (1 - _k * vIndex2) * Result2[index - 1] + _k * vIndex2 * Source[index];



            Rising[index] = double.NaN;
            Falling[index] = double.NaN;
            Flat[index] = double.NaN;

            if (Result.IsRising())
                Rising[index] = Result[index];

            else if (Result.IsFalling())
                Falling[index] = Result[index];
            else

                Flat[index] = Result[index];


            temp_ADX[index] = Math.Abs(adx.DIPlus[index] - adx.DIMinus[index]);

            MACD_ADX[index] = (Fast_ADX.Result[index] - Slow_ADX.Result[index]);

            ResultMACD[index] = MACD_ADX[index];


            if (double.IsNaN(Signal.Result[index]) == false)
                ResultSignal[index] = Signal.Result[index];


            // Colors Setup -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            Chart.SetBarColor(index, Color.FromArgb(255, 40, 40, 40));


            if (Bars.ClosePrices[index] > Result[index] && Bars.ClosePrices[index] > Bars.OpenPrices[index] && Result.IsRising())
            {



                if (double.IsNaN(strend.UpTrend[index]) == false && Bars.ClosePrices[index] > strend.UpTrend[index])
                {
                    Chart.SetBarColor(index, Color.FromArgb(255, 0, 70, 0));
                }

                else
                {
                    Chart.SetBarColor(index, Color.FromArgb(255, 255, 255, 255));

                }

                if (ResultMACD[index] > ResultSignal[index] && ResultMACD[index] > 0 && adx.DIPlus[index] > adx.DIMinus[index] && Bars.ClosePrices[index] > vwap.Result[index])
                {

                    Chart.SetBarColor(index, Color.FromArgb(255, 0, 150, 0));

                }


            }

            else if (Bars.ClosePrices[index] < Result[index] && Bars.ClosePrices[index] < Bars.OpenPrices[index] && Result.IsFalling())
            {

                if (double.IsNaN(strend.DownTrend[index]) == false && Bars.ClosePrices[index] < strend.DownTrend[index])
                {
                    Chart.SetBarColor(index, Color.FromArgb(200, 70, 0, 0));
                }

                else
                {
                    Chart.SetBarColor(index, Color.FromArgb(255, 255, 255, 255));

                }

                if (ResultMACD[index] > ResultSignal[index] && ResultMACD[index] > 0 && adx.DIPlus[index] < adx.DIMinus[index] && Bars.ClosePrices[index] < vwap.Result[index] && double.IsNaN(strend.DownTrend[index]) == false && Bars.ClosePrices[index] < strend.DownTrend[index])
                {

                    Chart.SetBarColor(index, Color.FromArgb(255, 150, 0, 0));

                }
            }

            else if (Bars.ClosePrices[index] < Result[index] && Bars.ClosePrices[index] < Bars.OpenPrices[index])
            {
                if (double.IsNaN(strend.DownTrend[index]) == false && Bars.ClosePrices[index] < strend.DownTrend[index])
                {

                    Chart.SetBarColor(index, Color.FromArgb(255, 70, 0, 0));
                }

                else if (double.IsNaN(strend.UpTrend[index]) == false && Bars.ClosePrices[index] > strend.UpTrend[index])
                {
                    Chart.SetBarColor(index, Color.FromArgb(255, 255, 255, 255));
                }
            }


            else if (Bars.ClosePrices[index] > Result[index] && Bars.ClosePrices[index] > Bars.OpenPrices[index])
            {
                if (double.IsNaN(strend.UpTrend[index]) == false && Bars.ClosePrices[index] > strend.UpTrend[index])
                {

                    Chart.SetBarColor(index, Color.FromArgb(255, 0, 70, 0));
                }

                else if (double.IsNaN(strend.DownTrend[index]) == false && Bars.ClosePrices[index] < strend.DownTrend[index])
                {
                    Chart.SetBarColor(index, Color.FromArgb(255, 255, 255, 255));
                }



            }
        }

    }
}


AN
andurei

Joined on 30.09.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: TrendTrader6.algo
  • Rating: 5
  • Installs: 2538
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
MU
mustaphaplan · 6 months ago

Looks an interesting indie.  But how do you use it?  Seems pretty pointless, posting if there are no instructions.

Any help would be useful?

MO
moda.house.for.you · 2 years ago

The vast ambition and high standard of life in Australia have prompted many to seek out this educational destination for further studies. However, they also face numerous challenges including intense training and multiple assignments. In such a situation, Assignment Help services in Australia  https://www.assignmenthelper.com.au/accounting-assignment-help/ prove to be a godsend. Students can save their time, money and effort by availing these services. Here are some of the main reasons why students choose AssignmentHelper.com.au for their academic requirements.

MO
moda.house.for.you · 2 years ago

The vast ambition and high standard of life in Australia have prompted many to seek out this educational destination for further studies. However, they also face numerous challenges including intense training and multiple assignments. In such a situation, Assignment Help services in Australia prove to be a godsend. Students can save their time, money and effort by availing these services. Here are some of the main reasons why students choose AssignmentHelper.com.au for their academic requirements.

Y.
Y.M. · 3 years ago

Thank you for providing this indicator andurei. Do you have also a manual which explains the idea of the indicator?