Referenced Indicators: Lazy loading
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; } } }
Replies
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
whis.gg
29 Nov 2016, 19:49
Please, could you confirm you are aware of it and it's going to be fixed in the future?
@whis.gg