Category Oscilators  Published on 18/01/2023

Shadow True Strength Index indicator

Description

Shadow True Strength Index indicator

Use shadow color as trade sentiment; green for Long; red for Short


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

namespace cAlgo
{
    [Cloud("ZoneUp", "ZoneDn", FirstColor = "Green", SecondColor = "Red", Opacity = 0.1)]  
    [Levels(-25.0, 0.0, +25.0)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mTSIshadow : Indicator
    {
        [Parameter("Source (close)")]
        public DataSeries inpDataSeries { get; set; }
        [Parameter("Smooth Fast Periods (7)", DefaultValue = 7)]
        public int inpSmoothFastPeriods { get; set; }
        [Parameter("Smooth Slow Periods (14)", DefaultValue = 14)]
        public int inpSmoothSlowPeriods { get; set; }
        [Parameter("Smooth Shadow Period 1 (14)", DefaultValue = 14)]
        public int inpSmoothPeriod1 { get; set; }
        [Parameter("Smooth Type 1 (sma)", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType1 { get; set; }
        [Parameter("Smooth Shadow Period 2 (14)", DefaultValue = 14)]
        public int inpSmoothPeriod2 { get; set; }
        [Parameter("Smooth Type 2 (sma)", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType2 { get; set; }

        [Output("TSI", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTSI { get; set; }
        [Output("Shadow 1", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outShadow1 { get; set; }
        [Output("Shadow 2", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outShadow2 { get; set; }
        [Output("ZoneUp", LineColor = "Transparent")]
        public IndicatorDataSeries outZoneUp { get; set; }
        [Output("ZoneDn", LineColor = "Transparent")]
        public IndicatorDataSeries outZoneDn { get; set; }
        
        private MovingAverage _pr, _sm1udm, _sm2udm,  _sm1adm, _sm2adm, _shadow1, _shadow2;
        private IndicatorDataSeries _udm, _adm, _tsi;
        

        protected override void Initialize()
        {
            _pr = Indicators.MovingAverage(inpDataSeries, 1, MovingAverageType.Simple);
            _udm = CreateDataSeries();
            _adm = CreateDataSeries();
            _tsi = CreateDataSeries();
            _sm1udm = Indicators.MovingAverage(_udm, inpSmoothFastPeriods, MovingAverageType.Exponential);
            _sm2udm = Indicators.MovingAverage(_sm1udm.Result, inpSmoothSlowPeriods, MovingAverageType.Exponential);
            _sm1adm = Indicators.MovingAverage(_adm, inpSmoothFastPeriods, MovingAverageType.Exponential);
            _sm2adm = Indicators.MovingAverage(_sm1adm.Result, inpSmoothSlowPeriods, MovingAverageType.Exponential);
            _shadow1 = Indicators.MovingAverage(_tsi, inpSmoothPeriod1, inpSmoothType1);
            _shadow2 = Indicators.MovingAverage(_shadow1.Result, inpSmoothPeriod2, inpSmoothType2);
        }

        public override void Calculate(int i)
        {
            _udm[i] = i>1 ? _pr.Result[i] - _pr.Result[i-1] : _pr.Result[i] - Bars.TypicalPrices[i];
            _adm[i] = Math.Abs(_udm[i]);
            _tsi[i] = (_sm2adm.Result[i] != 0 ? 100 * _sm2udm.Result[i] / _sm2adm.Result[i] : 0);
            
            outTSI[i] = _tsi[i];
            outShadow1[i] = _shadow1.Result[i];
            outShadow2[i] = _shadow2.Result[i];            
            outZoneUp[i] = outZoneDn[i] = _tsi[i];
            if(_tsi[i] > _shadow1.Result[i] && _tsi[i] > _shadow2.Result[i])
                outZoneDn[i] = Math.Max(_shadow1.Result[i], _shadow2.Result[i]);
            if(_tsi[i] < _shadow1.Result[i] && _tsi[i] < _shadow2.Result[i])
                outZoneDn[i] = Math.Min(_shadow1.Result[i], _shadow2.Result[i]);
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mTSIshadow.algo
  • Rating: 5
  • Installs: 750
Comments
Log in to add a comment.
LA
larkimpressive · 1 month ago

Your post has aided in my comprehension of the subject.
 

SE
SebastianENewell · 5 months ago

Nice post!

WE
wedgemunch · 5 months ago
VE
veronicacrandall236 · 10 months ago

Your article was a big help understanding concept.

ZE
Zeldafarah10 · 1 year ago

Fantastic post; you've pointed up some 2048 really good points. I too think this is a really great website. I'll come back for more high-quality articles and will also tell everyone about this website. Thanks.