Category Oscilators  Published on 25/01/2023

Internal Strength indicator

Description

The Internal Strength indicator shows bar strength and direction, attempting to identify the bar's impulse by touching the upper and lower bands.


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

namespace cAlgo
{
    [Levels(0.5, 10, 50, 90)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mInternalStrength : Indicator
    {
        [Parameter("DrawMode (RAW)", DefaultValue = enumDrawMode.DrawRAW)]
        public enumDrawMode inpDrawMode { get; set; } 
        [Parameter("Period (2)", DefaultValue = 2)]
        public int inpPeriod { get; set; }

        [Parameter("Bands Periods (200)", DefaultValue = 200)]
        public int inpPeriodBB { get; set; }
        [Parameter("Bands StdDev (1.386)", DefaultValue = 1.318)]
        public double inpBBStdDev { get; set; }
        [Parameter("Bands Smooth Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType { get; set; }

        [Output("Internal Strength", LineColor = "Black", LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outInternalStrength { get; set; }
        [Output("BB up", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBup { get; set; }
        [Output("BB Down", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBdn { get; set; }
        [Output("BB mid", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBmid { get; set; }
        
        private IndicatorDataSeries _is, _raw;
        private RelativeStrengthIndex _rsi;
        private BollingerBands _bb;
        

        protected override void Initialize()
        {
            _raw = CreateDataSeries();
            _is = CreateDataSeries();
            _rsi = Indicators.RelativeStrengthIndex(_raw, inpPeriod);
            _bb = Indicators.BollingerBands(_raw, inpPeriodBB, inpBBStdDev, inpSmoothType);
        }

        public override void Calculate(int i)
        {
            _raw[i] = (Bars.HighPrices[i] != Bars.LowPrices[i] ? (Bars.ClosePrices[i]- Bars.LowPrices[i]) / (Bars.HighPrices[i] - Bars.LowPrices[i]) : 0);
            
            if(inpDrawMode == enumDrawMode.DrawRAW)
                _is[i] = _raw[i];
            else
                _is[i] = _rsi.Result[i];

            outInternalStrength[i] = _is[i];
            outBBup[i] = inpDrawMode == enumDrawMode.DrawRAW ? _bb.Top[i] : double.NaN;
            outBBdn[i] = inpDrawMode == enumDrawMode.DrawRAW ? _bb.Bottom[i] : double.NaN;
            outBBmid[i] = inpDrawMode == enumDrawMode.DrawRAW ? _bb.Main[i] : double.NaN;
        }
    }
    
    public enum enumDrawMode
    {
        DrawRAW,
        DrawRSI
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mInternalStrength.algo
  • Rating: 5
  • Installs: 224
  • Modified: 21/11/2023 13:53
Comments
Log in to add a comment.
No comments found.