Initialize seems to be called twice on startup
Created at 01 Dec 2013, 21:26
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); } } }
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