Overlaying one indicator on top of another

Created at 04 Feb 2016, 20:47
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DM

Dm2025

Joined 03.02.2016

Overlaying one indicator on top of another
04 Feb 2016, 20:47


I like to use RSI 14, RSI 5, and CCI 5. It would be nice to overlay all of them. This saves on screen space. I'm guessing the only way to do it is through calgo.

Here is the code for one RSI indicator, how can we add other indicators in there?

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AutoRescale = true, TimeZone = TimeZones.UTC, ScalePrecision = 0)]
    public class SingleRSI : Indicator
    {
        private RelativeStrengthIndex rsi;

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

        [Parameter(DefaultValue = 50)]
        public int Periods { get; set; }

        [Output("Rsi", Color = Colors.Green)]
        public IndicatorDataSeries Rsi { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
        }

        public override void Calculate(int index)
        {
            Rsi[index] = rsi.Result[index];
        }

    }
}


@Dm2025
Replies

Dm2025
06 Feb 2016, 01:34

Good news. I have figured it out.

/api/guides/indicators near the bottom of the page I found something on combining two indicators. The following is how you can have multiple indicators in one indicator window.

using cAlgo.API;
using cAlgo.API.Indicators;
 
namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 5)]
    public class Aroon_RSI_DMS : Indicator
    {
        private Aroon aroon ;
        private RelativeStrengthIndex rsi;
        private DirectionalMovementSystem dms;
 
        [Parameter]
        public DataSeries Source { get; set; }
 
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }
         
 
        [Output("Aroon Up", Color = Colors.LightSkyBlue)]
        public IndicatorDataSeries AroonUp { get; set; }
 
        [Output("Aroon Down", Color = Colors.Red)]
        public IndicatorDataSeries AroonDn { get; set; }
 
        [Output("Rsi", Color = Colors.Green)]
        public IndicatorDataSeries Rsi { get; set; }
 
        [Output("DI Plus", Color = Colors.DarkGreen)]
        public IndicatorDataSeries DmsDIPlus { get; set; }
 
        [Output("DI Minus", Color = Colors.DarkRed)]
        public IndicatorDataSeries DmsDIMinus { get; set; }
 
        [Output("ADX", Color = Colors.Blue)]
        public IndicatorDataSeries DmsADX { get; set; }
 
 
        protected override void Initialize()
        {
            // Initialize and create nested indicators
            aroon = Indicators.Aroon(Periods);
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            dms = Indicators.DirectionalMovementSystem(Periods);
        }
 
 
        public override void Calculate(int index)
        {
            AroonUp[index] = aroon.Up[index];
            AroonDn[index] = aroon.Down[index];
 
            Rsi[index] = rsi.Result[index];
 
            DmsADX[index] = dms.ADX[index];
            DmsDIMinus[index] = dms.DIMinus[index];
            DmsDIPlus[index] = dms.DIPlus[index];
             
        }
 
    }
}

So for the RSI I used this code:

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AutoRescale = true, TimeZone = TimeZones.UTC, ScalePrecision = 0)]
    public class DoubleRsi : Indicator
    {
        private RelativeStrengthIndex rsi;
        private RelativeStrengthIndex rsi2;

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

        [Output("Rsi", Color = Colors.Green)]
        public IndicatorDataSeries Rsi { get; set; }

        [Output("Rsi2", Color = Colors.Red)]
        public IndicatorDataSeries Rsi2 { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            rsi = Indicators.RelativeStrengthIndex(Source, 14);
            rsi2 = Indicators.RelativeStrengthIndex(Source, 5);
        }

        public override void Calculate(int index)
        {
            Rsi[index] = rsi.Result[index];
            Rsi2[index] = rsi2.Result[index];
        }

    }
}

And now we have mt4 functionality.


@Dm2025