Dynamic RSI free

by Danis in category Trend at 21/03/2021
Description

RSI MA with signals on chart.

For more details about Forex analysis pleas visit www.festkapital.de

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo.Indicators
{
    [Cloud("SMA", "RSI", FirstColor = "#FFFF3236", Opacity = 0.2, SecondColor = "#FF16BB47")]
    [Levels(30, 50, 70)]
    [Indicator(IsOverlay = false, AutoRescale = true, ScalePrecision = 3, AccessRights = AccessRights.None)]

    public class RSI_xMA_onChart : Indicator
    {
        [Parameter("XMA Period", DefaultValue = 12)]
        public int Length { get; set; }
        [Parameter("RSI period", DefaultValue = 14)]
        public int rsiPeriod { get; set; }
        [Parameter("SMA period", DefaultValue = 20)]
        public int rmaPeriod { get; set; }
        [Parameter("CCI Period", DefaultValue = 20)]
        public int cciPeriod { get; set; }
        [Parameter("WWS Period", DefaultValue = 5)]
        public int wwsPeriod { get; set; }

        [Output("RSI", LineColor = "#FF005727")]
        public IndicatorDataSeries RSI { get; set; }
        [Output("SMA", LineColor = "#FF542478")]
        public IndicatorDataSeries RMA { get; set; }

        [Output("Level 65", LineColor = "#3CFF5050", LineStyle = LineStyle.Solid, Thickness = 5)]
        public IndicatorDataSeries level65 { get; set; }
        [Output("Level 35", LineColor = "#36009900", LineStyle = LineStyle.Solid, Thickness = 5)]
        public IndicatorDataSeries level35 { get; set; }

        public IndicatorDataSeries downTrend, upTrend, _xOpen, _xClose, _xHigh, _xLow;

        private IndicatorDataSeries new_array;
        private IndicatorDataSeries buf_1, buf_2;

        private RelativeStrengthIndex rsi;
        private SimpleMovingAverage rma;
        private WellesWilderSmoothing wws;
        private CommodityChannelIndex cci;

        private Color Cr, Cdr, Cg, Cdg, Co, rsitC, HkmaC, signC;

        protected Bars bars1D;

        private string signT = string.Empty;
        private string rsiT = string.Empty;
        private string HkmaT = string.Empty;

        int i = 0;
        int int_1 = 0;
        int new_size = 0;
        int int_2 = 4;
        double double_1 = 0;
        double double_2 = 0;
        double double_3 = 0;
        double double_4 = 0;
        double double_5 = 0;
        double double_6 = 0;
        double pi = 3.1415926535;

        protected override void Initialize()
        {
            var index = Bars.ClosePrices.Count - 1;

            Cg = Chart.ColorSettings.BuyColor;
            Cr = Chart.ColorSettings.SellColor;
            Co = Color.Orange;
            Cdr = Color.DarkRed;
            Cdg = Color.DarkGreen;

            new_array = CreateDataSeries();
            buf_1 = CreateDataSeries();
            buf_2 = CreateDataSeries();
            downTrend = CreateDataSeries();
            upTrend = CreateDataSeries();

            _xOpen = CreateDataSeries();
            _xClose = CreateDataSeries();
            _xHigh = CreateDataSeries();
            _xLow = CreateDataSeries();

            rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, rsiPeriod);
            rma = Indicators.SimpleMovingAverage(rsi.Result, rmaPeriod);
            cci = Indicators.CommodityChannelIndex(cciPeriod);
            wws = Indicators.WellesWilderSmoothing(cci.Result, wwsPeriod);

            double_1 = 3.0 * pi;
            int_1 = Length - 1;
            new_size = Length * int_2 + int_1;
            double_5 = 0;

            for (i = 0; i < new_size; i++)
            {
                if (i <= int_1 - 1)
                    double_3 = 1.0 * i / (int_1 - 1);
                else
                    double_3 = (i - int_1 + 1) * (2.0 * int_2 - 1.0) / (int_2 * Length - 1.0) + 1.0;

                double_2 = Math.Cos(pi * double_3);
                double_6 = 1.0 / (double_1 * double_3 + 1.0);
                if (double_3 <= 0.5)
                    double_6 = 1;
                new_array[i] = double_6 * double_2;
                double_5 += new_array[i];
            }
        }

        public override void Calculate(int index)
        {
//----- extreme MA
            int limit = 0;
            double double_7 = 0;
            int counted_bars = index;

            if (counted_bars > 0)
                limit = Barrs - counted_bars;

            if (counted_bars < 0)
                return;

            if (counted_bars == 0)
                limit = Barrs - new_size - 1;

            if (counted_bars < 1)
            {
                for (int id = 0; id < Length * int_2 + Length; id++)
                {
                    downTrend[id] = 0;
                    upTrend[id] = 0;
                    buf_1[id] = 0;
                }
            }

            double_4 = 0;

            for (int a = 0; a < new_size; a++)
            {
                double_7 = Bars.ClosePrices.Last(a);
                double_4 += new_array[a] * double_7;
            }

            if (double_5 > 0.0)
                buf_1[index] = double_4 / double_5;

            if (Math.Abs(buf_1[index] - (buf_1[index - 1])) < 1.618 * Symbol.TickSize)
                buf_1[index] = buf_1[index - 1];

            buf_2[index] = buf_2[index - 1];

            if (buf_1[index] - (buf_1[index - 1]) > 1.618 * Symbol.TickSize)
                buf_2[index] = 1;

            if (buf_1[index - 1] - buf_1[index] > 1.618 * Symbol.TickSize)
                buf_2[index] = -1;

            if (buf_2[index] > 0.0)
            {
                upTrend[index] = buf_1[index];

                if (buf_2[index - 1] < 0.0)
                    upTrend[index - 1] = buf_1[index - 1];

                downTrend[index] = double.NaN;
            }
            if (buf_2[index] < 0.0)
            {
                downTrend[index] = buf_1[index];

                if (buf_2[index - 1] > 0.0)
                    downTrend[index - 1] = buf_1[index - 1];

                upTrend[index] = double.NaN;
            }

//----- HeikinAshi
            if (index <= 7)
            {
                _xOpen[index] = Math.Round((Bars.OpenPrices[index] + Bars.ClosePrices[index]) / 2, Symbol.Digits);
                _xClose[index] = Math.Round((Bars.OpenPrices[index] + Bars.LowPrices[index] + Bars.HighPrices[index] + Bars.ClosePrices[index]) / 4, Symbol.Digits);
                _xHigh[index] = Bars.HighPrices[index];
                _xLow[index] = Bars.LowPrices[index];
                return;
            }
            _xOpen[index] = Math.Round((_xOpen[index - 1] + _xClose[index - 1]) / 2, Symbol.Digits);
            _xClose[index] = Math.Round((Bars.OpenPrices[index] + Bars.LowPrices[index] + Bars.HighPrices[index] + Bars.ClosePrices[index]) / 4, Symbol.Digits);
            _xHigh[index] = Math.Max(Bars.HighPrices[index], Math.Max(_xOpen[index], _xClose[index]));
            _xLow[index] = Math.Min(Bars.LowPrices[index], Math.Min(_xOpen[index], _xClose[index]));

            level65[index] = 65;
            level35[index] = 35;

            RSI[index] = rsi.Result[index];
            RMA[index] = rma.Result[index];

//----- Direction Signal
            bool goBullish = (cci.Result.Last(0) > wws.Result.Last(0) || upTrend.IsRising() || (rsi.Result.Last(1) > 70 && rsi.Result.Last(0) > rma.Result.Last(0))) ? true : false;
            bool goBearish = (cci.Result.Last(0) < wws.Result.Last(0) || downTrend.IsFalling() || (rsi.Result.Last(1) < 30 && rsi.Result.Last(0) < rma.Result.Last(0))) ? true : false;

//------ RSI signal
            bool rsiBullish = (rsi.Result.Last(1) > 40 && rsi.Result.Last(0) > rma.Result.Last(0)) ? true : false;
            bool rsiBearish = (rsi.Result.Last(1) < 65 && rsi.Result.Last(0) < rma.Result.Last(0)) ? true : false;

//----- HkAshi XMA signal
            bool hkxmaBullish = (upTrend.IsRising() && upTrend.Last(1) < _xClose.Last(1) && _xOpen.Last(0) < _xClose.Last(1)) ? true : false;
            bool hkxmaBearish = (downTrend.IsFalling() && downTrend.Last(1) > _xClose.Last(1) && _xOpen.Last(0) > _xClose.Last(1)) ? true : false;

//------ Entry Signal signal
            bool isBullish = (goBullish && rsiBullish && cci.Result.Last(1) > 0 && cci.Result.Last(0) > wws.Result.Last(0)) ? true : false;
            bool isBearish = (goBearish && rsiBearish && cci.Result.Last(1) < 0 && cci.Result.Last(0) < wws.Result.Last(0)) ? true : false;

            signT = (isBullish) ? "Buy" : (isBearish) ? "Sell" : "Wait";
            signC = (signT == "Buy") ? Cg : (signT == "Sell") ? Cr : Co;

            rsiT = (rsiBullish) ? "Bullish" : (rsiBearish) ? "Bearish" : "Range";
            rsitC = (rsiT == "Bullish") ? Cg : (rsiT == "Bearish") ? Cr : Co;

            HkmaT = (hkxmaBullish) ? "Bullish" : (hkxmaBearish) ? "Bearish" : "Range";
            HkmaC = (HkmaT == "Bullish") ? Cg : (HkmaT == "Bearish") ? Cr : Co;

            Chart.DrawStaticText("sign", "Signal:" + "\t\t", VerticalAlignment.Top, HorizontalAlignment.Right, Chart.ColorSettings.ForegroundColor);
            Chart.DrawStaticText("signt", signT, VerticalAlignment.Top, HorizontalAlignment.Right, signC);

            Chart.DrawStaticText("rsi", "\nRSI:" + "\t\t", VerticalAlignment.Top, HorizontalAlignment.Right, Chart.ColorSettings.ForegroundColor);
            Chart.DrawStaticText("rsiT", "\n" + rsiT, VerticalAlignment.Top, HorizontalAlignment.Right, rsitC);

            Chart.DrawStaticText("HkAshi", "\n\nHk.xMA:" + "\t\t", VerticalAlignment.Top, HorizontalAlignment.Right, Chart.ColorSettings.ForegroundColor);
            Chart.DrawStaticText("HkAshi1", "\n\n" + HkmaT, VerticalAlignment.Top, HorizontalAlignment.Right, HkmaC);
        }

        private int Barrs
        {
            get { return Bars.ClosePrices.Count; }
        }
    }
}
Comments

khushal09 - April 08, 2021 @ 16:46

can you please remove commentry from chart

0