Initialize seems to be called twice on startup

Created at 01 Dec 2013, 21:26
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!
BP

bp2012

Joined 31.08.2013

Initialize seems to be called twice on startup
01 Dec 2013, 21:26


The following code shows that the initialize method seems to be called twice. I verified this in both cAlgo and cTrader. The only impact seems to be performance. If I have an indicator that does some heavy prep work in the initialize method, I'm paying double performance.

Code demonstrating the issue:

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using System.Runtime.InteropServices;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

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

        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            log("init Complete");
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }

        public void log(string txt)
        {
            Print(txt);
            MessageBox(new IntPtr(0), txt, "debug", 0);
        }
    }
}

 


@bp2012
Replies

Spotware
02 Dec 2013, 16:18

Initialize is called when the Timeframe / Symbol of a chart is changed and when new historical data is received.
When you open the chart we show cached data first and calculate indicators. Then we download actual data and calculate indicator one more time.


@Spotware