Delays in displaying vaules on the chart

Created at 20 Feb 2016, 18:48
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!
MI

mikepecson72

Joined 15.01.2016

Delays in displaying vaules on the chart
20 Feb 2016, 18:48


I have an indicator that display values on the chart via  ChartObjects.DrawText and so far it is working except that it takes 30 seconds or so to display on the chart. Its ok if only one chart but if change timeframes and switch to other pairs, the delays becomes annoying.

What can I do to minimize the delays if not make it realtime as much as possible?

below are the screenshot and code for your further investigations.

thanks in advance.

 

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

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

        private CommodityChannelIndex _cci_daily;
        private CommodityChannelIndex _cci_4h;
        private CommodityChannelIndex _cci_1h;
        private CommodityChannelIndex _cci_30m;
        private CommodityChannelIndex _cci_15m;
        private CommodityChannelIndex _cci_5m;


        protected override void Initialize()
        {
            _cci_daily = Indicators.CommodityChannelIndex(MarketData.GetSeries(TimeFrame.Daily), 14);
            _cci_4h = Indicators.CommodityChannelIndex(MarketData.GetSeries(TimeFrame.Hour4), 14);
            _cci_1h = Indicators.CommodityChannelIndex(MarketData.GetSeries(TimeFrame.Hour), 14);
            _cci_30m = Indicators.CommodityChannelIndex(MarketData.GetSeries(TimeFrame.Minute30), 14);
            _cci_15m = Indicators.CommodityChannelIndex(MarketData.GetSeries(TimeFrame.Minute15), 14);
            _cci_5m = Indicators.CommodityChannelIndex(MarketData.GetSeries(TimeFrame.Minute5), 14);
        }

        public override void Calculate(int index)
        {

            ChartObjects.DrawText("1", xySpace(0, 1) + _cci_daily.Result.LastValue, StaticPosition.TopLeft);
            ChartObjects.DrawText("2", xySpace(0, 2) + _cci_4h.Result.LastValue, StaticPosition.TopLeft);
            ChartObjects.DrawText("3", xySpace(0, 3) + _cci_1h.Result.LastValue, StaticPosition.TopLeft);
            ChartObjects.DrawText("4", xySpace(0, 4) + _cci_30m.Result.LastValue, StaticPosition.TopLeft);
            ChartObjects.DrawText("5", xySpace(0, 5) + _cci_15m.Result.LastValue, StaticPosition.TopLeft);
            ChartObjects.DrawText("6", xySpace(0, 6) + _cci_5m.Result.LastValue, StaticPosition.TopLeft);



        }
        private string xySpace(int x, int y)
        {
            if (x < 0 || y < 0)
                return ("");
            string str = "";
            for (int i = 0; i < y; i++)
                str += "\n";
            for (int i = 0; i < x; i++)
                str += "\t";
            return (str);
        }
    }
}

 


@mikepecson72
Replies

Spotware
24 Feb 2016, 15:25

Dear Trader,

We kindly ask you to optimize your code and try to use as less loops as possible on the Calculate method.

The Calculate method is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick. In the case of multi-symbol / multi-timeframe implementation, it will be called on each tick of each symbol that is used in the indicator. 


@Spotware