Rainbow2 free

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

This indicator calculates the high and low of the Rainbow indicator and its averages.

Well know too.

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
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Rainbow2 : Indicator
    {
        [Parameter(DefaultValue = 15)]
        public int Periods { get; set; }

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

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

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

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

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

        private SimpleMovingAverage sma1;
        private SimpleMovingAverage sma2;
        private SimpleMovingAverage sma3;
        private SimpleMovingAverage sma4;
        private SimpleMovingAverage sma5;
        private SimpleMovingAverage sma6;
        private SimpleMovingAverage sma7;
        private SimpleMovingAverage sma8;
        private SimpleMovingAverage sma9;
        private SimpleMovingAverage sma10;

        private double[] array;

        private double max, min;
        private double CenterMean, UpperMean, LowerMean;

        protected override void Initialize()
        {
            sma1 = Indicators.SimpleMovingAverage(Bars.ClosePrices, Periods);
            sma2 = Indicators.SimpleMovingAverage(sma1.Result, Periods);
            sma3 = Indicators.SimpleMovingAverage(sma2.Result, Periods);
            sma4 = Indicators.SimpleMovingAverage(sma3.Result, Periods);
            sma5 = Indicators.SimpleMovingAverage(sma4.Result, Periods);
            sma6 = Indicators.SimpleMovingAverage(sma5.Result, Periods);
            sma7 = Indicators.SimpleMovingAverage(sma6.Result, Periods);
            sma8 = Indicators.SimpleMovingAverage(sma7.Result, Periods);
            sma9 = Indicators.SimpleMovingAverage(sma8.Result, Periods);
            sma10 = Indicators.SimpleMovingAverage(sma9.Result, Periods);

            array = new double[10];
        }

        public override void Calculate(int index)
        {
            array[0] = sma1.Result[index];
            array[1] = sma2.Result[index];
            array[2] = sma3.Result[index];
            array[3] = sma4.Result[index];
            array[4] = sma5.Result[index];
            array[5] = sma6.Result[index];
            array[6] = sma7.Result[index];
            array[7] = sma8.Result[index];
            array[8] = sma9.Result[index];
            array[9] = sma10.Result[index];

            max = 0;
            min = 100;
            for (int i = 0; i <= 9; i++)
            {
                if (array[i] < min)
                    min = array[i];

                if (array[i] > max)
                    max = array[i];
            }

            CenterMean = (max + min) / 2;
            UpperMean = (max + CenterMean) / 2;
            LowerMean = (CenterMean + min) / 2;

            Result1[index] = max;
            Result2[index] = min;
            Result3[index] = UpperMean;
            Result4[index] = CenterMean;
            Result5[index] = LowerMean;
        }
    }
}
Comments
0