accessing a value in custom indicator1 from custom indicator2

Created at 07 Sep 2020, 23:25
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!
xabbu's avatar

xabbu

Joined 20.07.2020

accessing a value in custom indicator1 from custom indicator2
07 Sep 2020, 23:25


Hi all, maybe someone can give a little help here:

 

I'm trying to access a value in indicator#1 from indicator#2 via reference:

 

indicator #1:

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Indi1 : Indicator
    {

        [Output("Main")]
        public int _intResult { get; set; }


        protected override void Initialize()
        {
            _intResult = 777;
        }

        public override void Calculate(int index)
        {
            _intResult += 1;
            Print(_intResult);
            string Text = "Trade allowed : " + _intResult;
            IndicatorArea.DrawStaticText("Symbols", Text, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Silver);
        }
    }
}

​

and here the code from the "receiving" indicator #2

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Indi2 : Indicator
    {


        [Output("Main")]
        public int Result { get; set; }

        private Indi1 _newIndicator;


        protected override void Initialize()
        {
            _newIndicator = Indicators.GetIndicator<Indi1>();
        }

        public override void Calculate(int index)
        {
            Print(_newIndicator);
            string Text = "Trade allowed : " + _newIndicator._intResult;
            IndicatorArea.DrawStaticText("Symbols", Text, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Silver);
        }
    }
}

 

but it doesn't work, the received value is always 777 but not the actual value of this variable in indicator #1...

I'm greatful for any kind of help,

 

Kindest regards,


@xabbu
Replies

PanagiotisCharalampous
08 Sep 2020, 08:02

Hi xabbu,

The indicator's Calculate() method is only called when an IndicatorDataSeries accessed by external code. In your case this does not happen, hence the Calculate() method is never actually executed. You have two options a) use IndicatorDataSeries instead of a normal variable b) call Calculate() method manually.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

xabbu
08 Sep 2020, 09:21

Great support, Panagiotis, thanks!

Do I have to alter the indicator #1 or #2 (and how can I call the calculate() by hand...?

Best,


@xabbu

PanagiotisCharalampous
08 Sep 2020, 09:28

Hi xabbu,

1) You have to change indicator #1

2) Just call _newIndicator.Calculate(index);

Best Regards,

Panagiotis 


@PanagiotisCharalampous

xabbu
08 Sep 2020, 09:54

I tried and inserted this line of new code in every possible (and impossible ;-) place in the code of indicator #1 (and #2 to also) - but I can't mange your tip to work. Can you give another little hint to get it done correctly? Danke


@xabbu

PanagiotisCharalampous
08 Sep 2020, 09:55

Hi xabbu,

Just use an IndicatorDataSeries to store your values.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

xabbu
08 Sep 2020, 10:11

okay, I will try it with this advice, do I have to do it on indicator #1 or #2...?

and is it the right way when I only wan't to get a boolean expression from the sending to the receiving indicator / cBot?

Thanks Panagiotis


@xabbu

PanagiotisCharalampous
08 Sep 2020, 10:14

Hi xabbu,

On indicator 1.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

xabbu
08 Sep 2020, 10:16

thanks, okay, and is it the right way when I only wan't to get a boolean expression from the sending to the receiving indicator / cBot - quasi as a signal?

 


@xabbu

PanagiotisCharalampous
08 Sep 2020, 10:17

Hi xabbu,

Yes I would recommend this approach.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous