예제 #1
0
        void mnitlbShowLastBars_UserTyped(object sender, LabeledTextBoxUserTypedArgs e)
        {
            try {
                string userTyped = e.StringUserTyped;
                int    userTypedInteger;
                bool   validInteger = Int32.TryParse(userTyped, out userTypedInteger);
                if (validInteger == false)
                {
                    e.HighlightTextWithRed = true;
                    return;
                }
                if (userTypedInteger < 0)
                {
                    e.HighlightTextWithRed = true;
                    return;
                }

                ContextChart context = this.ChartFormManager.ContextCurrentChartOrStrategy;
                context.DataRange = (userTypedInteger == 0) ? new BarDataRange() : new BarDataRange(userTypedInteger);

                this.mnitlbShowLastBars.BackColor = Color.Gainsboro;
                this.mniShowBarRange.Checked      = false;
                this.mniShowBarRange_Click(sender, null);

                this.ChartFormManager.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy("mnitlbShowLastBars_UserTyped");
            } catch (Exception ex) {
                Assembler.PopupException("mnitlbShowLastBars_UserTyped()", ex);
            }
        }
예제 #2
0
        void chartCreateShowPopulateSelectorsSlidersNoStrategy(ContextChart contextChart)
        {
            ChartFormManager chartFormManager = new ChartFormManager();

            chartFormManager.InitializeChartNoStrategy(this.mainForm, contextChart);
            this.mainForm.GuiDataSnapshot.ChartFormManagers.Add(chartFormManager.DataSnapshot.ChartSerno, chartFormManager);
            chartFormManager.ChartFormShow();
        }
예제 #3
0
        void mnitlbAll_UserTyped(object sender, LabeledTextBoxUserTypedArgs e)
        {
            try {
                string userTyped = e.StringUserTyped;
                int    userTypedInteger;
                bool   validInteger = Int32.TryParse(userTyped, out userTypedInteger);
                if (validInteger == false)
                {
                    e.HighlightTextWithRed = true;
                    return;
                }
                if (userTypedInteger <= 0)
                {
                    e.HighlightTextWithRed = true;
                    return;
                }
                MenuItemLabeledTextBox mniTypedAsLTB = sender as MenuItemLabeledTextBox;
                if (mniTypedAsLTB == null)
                {
                    string msg = "SENDER_MUSTBE_LabeledTextBoxControl_GOT " + mniTypedAsLTB.GetType();
                    Assembler.PopupException(msg);
                    return;
                }

                BarScale barScaleTyped;
                switch (mniTypedAsLTB.Name)
                {
                case "mnitlbMinutes":           barScaleTyped = BarScale.Minute;                break;

                case "mnitlbHourly":            barScaleTyped = BarScale.Hour;                  break;

                case "mnitlbDaily":                     barScaleTyped = BarScale.Daily;                 break;

                case "mnitlbWeekly":            barScaleTyped = BarScale.Weekly;                break;

                case "mnitlbMonthly":           barScaleTyped = BarScale.Monthly;               break;

                //case "mnitlbQuarterly":		barScaleTyped = BarScale.Quarterly;		break;
                case "mnitlbYearly":            barScaleTyped = BarScale.Yearly;                break;

                default:
                    string msg = "SENDER_UNEXPECTED_NAME " + mniTypedAsLTB.Name;
                    Assembler.PopupException(msg);
                    return;
                }

                this.selectOneDeselectResetOthers(this.DdbBars.DropDownItems, mniTypedAsLTB, this.GroupScaleLabeledTextboxes);

                BarScaleInterval scaleIntervalUserEntered = new BarScaleInterval(barScaleTyped, userTypedInteger);
                ContextChart     context = this.ChartFormManager.ContextCurrentChartOrStrategy;
                context.ScaleInterval = scaleIntervalUserEntered;
                this.ChartFormManager.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy("mniltbAll_UserTyped");
            } catch (Exception ex) {
                Assembler.PopupException("mniltbMinutes_UserTyped()", ex);
            }
        }
예제 #4
0
        internal void DataSourcesTree_OnNewChartForSymbolClicked(object sender, DataSourceSymbolEventArgs e)
        {
            ContextChart contextChart = new ContextChart("CHART_" + e.Symbol);

            contextChart.DataSourceName = e.DataSource.Name;
            contextChart.Symbol         = e.Symbol;
            contextChart.ScaleInterval  = e.DataSource.ScaleInterval;
            //this.chartCreateShowPopulateSelectorsSliders(contextChart);
            this.chartCreateShowPopulateSelectorsSlidersNoStrategy(contextChart);
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        public void PropagateContextChartOrScriptToLTB(ContextChart ctxChart, Bitmap streamingProviderIcon = null)
        {
            if (base.InvokeRequired)
            {
                base.BeginInvoke((MethodInvoker) delegate { this.PropagateContextChartOrScriptToLTB(ctxChart, streamingProviderIcon); });
                return;
            }

            if (streamingProviderIcon != null)
            {
                this.btnStreaming.Image = streamingProviderIcon;
            }
            // from btnStreaming_Click(); not related but visualises the last clicked state
            if (this.btnStreaming.Checked)
            {
                this.mniBacktestOnSelectorsChange.Enabled = false;
                this.mniBacktestNow.Enabled = false;
                this.btnAutoSubmit.Enabled  = true;
            }
            else
            {
                this.mniBacktestOnSelectorsChange.Enabled = true;
                this.mniBacktestNow.Enabled = true;
                this.btnAutoSubmit.Enabled  = false;
            }

            if (ctxChart.ShowRangeBar)
            {
                this.ChartControl.RangeBarCollapsed = false;
                this.mniShowBarRange.Checked        = true;
            }
            else
            {
                this.ChartControl.RangeBarCollapsed = true;
                this.mniShowBarRange.Checked        = false;
            }

            this.btnStreaming.Checked = ctxChart.ChartStreaming;
            ContextScript ctxScript = ctxChart as ContextScript;

            if (ctxScript == null)
            {
                return;
            }

            this.mniBacktestOnRestart.Checked         = ctxScript.BacktestOnRestart;
            this.mniBacktestOnSelectorsChange.Checked = ctxScript.BacktestOnSelectorsChange;
            this.btnAutoSubmit.Checked = ctxScript.ChartAutoSubmitting;
            this.PropagateContextScriptToLTB(ctxScript);
        }
예제 #7
0
        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();
        }