public void InitializeChartNoStrategy(MainForm mainForm, ContextChart contextChart) { string msig = "ChartFormsManager.InitializeChartNoStrategy(" + contextChart + "): "; this.MainForm = mainForm; if (this.DataSnapshot.ChartSerno == -1) { int charSernoNext = mainForm.GuiDataSnapshot.ChartSernoNextAvailable; bool createdNewFile = this.DataSnapshotSerializer.Initialize(Assembler.InstanceInitialized.AppDataPath, "ChartFormDataSnapshot-" + charSernoNext + ".json", "Workspaces", Assembler.InstanceInitialized.AssemblerDataSnapshot.CurrentWorkspaceName, true, true); this.DataSnapshot = this.DataSnapshotSerializer.Deserialize(); // will CREATE a new ChartFormDataSnapshot and keep the reference for further Serialize(); we should fill THIS object this.DataSnapshot.ChartSerno = charSernoNext; this.DataSnapshotSerializer.Serialize(); } this.ChartForm = new ChartForm(this); this.DataSnapshot.StrategyGuidJsonCheck = "NO_STRATEGY_CHART_ONLY"; if (this.DataSnapshot.ChartSettings == null) { // delete "ChartSettings": {} from JSON to reset to ChartControl>Design>ChartSettings>Properties this.DataSnapshot.ChartSettings = this.ChartForm.ChartControl.ChartSettings; // opening from Datasource => save } else { this.ChartForm.ChartControl.ChartSettings = this.DataSnapshot.ChartSettings; // otherwize JustDeserialized => propagate this.ChartForm.ChartControl.PropagateSettingSplitterDistancePriceVsVolume(); } if (contextChart != null) { // contextChart != null when opening from Datasource; contextChart == null when JustDeserialized this.DataSnapshot.ContextChart = contextChart; } this.DataSnapshotSerializer.Serialize(); this.ChartForm.FormClosed += this.MainForm.MainFormEventManager.ChartForm_FormClosed; //this.ChartForm.CtxReporters.Enabled = false; this.ChartForm.DdbReporters.Enabled = false; this.ChartForm.DdbBacktest.Enabled = false; this.ChartForm.DdbStrategy.Enabled = false; this.ChartForm.MniShowSourceCodeEditor.Enabled = false; this.EventManager = new ChartFormEventManager(this); this.ChartForm.AttachEventsToChartFormsManager(); try { this.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy(msig); } catch (Exception ex) { string msg = "PopulateCurrentChartOrScriptContext(): "; Assembler.PopupException(msg + msig, ex); } }
public void InitializeStrategyAfterDeserialization(MainForm mainForm, string strategyGuid) { Strategy strategyFound = null; if (String.IsNullOrEmpty(strategyGuid) == false) { strategyFound = Assembler.InstanceInitialized.RepositoryDllJsonStrategy.LookupByGuid(strategyGuid); // can return NULL here } this.InitializeWithStrategy(mainForm, strategyFound); this.FOR_DEBUGGING_initializedWithStrategyAfterDeserialization = true; if (strategyFound == null) { string msg = "STRATEGY_NOT_FOUND: RepositoryDllJsonStrategy.LookupByGuid(strategyGuid=" + strategyGuid + ")"; Assembler.PopupException(msg); return; } // ALREADY_DONE_BY_InitializeWithStrategy()_ABOVE this.Strategy = strategyFound; if (this.Strategy.ScriptContextCurrent.BacktestOnRestart == false) return; this.Strategy.CompileInstantiate(); //this.Strategy is initialized in this.Initialize(); mess comes from StrategiesTree_OnStrategyOpenSavedClicked() (TODO: reduce multiple paths) if (this.Strategy.Script == null) { string msig = " InitializeStrategyAfterDeserialization(" + this.Strategy.ToString() + ")"; string msg = "COMPILATION_FAILED_AFTER_DESERIALIZATION BACKTEST_ON_RESTART_TURNED_OFF"; Assembler.PopupException(msg + msig); this.Strategy.ScriptContextCurrent.BacktestOnRestart = false; Assembler.InstanceInitialized.RepositoryDllJsonStrategy.StrategySave(this.Strategy); #if DEBUG Debugger.Break(); #endif return; } if (this.Strategy.Script.Executor == null) { //IM_GETTING_HERE_ON_STARTUP_AFTER_SUCCESFULL_COMPILATION_CHART_RELATED_STRATEGIES Debugger.Break(); // you should never get here; a compiled script should've been already linked to Executor (without bars on deserialization) 10 lines above in this.InitializeWithStrategy(mainForm, strategy); this.Strategy.Script.Initialize(this.Executor); } // make sure so that reporters will get poked this.Executor.BacktesterRunSimulationTrampoline(new Action(this.afterBacktesterCompleteOnceOnRestart), true); //NOPE_ALREADY_POPULATED_UPSTACK this.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsBacktestIfStrategy("InitializeStrategyAfterDeserialization()"); }
public void InitializeChartNoStrategyAfterDeserialization(MainForm mainForm) { this.InitializeChartNoStrategy(mainForm, null); }
public void InitializeWithStrategy(MainForm mainForm, Strategy strategy) { string msig = "ChartFormsManager.InitializeWithStrategy(" + strategy + "): "; this.MainForm = mainForm; this.Strategy = strategy; //this.Executor = new ScriptExecutor(mainForm.Assembler, this.Strategy); if (this.DataSnapshot.ChartSerno == -1) { int charSernoNext = mainForm.GuiDataSnapshot.ChartSernoNextAvailable; bool createdNewFile = this.DataSnapshotSerializer.Initialize(Assembler.InstanceInitialized.AppDataPath, "ChartFormDataSnapshot-" + charSernoNext + ".json", "Workspaces", Assembler.InstanceInitialized.AssemblerDataSnapshot.CurrentWorkspaceName, true, true); this.DataSnapshot = this.DataSnapshotSerializer.Deserialize(); this.DataSnapshot.ChartSerno = charSernoNext; } this.DataSnapshot.StrategyGuidJsonCheck = strategy.Guid.ToString(); this.DataSnapshotSerializer.Serialize(); if (this.ChartForm == null) { // 1. create ChartForm.Chart.Renderer this.ChartForm = new ChartForm(this); this.ChartForm.FormClosed += this.MainForm.MainFormEventManager.ChartForm_FormClosed; // 2. create Executor with Renderer this.Executor.Initialize(this.ChartForm.ChartControl as ChartShadow, this.Strategy, Assembler.InstanceInitialized.OrderProcessor, Assembler.InstanceInitialized.StatusReporter); // 3. initialize Chart with Executor (I don't know why it should be so crazy) //this.ChartForm.Chart.Initialize(this.Executor); //ScriptExecutor.DataSource: you should not access DataSource before you've set Bars //this.ChartForm.ChartStreamingConsumer.Initialize(this); this.scriptEditorFormFactory = new ScriptEditorFormFactory(this, Assembler.InstanceInitialized.RepositoryDllJsonStrategy); this.ChartForm.CtxReporters.Items.AddRange(this.ReportersFormsManager.MenuItemsProvider.MenuItems.ToArray()); this.EventManager = new ChartFormEventManager(this); this.ChartForm.AttachEventsToChartFormsManager(); } else { // we had chart already opened with bars loaded; then we clicked on a strategy and we want strategy to be backtested on these bars this.Executor.Initialize(this.ChartForm.ChartControl as ChartShadow, this.Strategy, Assembler.InstanceInitialized.OrderProcessor, Assembler.InstanceInitialized.StatusReporter); if (this.ChartForm.CtxReporters.Items.Count == 0) { this.ChartForm.CtxReporters.Items.AddRange(this.ReportersFormsManager.MenuItemsProvider.MenuItems.ToArray()); } } if (this.DataSnapshot.ChartSettings == null) { this.DataSnapshot.ChartSettings = this.ChartForm.ChartControl.ChartSettings; // opening from Datasource => save } else { this.ChartForm.ChartControl.ChartSettings = this.DataSnapshot.ChartSettings; // otherwize JustDeserialized => propagate this.ChartForm.ChartControl.PropagateSettingSplitterDistancePriceVsVolume(); } //this.ChartForm.CtxReporters.Enabled = true; this.ChartForm.DdbReporters.Enabled = true; this.ChartForm.DdbStrategy.Enabled = true; this.ChartForm.DdbBacktest.Enabled = true; this.ChartForm.MniShowSourceCodeEditor.Enabled = !this.Strategy.ActivatedFromDll; try { //I'm here via Persist.Deserialize() (=> Reporters haven't been restored yet => backtest should be postponed); will backtest in InitializeStrategyAfterDeserialization this.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy(msig, true, true); } catch (Exception ex) { string msg = "PopulateCurrentChartOrScriptContext(): "; Assembler.PopupException(msg + msig, ex); } }
public MainFormEventManager(MainForm mainForm) { this.mainForm = mainForm; }
public MainFormWorkspacesManager(MainForm mainForm) { this.mainForm = mainForm; this.workspaceMenuItems = this.initializeFromRepository(); }