Category Oscilators  Published on 18/01/2023

SuperTrend (colored version)

Description

This is the same indicator as the one from API indicators; only the shadow sentiment is added for visual clarity


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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mSuperTrend : Indicator
    {
        [Parameter("Period (10)", DefaultValue = 10, Group = "SuperTrend")]
        public int inpPeriod { get; set; }
        [Parameter("Multiplier (3)", DefaultValue = 3.0, Group = "SuperTrend")]
        public double inpMultiplier { get; set; }
        [Parameter("ShowContinualLine (yes)", DefaultValue = true, Group = "Additional")]
        public bool inpShowContinualLine { get; set; }


        [Output("Main", LineColor = "Gray", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outMain { get; set; }
        [Output("UpTrend", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
        public IndicatorDataSeries outUpTrend { get; set; }
        [Output("DownTrend", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
        public IndicatorDataSeries outDownTrend { get; set; }


        private Supertrend _supertrend;


        protected override void Initialize()
        {
            _supertrend = Indicators.Supertrend(inpPeriod, inpMultiplier);
        }

        public override void Calculate(int i)
        {
            if (i < inpPeriod)
            {
                outMain[i] = Bars.ClosePrices[i];
                outUpTrend[i] = double.NaN;
                outDownTrend[i] = double.NaN;
                return;
            }

            if (inpShowContinualLine == true)
                outMain[i] = (!double.IsNaN(_supertrend.UpTrend[i]) ? _supertrend.UpTrend[i] : _supertrend.DownTrend[i]);
            else
                outMain[i] = double.NaN;
            outUpTrend[i] = _supertrend.UpTrend[i];
            outDownTrend[i] = _supertrend.DownTrend[i];
        }
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mSuperTrend.algo
  • Rating: 5
  • Installs: 402
Comments
Log in to add a comment.
No comments found.