internal void ChartRangeBar_AnyValueChanged(object sender, RangeArgs <DateTime> e) { BarDataRange newRange = new BarDataRange(e.ValueMin.Date, e.ValueMax.Date); try { this.chartFormManager.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy("ChartRangeBar_AnyValueChanged"); } catch (Exception ex) { Assembler.PopupException("ChartRangeBar_AnyValueChanged", ex); } }
protected ContextChart() { Name = "UNDEFINED"; Symbol = "UNDEFINED"; DataSourceName = "UNDEFINED"; ScaleInterval = new BarScaleInterval(); DataRange = new BarDataRange(500); //ChartBarSpacing = 6; ChartStreaming = false; ShowRangeBar = false; }
public void AbsorbFrom(ContextChart found) { if (found == null) { return; } //KEEP_CLONE_UNDEFINED this.Name = found.Name; this.Symbol = found.Symbol; this.DataSourceName = found.DataSourceName; this.ScaleInterval = found.ScaleInterval.Clone(); this.DataRange = found.DataRange.Clone(); //this.ChartBarSpacing = found.ChartBarSpacing; this.ChartStreaming = found.ChartStreaming; this.ShowRangeBar = found.ShowRangeBar; }
public Bars RescaleBarsAndRegister(NotOnChartBarsKey symbolScaleInterval) { DataSource ds = Assembler.InstanceInitialized.RepositoryJsonDataSource.DataSourceFind(symbolScaleInterval.DataSourceName); BarDataRange range = new BarDataRange(this.ScriptExecutor.Bars.BarFirst.DateTimeOpen, this.ScriptExecutor.Bars.BarLast.DateTimeOpen); Bars bars = null; try { Bars barsAll = ds.BarsLoadAndCompress(symbolScaleInterval.Symbol, symbolScaleInterval.BarScaleInterval); Bars bar = barsAll.SelectRange(range); } catch (Exception ex) { Debugger.Break(); } try { this.Registry.Add(symbolScaleInterval, bars); } catch (Exception ex) { Debugger.Break(); } return(bars); }
public void PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy(string msig, bool loadNewBars = true, bool skipBacktest = false) { //TODO abort backtest here if running!!! (wait for streaming=off) since ChartStreaming wrongly sticks out after upstack you got "Selectors should've been disabled" Exception ContextChart context = this.ContextCurrentChartOrStrategy; msig += (this.Strategy != null) ? " << PopulateCurrentScriptContext(): Strategy[" + this.Strategy + "].ScriptContextCurrent[" + context.Name + "]" : " << PopulateCurrentScriptContext(): this.ChartForm[" + this.ChartForm.Text + "].ChartControl.ContextChart[" + context.Name + "]"; //BarScaleInterval barScaleInterval = (contextToPopulate.ScaleInterval != null) ? contextToPopulate.ScaleInterval : new BarScaleInterval(); if (context.ScaleInterval.Scale == BarScale.Unknown) { string msg = "contextToPopulate.ScaleInterval[" + context.ScaleInterval + "] has BarScale.Unknown #1" + "; WILL_NOT_INITIALIZE Executor.Init(Strategy->BarsLoaded)"; Assembler.PopupException(msg + msig); return; } if (string.IsNullOrEmpty(context.DataSourceName)) { string msg = "DataSourceName.IsNullOrEmpty; WILL_NOT_INITIALIZE Executor.Init(Strategy->BarsLoaded)"; Assembler.PopupException(msg + msig); return; } DataSource dataSource = Assembler.InstanceInitialized.RepositoryJsonDataSource.DataSourceFind(context.DataSourceName); if (dataSource == null) { string msg = "DataSourceName[" + context.DataSourceName + "] not found; WILL_NOT_INITIALIZE Executor.Init(Strategy->BarsLoaded)"; Assembler.PopupException(msg + msig); return; } if (string.IsNullOrEmpty(context.Symbol)) { string msg = "Strategy[" + this.Strategy + "].ScriptContextCurrent.Symbol.IsNullOrEmpty; WILL_NOT_INITIALIZE Executor.Init(Strategy->BarsLoaded)"; Assembler.PopupException(msg + msig); return; } string symbol = context.Symbol; if (context.ChartStreaming) { string msg = "strategyToSave[" + this.Strategy + "].ScriptContextCurrent[].ChartStreaming=true" + "; Selectors should've been Disable()d on chat[" + this.ChartForm + "].Activated() or StreamingOn()" + " in MainForm.PropagateSelectorsForCurrentChart()"; throw new Exception(msg + msig); } BarScaleInterval barScaleInterval = context.ScaleInterval; if (barScaleInterval.Scale == BarScale.Unknown) { barScaleInterval = dataSource.ScaleInterval; } if (barScaleInterval.Scale == BarScale.Unknown) { string msg = "barScaleInterval.ScaleInterval[" + barScaleInterval + "] has BarScale.Unknown #3" + "; WILL_NOT_INITIALIZE Executor.Init(Strategy->BarsLoaded)"; throw new Exception(msg + msig); } BarDataRange barRange = (context.DataRange != null) ? context.DataRange : new BarDataRange(); //PositionSize posSize = (contextToPopulate.PositionSize != null) ? contextToPopulate.PositionSize : new PositionSize(); if (loadNewBars) { Bars barsAll = dataSource.BarsLoadAndCompress(symbol, barScaleInterval); if (barsAll.Count > 0) { this.ChartForm.ChartControl.RangeBar.Initialize(barsAll, barsAll); } Bars barsClicked = barsAll.SelectRange(barRange); this.Executor.SetBars(barsClicked); this.ChartForm.ChartControl.Initialize(barsClicked); //SCROLL_TO_SNAPSHOTTED_BAR this.ChartForm.ChartControl.ScrollToLastBarRight(); this.ChartForm.PopulateBtnStreamingClickedAndText(); context.ScaleInterval = barScaleInterval; context.DataRange = barRange; } // set original Streaming Icon before we lost in simulationPreBarsSubstitute() and launched backtester in another thread //V1 this.Executor.Performance.Initialize(); //V2_REPORTERS_NOT_REFRESHED this.Executor.BacktesterRunSimulation(); var iconCanBeNull = this.Executor.DataSource.StreamingProvider != null ? this.Executor.DataSource.StreamingProvider.Icon : null; this.ChartForm.PropagateContextChartOrScriptToLTB(context, iconCanBeNull); // v1 already in ChartRenderer.OnNewBarsInjected event - commented out DoInvalidate(); // v2 NOPE, during DataSourcesTree_OnSymbolSelected() we're invalidating it here! - uncommented back this.ChartForm.ChartControl.InvalidateAllPanelsFolding(); if (this.Strategy == null) { this.DataSnapshotSerializer.Serialize(); return; } this.Strategy.ScriptContextCurrent.PositionSize = this.Strategy.ScriptContextCurrent.PositionSize; Assembler.InstanceInitialized.RepositoryDllJsonStrategy.StrategySave(this.Strategy); if (skipBacktest) { return; } if (this.Strategy.ScriptContextCurrent.BacktestOnSelectorsChange == false) { return; } if (this.Strategy.Script == null) { //this.StrategyCompileActivatePopulateSlidersShow(); string msg = "1) will compile it upstack in InitializeStrategyAfterDeserialization() or 2) compilation failed at Editor-F5"; Debugger.Break(); return; } this.BacktesterRunSimulationRegular(); }