Category Trend  Published on 01/09/2022

TrendValue indicator

Description

The TrendValue indicator show trending zones for long and short trades


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 mTrendValue : Indicator
    {
        [Parameter("Range Period (10)", DefaultValue = 10, MinValue = 1, Group = "TrendValue")]
        public int inpRangePeriod { get; set; }
        [Parameter("ATR Period (10)", DefaultValue = 10, MinValue = 1, Group = "TrendValue")]
        public int inpATRPeriods { get; set; }
        [Parameter("ATR Sensitivity (1.618)", DefaultValue = 1.618, MinValue = 0.382, Group = "TrendValue")]
        public double inpATRSensitivity { get; set; }
        [Parameter("Smooth Type (sma)", DefaultValue = MovingAverageType.Simple, Group = "TrendValue")]
        public MovingAverageType inpSmoothType { get; set; }

        [Output("Trend Value", Thickness = 2, LineColor = "FF02AFF1")]
        public IndicatorDataSeries outTrendValue { get; set; }

        private MovingAverage _smah, _smal;
        private AverageTrueRange _atr;
        private IndicatorDataSeries _highSensivity, _lowSensivity, _trend, _tv;


        protected override void Initialize()
        {
            _smah = Indicators.MovingAverage(Bars.HighPrices, inpRangePeriod, inpSmoothType);
            _smal = Indicators.MovingAverage(Bars.LowPrices, inpRangePeriod, inpSmoothType);
            _atr = Indicators.AverageTrueRange(inpATRPeriods, inpSmoothType);
            _highSensivity = CreateDataSeries();
            _lowSensivity = CreateDataSeries();
            _trend = CreateDataSeries();
            _tv = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _highSensivity[i] = _smah.Result[i] * (1 + 0 / 100) + _atr.Result[i] * inpATRSensitivity;
            _lowSensivity[i] = _smal.Result[i] * (1 - 0 / 100) - _atr.Result[i] * inpATRSensitivity;

            if (i < inpRangePeriod)
            {
                _trend[i] = +1;
                _tv[i] = Bars.ClosePrices[i];
                return;
            }

            _trend[i] = _trend[i - 1];

            if (Bars.ClosePrices[i] > _highSensivity[i - 1])
                _trend[i] = +1;
            if (Bars.ClosePrices[i] < _lowSensivity[i - 1])
                _trend[i] = -1;

            if (_trend[i] > 0)
            {
                if (_lowSensivity[i] < _lowSensivity[i - 1])
                    _lowSensivity[i] = _lowSensivity[i - 1];
                _tv[i] = _lowSensivity[i];
            }
            if (_trend[i] < 0)
            {
                if (_highSensivity[i] > _highSensivity[i - 1])
                    _highSensivity[i] = _highSensivity[i - 1];
                _tv[i] = _highSensivity[i];
            }

            outTrendValue[i] = _tv[i];
        }
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mTrendValue.algo
  • Rating: 5
  • Installs: 998
Comments
Log in to add a comment.
AJ
aj47310 · 6 months ago

Good to see that the TrendValue indicator show trending zones for long and short trades and it is good for us to learn more. You can see page to check website so you can view details about it and make a decision what is the best for you.


 

LO
lohip36065 · 1 year ago

Its a very nice post for the TrendValue indicator free and there are many ideas we can use to find the best results. By using the bestwritingsclues I saw many users are getting help to find the results they want. Good to have the right results we want.