Indicator with multiple outputs as overlay and as separate Window?

Created at 18 Nov 2017, 18:43
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!
Mikro's avatar

Mikro

Joined 20.06.2015

Indicator with multiple outputs as overlay and as separate Window?
18 Nov 2017, 18:43


Hi all,

is it possible to have an indicator draw outputs as overlay and also direct another output to a separate indicator window?

For example I want an Alligator to output the moving averages as overlay and a tradedirection Signal [1,0,-1] as seperate chart?

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class indTradeDirection : Indicator
    {
        [Parameter(DefaultValue = 13)]
        public int JawsPeriods { get; set; }

        [Parameter(DefaultValue = 8)]
        public int JawsShift { get; set; }

        [Parameter(DefaultValue = 8)]
        public int TeethPeriods { get; set; }

        [Parameter(DefaultValue = 5)]
        public int TeethShift { get; set; }

        [Parameter(DefaultValue = 5)]
        public int LipsPeriods { get; set; }

        [Parameter(DefaultValue = 3)]
        public int LipsShift { get; set; }

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

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

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

        [Output("TradeDirection", Thickness = 3, PlotType = PlotType.Line, Color = Colors.WhiteSmoke)]
        public IndicatorDataSeries TradeDirection { get; set; }

        private WellesWilderSmoothing jawsMa;
        private WellesWilderSmoothing teethMa;
        private WellesWilderSmoothing lipsMa;

        protected override void Initialize()
        {

            jawsMa = Indicators.WellesWilderSmoothing(MarketSeries.Median, JawsPeriods);
            teethMa = Indicators.WellesWilderSmoothing(MarketSeries.Median, TeethPeriods);
            lipsMa = Indicators.WellesWilderSmoothing(MarketSeries.Median, LipsPeriods);
        }

        public override void Calculate(int index)
        {
            Jaws[index + JawsShift] = jawsMa.Result[index];
            Teeth[index + TeethShift] = teethMa.Result[index];
            Lips[index + LipsShift] = lipsMa.Result[index];
            calcTradeDirection(index);
        }

        private void calcTradeDirection(int index)
        {
            double lastLips = lipsMa.Result.LastValue;
            double lastTeeth = teethMa.Result.LastValue;
            double lastJaws = jawsMa.Result.LastValue;

            if (lastLips > lastTeeth && lastTeeth < lastJaws)
            {
                TradeDirection[index] = 1;
                return;
            }
            if (lastLips < lastTeeth && lastTeeth < lastJaws)
            {
                TradeDirection[index] = -1;
                return;
            }
            TradeDirection[index] = 0;
        }

        public TradeType? GetTradeDirection()
        {
            if (TradeDirection.LastValue==1)
            {
                return TradeType.Buy;
            }
            if (TradeDirection.LastValue == -1)
            {
                return TradeType.Sell;
            }
            return null;
        }
    }
}

Cheers

Mikro


@Mikro
Replies

Mikro
23 Nov 2017, 21:44

Hi Support,

could you clarify if this is possible?

THX


@Mikro

PanagiotisCharalampous
24 Nov 2017, 09:41

Hi Mikro,

This is not possible currently. But why don't you split your indicator to two (one with moving averages and one with trade direction) and use them both on the same chart? 

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

Mikro
25 Nov 2017, 14:24 ( Updated at: 21 Dec 2023, 09:20 )

Hi Panagiotis,

I am trying to build an integrated Indicator with an output for generated trade signals.

As a simple example if all lines of an Alligator are stacked by speed in long direction the output is "1", if stacked short "-1" and else "0".

