Referenced Indicators: Lazy loading

Created at 25 Nov 2016, 18:12
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!
Jiri's avatar

Jiri

Joined 31.08.2015

Referenced Indicators: Lazy loading
25 Nov 2016, 18:12


Hi Spotware,

When you try to access other types of properties than IndicatorDataSeries the object is not accessible due to lazy loading unless you try to access together with an IndicatorDataSeries. Please see sample below.

 

The referenced indicator:

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ReferencedIndicator : Indicator
    {
        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        public double ClosePrice;

        public override void Calculate(int index)
        {
            ClosePrice = MarketSeries.Close[index];
        }
    }
}

 

Trying to access ClosePrice:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LazyLoading : Indicator
    {
        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private ReferencedIndicator referencedIndi;

        protected override void Initialize()
        {
            referencedIndi = Indicators.GetIndicator<ReferencedIndicator>();
        }

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

 

Accessing ClosePrice by forcing the load:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LazyLoading : Indicator
    {
        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private ReferencedIndicator referencedIndi;

        protected override void Initialize()
        {
            referencedIndi = Indicators.GetIndicator<ReferencedIndicator>();
        }

        public override void Calculate(int index)
        {
            double a = referencedIndi.Result.LastValue; // forces the load of other objects as well
            Result[index] = referencedIndi.ClosePrice;
        }
    }
}


@Jiri
Replies

Jiri
29 Nov 2016, 19:49

Please, could you confirm you are aware of it and it's going to be fixed in the future?


@Jiri

Jiri
16 Dec 2016, 16:50

Spotware, could you respond to this topic?


@Jiri

firemyst
07 May 2019, 09:05

RE:

Jiri said:

Hi Spotware,

When you try to access other types of properties than IndicatorDataSeries the object is not accessible due to lazy loading unless you try to access together with an IndicatorDataSeries. Please see sample below.

I experienced similar issues.

Apparently this is intended behavior.

See this thread:

https://ctrader.com/forum/ctrader-support/16386

 


@firemyst