Category Trend  Published on 13/03/2023

Hoanh

Description

Hoanh trang in the mix


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 UTBOT : Indicator
    {
        [Parameter("Key", DefaultValue = 1)]
        public double keyvalue { get; set; }
        [Parameter("ATR Period", DefaultValue = 10)]
        public int atrperiod { get; set; }

        private AverageTrueRange xATR;

        [Output("UpTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "Green")]
        public IndicatorDataSeries XATRTrailingStopGreen { get; set; }
        [Output("Continuos", PlotType = PlotType.DiscontinuousLine, LineColor = "Green")]
        public IndicatorDataSeries XATRTrailingStop { get; set; }
        [Output("DownTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "Red")]
        public IndicatorDataSeries XATRTrailingStopRed { get; set; }

        protected override void Initialize()
        {
            xATR = Indicators.AverageTrueRange(atrperiod, MovingAverageType.Exponential);
        }

        public override void Calculate(int index)
        {
            double nLoss = keyvalue * xATR.Result[index];
            XATRTrailingStop[index] = (MarketSeries.Close[index] > XATRTrailingStop[index - 1] && MarketSeries.Close[index - 1] > XATRTrailingStop[index - 1]) ? Math.Max(XATRTrailingStop[index - 1], MarketSeries.Close[index] - nLoss) : (MarketSeries.Close[index] < XATRTrailingStop[index - 1] && MarketSeries.Close[index - 1] < XATRTrailingStop[index - 1]) ? Math.Min(XATRTrailingStop[index - 1], MarketSeries.Close[index] + nLoss) : (MarketSeries.Close[index] > XATRTrailingStop[index - 1]) ? MarketSeries.Close[index] - nLoss : MarketSeries.Close[index] + nLoss;
            XATRTrailingStopGreen[index] = XATRTrailingStop[index] < MarketSeries.Close[index] ? XATRTrailingStop[index] : double.NaN;
            XATRTrailingStopRed[index] = XATRTrailingStop[index] > MarketSeries.Close[index] ? XATRTrailingStop[index] : double.NaN;
        }
    }
}


HO
hoanhtrang09

Joined on 13.03.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: UT BOT.algo
  • Rating: 0
  • Installs: 484
  • Modified: 13/03/2023 09:00
Comments
Log in to add a comment.
GM
gmkenneyy · 1 year ago

Thanks for uploading this indicator. 

I'm afraid theres a small bug in your code

Change the colour of the Continuos line to Yellow (or any colour other than green) - and the resulting line will show only two colours instead of three.