So I open a nested Alligator in the new indicator an calculate the output.

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class indTradeDirection : Indicator
    {
        [Parameter(DefaultValue = 13)]
        public int JawsPeriods { get; set; }

        [Parameter(DefaultValue = 8)]
        public int JawsShift { get; set; }

        [Parameter(DefaultValue = 8)]
        public int TeethPeriods { get; set; }

        [Parameter(DefaultValue = 5)]
        public int TeethShift { get; set; }

        [Parameter(DefaultValue = 5)]
        public int LipsPeriods { get; set; }

        [Parameter(DefaultValue = 3)]
        public int LipsShift { get; set; }

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

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

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

        [Output("TradeDirection", Thickness = 3, PlotType = PlotType.Line, Color = Colors.WhiteSmoke)]
        public IndicatorDataSeries TradeDirection { get; set; }

        private SimpleMovingAverage jawsMa;
        private SimpleMovingAverage teethMa;
        private ExponentialMovingAverage lipsMa;

        protected override void Initialize()
        {
            jawsMa = Indicators.SimpleMovingAverage(MarketSeries.Close, JawsPeriods);
            teethMa = Indicators.SimpleMovingAverage(MarketSeries.Close, TeethPeriods);
            lipsMa = Indicators.ExponentialMovingAverage(MarketSeries.Close, LipsPeriods);
        }

        public override void Calculate(int index)
        {
            Jaws[index + JawsShift] = jawsMa.Result[index];
            Teeth[index + TeethShift] = teethMa.Result[index];
            Lips[index + LipsShift] = lipsMa.Result[index];
            calcTradeDirection(index);
        }

        private void calcTradeDirection(int index)
        {
            double lastLips = Lips[index];
            double lastTeeth = Teeth[index];
            double lastJaws = Jaws[index];

            if (lastLips > lastTeeth && lastTeeth > lastJaws)
            {
                TradeDirection[index] = 1;
                return;
            }
            if (lastLips < lastTeeth && lastTeeth < lastJaws)
            {
                TradeDirection[index] = -1;
                return;
            }
            TradeDirection[index] = 0;
        }

        public TradeType? GetTradeDirection()
        {
            if (TradeDirection.LastValue == 1)
            {
                return TradeType.Buy;
            }
            if (TradeDirection.LastValue == -1)
            {
                return TradeType.Sell;
            }
            return null;
        }
    }
}

If I use

IsOverlay = true

it looks like this

IsOverlay = false

looks like this

what I would like to have is

But if I open an aditional Indicators for the overlay and separate Chart the Parameters of the Indicators are not synchronised because the reside in different indicators.

Any Idea how to solve this?

THX


@Mikro

PanagiotisCharalampous
27 Nov 2017, 11:30

Hi Mikro,

Have a look at nested indicators. I believe that they can help you solve your issue. Let me know if this helpful.

Best Regards,

Panagiotis


@PanagiotisCharalampous

Mikro
03 Dec 2017, 23:26

RE:

Hi Panagiotis,

From I read about nested indicators using the Moving Average Indicators in my code is pretty much using nested indicators, isn't it?

 protected override void Initialize()
        {
            jawsMa = Indicators.SimpleMovingAverage(MarketSeries.Close, JawsPeriods);
            teethMa = Indicators.SimpleMovingAverage(MarketSeries.Close, TeethPeriods);
            lipsMa = Indicators.ExponentialMovingAverage(MarketSeries.Close, LipsPeriods);
        }

This way the indicator parameters can be handled by the algo but I have no option to draw the used indicators to different chart types, do I?

THX

Mirko

Panagiotis Charalampous said:

Hi Mikro,

Have a look at nested indicators. I believe that they can help you solve your issue. Let me know if this helpful.

Best Regards,

Panagiotis

 


@Mikro

ap11
04 Dec 2017, 10:12

RE: RE:

Hi Mirko,

That is correct. You need to have 2 indicators for this, Alligator and Signals indicator. Signals indicator will use Alligator as a nested indicator. Alligator should be added manually to the chart with same settings.

You can use Sample Alligator for this:
 

SampleAlligator alligator;

protected override void Initialize()
{
    alligator = Indicators.GetIndicator<SampleAlligator>(JawsPeriods, JawsShift, TeethPeriods, TeethShift, LipsPeriods, LipsShift);
}

public override void Calculate(int index)
{

    var jaws = alligator.Jaws[index];
    var teeth = alligator.Teeth[index];
    var lips = alligator.Lips[index];
    ...
}

 

Best Regatds,
Andrey

 

Mikro said:

Hi Panagiotis,

From I read about nested indicators using the Moving Average Indicators in my code is pretty much using nested indicators, isn't it?

 protected override void Initialize()
        {
            jawsMa = Indicators.SimpleMovingAverage(MarketSeries.Close, JawsPeriods);
            teethMa = Indicators.SimpleMovingAverage(MarketSeries.Close, TeethPeriods);
            lipsMa = Indicators.ExponentialMovingAverage(MarketSeries.Close, LipsPeriods);
        }

This way the indicator parameters can be handled by the algo but I have no option to draw the used indicators to different chart types, do I?

THX

Mirko

 


@ap11