Question. Accecs a reference indicator's variable

Created at 13 Jun 2015, 14:31
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!
OI

oilsok

Joined 12.06.2015

Question. Accecs a reference indicator's variable
13 Jun 2015, 14:31


Hello.

I leaned how to use reference indicator lastnight. but now I need to access Indicators variable.

it is a referenced Indicator a little modified my self

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
    public class PivotPoints : Indicator
    {
        private DateTime _previousPeriodStartTime;
        private int _previousPeriodStartIndex;
        private TimeFrame PivotTimeFrame;
        private VerticalAlignment vAlignment = VerticalAlignment.Top;
        private HorizontalAlignment hAlignment = HorizontalAlignment.Right;

        Colors pivotColor = Colors.White;
        Colors supportColor = Colors.Red;
        Colors resistanceColor = Colors.Green;

        [Parameter("Show Labels", DefaultValue = true)]
        public bool ShowLabels { get; set; }

        [Parameter("Pivot Color", DefaultValue = "White")]
        public string PivotColor { get; set; }
        [Parameter("Support Color", DefaultValue = "Red")]
        public string SupportColor { get; set; }
        [Parameter("Resistance Color", DefaultValue = "Green")]
        public string ResistanceColor { get; set; }

        public double Result_r3;

        public double Result_r2;

        public double Result_r1;

        public double Result_pivot;

        public double Result_s1;

        public double Result_s2;

        public double Result_s3;
....

and then cbot code writen

 public string ResistanceColor { get; set; }

        private PivotPoints pivotline;
        protected override void OnStart()
        {


        }

        protected override void OnTick()
        {
            pivotline = Indicators.GetIndicator<PivotPoints>(ShowLabels, PivotColor, SupportColor, ResistanceColor);
            // Put your core logic here
        }
        protected override void OnBar()
        {

            double r3 = pivotline.Result_r3;
            double r2 = pivotline.Result_r2;
            double r1 = pivotline.Result_r1;
            double pivot = pivotline.Result_pivot;
            double s1 = pivotline.Result_s1;
            double s2 = pivotline.Result_s2;
            double s3 = pivotline.Result_s3;

but when I backtest to see the value S1 and others using Print

they are all 0..

but when I test indicator internal value is not zero,,

hmmm


@oilsok
Replies

Spotware
15 Jun 2015, 14:35

Dear Trader,

Please note that we calculate Indicators on demand. If you do not access IndicatorDataSeries from the cBot the Calculate() method will not be invoked. Please use DataSeries instead of double fields.


@Spotware

deansi
21 Mar 2017, 12:54

RE:

Spotware said:

Dear Trader,

Please note that we calculate Indicators on demand. If you do not access IndicatorDataSeries from the cBot the Calculate() method will not be invoked. Please use DataSeries instead of double fields.

So just to clarify the meaning of "access IndicatorDataSeries", if I had the code with a custom indicator in a cBot as below example:

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        
        private TEMA tema;  // custom indicator

        protected override void OnStart()
        {
            var prevBars = MarketData.GetSeries(TimeFrame);
            tema = Indicators.GetIndicator<TEMA>(prevBars.Close, maPeriods); // THIS IS EXAMPLE A.
        }

        protected override void OnBar()
        {   
             double resultMA = tema.Result.Last(1) // THIS IS EXAMPLE B.
        }
    }

The line in the code where I have the comment "EXAMPLE A", is that enough to meet the requirement of accessing the IndicatorDataSeries on each bar, or does it require the line at "EXAMPLE B" in OnBar also?  (as OnTick would I assume also)


@deansi