Exemplo n.º 1
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);
            }
        }
		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 ChartFormManager(int charSernoDeserialized = -1) {
			// deserialization: ChartSerno will be restored; never use this constructor in your app!
			this.ScriptEditedNeedsSaving = false;
//			this.Executor = new ScriptExecutor(Assembler.InstanceInitialized.ScriptExecutorConfig
//				, this.ChartForm.ChartControl, null, Assembler.InstanceInitialized.OrderProcessor, Assembler.InstanceInitialized.StatusReporter);
			this.Executor = new ScriptExecutor();
			this.ReportersFormsManager = new ReportersFormsManager(this, Assembler.InstanceInitialized.RepositoryDllReporters);
			this.ChartStreamingConsumer = new ChartFormStreamingConsumer(this);
			
			this.DataSnapshotSerializer = new Serializer<ChartFormDataSnapshot>();
			if (charSernoDeserialized == -1) {
				this.DataSnapshot = new ChartFormDataSnapshot();
				return;
			}
			bool createdNewFile = this.DataSnapshotSerializer.Initialize(Assembler.InstanceInitialized.AppDataPath,
				"ChartFormDataSnapshot-" + charSernoDeserialized + ".json", "Workspaces",
				Assembler.InstanceInitialized.AssemblerDataSnapshot.CurrentWorkspaceName, true, true);
			this.DataSnapshot = this.DataSnapshotSerializer.Deserialize();
			this.DataSnapshot.ChartSerno = charSernoDeserialized;
			this.DataSnapshotSerializer.Serialize();
		}
Exemplo n.º 4
0
        public ChartFormManager(int charSernoDeserialized = -1)
        {
            // deserialization: ChartSerno will be restored; never use this constructor in your app!
            this.ScriptEditedNeedsSaving = false;
//			this.Executor = new ScriptExecutor(Assembler.InstanceInitialized.ScriptExecutorConfig
//				, this.ChartForm.ChartControl, null, Assembler.InstanceInitialized.OrderProcessor, Assembler.InstanceInitialized.StatusReporter);
            this.Executor = new ScriptExecutor();
            this.ReportersFormsManager  = new ReportersFormsManager(this, Assembler.InstanceInitialized.RepositoryDllReporters);
            this.ChartStreamingConsumer = new ChartFormStreamingConsumer(this);

            this.DataSnapshotSerializer = new Serializer <ChartFormDataSnapshot>();
            if (charSernoDeserialized == -1)
            {
                this.DataSnapshot = new ChartFormDataSnapshot();
                return;
            }
            bool createdNewFile = this.DataSnapshotSerializer.Initialize(Assembler.InstanceInitialized.AppDataPath,
                                                                         "ChartFormDataSnapshot-" + charSernoDeserialized + ".json", "Workspaces",
                                                                         Assembler.InstanceInitialized.AssemblerDataSnapshot.CurrentWorkspaceName, true, true);

            this.DataSnapshot            = this.DataSnapshotSerializer.Deserialize();
            this.DataSnapshot.ChartSerno = charSernoDeserialized;
            this.DataSnapshotSerializer.Serialize();
        }
		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);
			}
		}
Exemplo n.º 6
0
        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);
            }
        }