Category Trend  Published on 21/02/2021

iTrend

Description

iTrend is a trend indicator.
This version for cTrader has been based on this indicator for MT5 by Nikolay Kositsin, which in turn is based on previous work by other authors:

https://www.mql5.com/es/code/2002

The indicator has two lines: bullish (green) and bearish (red).
If the bullish line is above the bearish line the price is trending upwards.
If the bearish line is above the bullish line the price is trending downwards.

The lines are calculated with an exponential moving average (EMA) as follows:

Bullish line = close - EMA
Bearish line = - (low + high - 2*EMA) 


 

iTrend indicator on EURUSD H1

 


/*
The indicator has two lines: bullish (green) and bearish (red).
If the bullish line is above the bearish line the price is 
trending upwards.
If the bearish line is above the bullish line the price is 
trending downwards.

This indicator has been based on this trend indicator 
form MT5:
https://www.mql5.com/es/code/2002

*/
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class iTrend : Indicator
    {
        [Parameter("Price", DefaultValue = PriceType.CLOSE_PRICE)]
        public PriceType ParamPriceType { get; set; }

        [Parameter("Period", DefaultValue = 13, MinValue = 1)]
        public int ParamMAPeriod { get; set; }

        [Output("Bullish line", LineColor = "Lime", PlotType = PlotType.Line, LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries bullishLine { get; set; }

        [Output("Bearish line", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries bearishLine { get; set; }

        private MovingAverage ma;

        protected override void Initialize()
        {
            switch (this.ParamPriceType)
            {
                case PriceType.TYPICAL_PRICE:
                    this.ma = Indicators.MovingAverage(Bars.TypicalPrices, this.ParamMAPeriod, MovingAverageType.Exponential);
                    break;
                case PriceType.MEDIAN_PRICE:
                    this.ma = Indicators.MovingAverage(Bars.MedianPrices, this.ParamMAPeriod, MovingAverageType.Exponential);
                    break;
                case PriceType.WEIGHTED_PRICE:
                    this.ma = Indicators.MovingAverage(Bars.WeightedPrices, this.ParamMAPeriod, MovingAverageType.Exponential);
                    break;
                case PriceType.CLOSE_PRICE:
                default:
                    this.ma = Indicators.MovingAverage(Bars.ClosePrices, this.ParamMAPeriod, MovingAverageType.Exponential);
                    break;
            }
        }

        public override void Calculate(int index)
        {
            double price;
            switch (this.ParamPriceType)
            {
                case PriceType.TYPICAL_PRICE:
                    price = Bars.TypicalPrices[index];
                    break;
                case PriceType.MEDIAN_PRICE:
                    price = Bars.MedianPrices[index];
                    break;
                case PriceType.WEIGHTED_PRICE:
                    price = Bars.WeightedPrices[index];
                    break;
                case PriceType.CLOSE_PRICE:
                default:
                    price = Bars.ClosePrices[index];
                    break;
            }

            bullishLine[index] = price - this.ma.Result[index];
            bearishLine[index] = -(Bars.LowPrices[index] + Bars.HighPrices[index] - 2 * this.ma.Result[index]);
        }
    }

    public enum PriceType
    {
        CLOSE_PRICE,
        TYPICAL_PRICE,
        MEDIAN_PRICE,
        WEIGHTED_PRICE
    }
}


GU
guillermo

Joined on 07.06.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: iTrend.algo
  • Rating: 5
  • Installs: 1841
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
KI
kimsumneroz95 · 2 years ago

I love the version of cTrader! mt4/mt5 plugins providers really love this kind of indicator.