Category Trend  Published on 05/06/2023

BJ TSI

Description

using System;<font></font>

using cAlgo.API;<font></font>

using cAlgo.API.Indicators;<font></font>

<font></font>

namespace cAlgo<font></font>

{<font></font>

    [Levels(-25, 0, 25)]<font></font>

    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]<font></font>

    public class TrueStrengthIndex : Indicator<font></font>

    {<font></font>

        // Double Smoothed PC<font></font>

        // PC = Current Price minus Prior Price<font></font>

        // First Smoothing = 25-period EMA of PC<font></font>

        // Second Smoothing = 13-period EMA of 25-period EMA of PC<font></font>

<font></font>

        // Double Smoothed Absolute PC<font></font>

        // Absolute Price Change |PC| = Absolute Value of Current Price minus Prior Price<font></font>

        // First Smoothing = 25-period EMA of |PC|<font></font>

        // Second Smoothing = 13-period EMA of 25-period EMA of |PC|<font></font>

<font></font>

        // TSI = 100 x (Double Smoothed PC / Double Smoothed Absolute PC)<font></font>

<font></font>

        [Parameter("Source")]<font></font>

        public DataSeries Source { get; set; }<font></font>

<font></font>

        [Parameter("First Smoothing", DefaultValue = 25, MinValue = 1)]<font></font>

        public int FirstSmoothingPeriods { get; set; }<font></font>

<font></font>

        [Parameter("Second Smoothing", DefaultValue = 13, MinValue = 1)]<font></font>

        public int SecondSmoothingPeriods { get; set; }<font></font>

<font></font>

        [Parameter("Signal Periods", DefaultValue = 7, MinValue = 1)]<font></font>

        public int SignalPeriods { get; set; }<font></font>

<font></font>

        [Output("TSI", LineColor = "DodgerBlue")]<font></font>

        public IndicatorDataSeries TSI { get; set; }<font></font>

<font></font>

        [Output("Signal", LineColor = "Red")]<font></font>

        public IndicatorDataSeries Signal { get; set; }<font></font>

<font></font>

        private IndicatorDataSeries PC, APC;<font></font>

        private ExponentialMovingAverage FirstSmoothingPC, SecondSmoothingPC, FirstSmoothingAPC, SecondSmoothingAPC;<font></font>

        private ExponentialMovingAverage SignalEMA;<font></font>

<font></font>

        protected override void Initialize()<font></font>

        {<font></font>

            PC = CreateDataSeries();<font></font>

            FirstSmoothingPC = Indicators.ExponentialMovingAverage(PC, FirstSmoothingPeriods);<font></font>

            SecondSmoothingPC = Indicators.ExponentialMovingAverage(FirstSmoothingPC.Result, SecondSmoothingPeriods);<font></font>

<font></font>

            APC = CreateDataSeries();<font></font>

            FirstSmoothingAPC = Indicators.ExponentialMovingAverage(APC, FirstSmoothingPeriods);<font></font>

            SecondSmoothingAPC = Indicators.ExponentialMovingAverage(FirstSmoothingAPC.Result, SecondSmoothingPeriods);<font></font>

<font></font>

            SignalEMA = Indicators.ExponentialMovingAverage(TSI, SignalPeriods);<font></font>

        }<font></font>

<font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

        public override void Calculate(int index)</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

        {</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

            PC[indice] = Source[indice] - Source[indice - 1] ;</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

            APC[index] = Math.Abs(PC[index]);</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

            TSI[index] = 100 * (SecondSmoothingPC.Result[index] / SecondSmoothingAPC.Result[index]);</font></font><font></font>

<font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

            Signal[index] = SignalEMA.Résultat[index] ;</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

        }</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

    }</font></font><font></font><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">

}</font></font><font></font>


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

namespace cAlgo
{
    [Levels(-25, 0, 25)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class TrueStrengthIndex : Indicator
    {
        // Double Smoothed PC
        // PC = Current Price minus Prior Price
        // First Smoothing = 25-period EMA of PC
        // Second Smoothing = 13-period EMA of 25-period EMA of PC

        // Double Smoothed Absolute PC
        // Absolute Price Change |PC| = Absolute Value of Current Price minus Prior Price
        // First Smoothing = 25-period EMA of |PC|
        // Second Smoothing = 13-period EMA of 25-period EMA of |PC|

        // TSI = 100 x (Double Smoothed PC / Double Smoothed Absolute PC)

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

        [Parameter("First Smoothing", DefaultValue = 25, MinValue = 1)]
        public int FirstSmoothingPeriods { get; set; }

        [Parameter("Second Smoothing", DefaultValue = 13, MinValue = 1)]
        public int SecondSmoothingPeriods { get; set; }

        [Parameter("Signal Periods", DefaultValue = 7, MinValue = 1)]
        public int SignalPeriods { get; set; }

        [Output("TSI", LineColor = "DodgerBlue")]
        public IndicatorDataSeries TSI { get; set; }

        [Output("Signal", LineColor = "Red")]
        public IndicatorDataSeries Signal { get; set; }

        private IndicatorDataSeries PC, APC;
        private ExponentialMovingAverage FirstSmoothingPC, SecondSmoothingPC, FirstSmoothingAPC, SecondSmoothingAPC;
        private ExponentialMovingAverage SignalEMA;

        protected override void Initialize()
        {
            PC = CreateDataSeries();
            FirstSmoothingPC = Indicators.ExponentialMovingAverage(PC, FirstSmoothingPeriods);
            SecondSmoothingPC = Indicators.ExponentialMovingAverage(FirstSmoothingPC.Result, SecondSmoothingPeriods);

            APC = CreateDataSeries();
            FirstSmoothingAPC = Indicators.ExponentialMovingAverage(APC, FirstSmoothingPeriods);
            SecondSmoothingAPC = Indicators.ExponentialMovingAverage(FirstSmoothingAPC.Result, SecondSmoothingPeriods);

            SignalEMA = Indicators.ExponentialMovingAverage(TSI, SignalPeriods);
        }

        public override void Calculate(int index)
        {
            PC[index] = Source[index] - Source[index - 1];
            APC[index] = Math.Abs(PC[index]);
            TSI[index] = 100 * (SecondSmoothingPC.Result[index] / SecondSmoothingAPC.Result[index]);

            Signal[index] = SignalEMA.Result[index];
        }
    }
}


FT
ftmo1685059507

Joined on 05.06.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: True Strength Index.algo
  • Rating: 0
  • Installs: 324
Comments
Log in to add a comment.
No comments found.