public Backtester(ScriptExecutor executor) {
			this.backtestQuoteBarConsumer = new BacktestQuoteBarConsumer(this);
			this.Executor = executor;
			if (this.Executor.Strategy == null) return;
			if (this.Executor.Strategy.Script == null) return;
			this.Initialize(this.Executor.Strategy.Script.BacktestMode);
		}
		public SystemPerformance(ScriptExecutor scriptExecutor) {
			if (scriptExecutor == null) {
				string msg = "we shouldn't execute strategy when this.Executor == null";
				throw new Exception(msg);
			}

			this.Executor = scriptExecutor;
			this.SliceLong			= new SystemPerformanceSlice(this, PositionLongShort.Long,		"StatsForLongPositionsOnly");
			this.SliceShort			= new SystemPerformanceSlice(this, PositionLongShort.Short,		"StatsForShortPositionsOnly");
			this.SlicesShortAndLong	= new SystemPerformanceSlice(this, PositionLongShort.Unknown,	"StatsForShortAndLongPositions");
			this.SliceBuyHold		= new SystemPerformanceSlice(this, PositionLongShort.Unknown,	"StatsForBuyHold");
		}
		public ExecutionDataSnapshot(ScriptExecutor strategyExecutor) {
			this.executor = strategyExecutor;

			this.PositionsOpenNow = new List<Position>();
			this.AlertsPending = new List<Alert>();
			this.AlertsPendingHistoryByBar = new Dictionary<int, List<Alert>>();
			this.AlertsMaster = new List<Alert>();
			this.AlertsNewAfterExec = new List<Alert>();
			this.PositionsMaster = new List<Position>();
			this.PositionsMasterByEntryBar = new Dictionary<int, List<Position>>();
			this.PositionsMasterByExitBar = new Dictionary<int, List<Position>>();
			this.positionSernoAbs = 0;
			this.PositionsOpenedAfterExec = new List<Position>();
			this.PositionsClosedAfterExec = new List<Position>();
			this.Indicators = new Dictionary<string, Indicator>();
		}
		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 MarketRealStreaming(ScriptExecutor executor) {
			this.executor = executor;
		}
		public ScriptExecutorEventGenerator(ScriptExecutor scriptExecutor) {
			this.scriptExecutor = scriptExecutor;
		}
		public PositionPrototypeActivator(ScriptExecutor strategyExecutor) {
			this.executor = strategyExecutor;
		}
		public void Initialize(ScriptExecutor scriptExecutor) {
			this.Executor = scriptExecutor;
		}
示例#9
0
		public virtual void AbsorbFromExecutor(ScriptExecutor executor) {
		}
		public MarketSimStreaming(ScriptExecutor executor) {
			this.executor = executor;
			this.stopLossesActivatedOnPreviousQuotes = new List<Alert>();
		}
		public CommissionCalculatorZero(ScriptExecutor scriptExecutor) : base(scriptExecutor) { }
		public NotOnChartBarsHelper(ScriptExecutor scriptExecutor) {
			this.ScriptExecutor = scriptExecutor;
			this.Registry = new Dictionary<NotOnChartBarsKey, Bars>();
		}
		public bool BacktestStarting(ScriptExecutor executor) {
			this.Executor = executor;
			string msig = " Indicator[" + this.NameWithParameters + "].BacktestStarting()";

			// HACK new Indicator will be Initialize()d with an Executor having Bars generated by BacktestDataSource;
			// HACK so that this.NotOnChartBarsKey won't help to pick up the Registered from NotOnChartBarsHelper;
			// HACK I want the this.NotOnChartDataSourceName be the same as before backtest, from a real datasource ("MOCK")
			this.NotOnChartDataSourceName = executor.Bars.DataSource.Name;

			NotOnChartBarsKey key = this.NotOnChartBarsKey;
			if (string.IsNullOrEmpty(this.NotOnChartSymbol) == false) {
				this.Executor.NotOnChartBarsHelper.FindNonChartBarsSubscribeRegisterForIndicator(key);
				if (this.BarsEffective == null) {
					string msg = "NOT_ON_CHART_BARS_HELPER_DOESNT_HAVE_BARS_REGISTERED[" + this.NotOnChartSymbol + "]";
					this.IndicatorErrorsOnBacktestStartingAppend(msg);
					Assembler.PopupException(msg + msig);
				}
			} else {
				if (this.NotOnChartBarScaleInterval != null) {
					if (this.NotOnChartBarScaleInterval.Scale == BarScale.Unknown
						&& this.NotOnChartBarScaleInterval == this.Executor.Bars.ScaleInterval) {
						string msg = "SET_TO_NULL_IF_SAME_AS_EXECUTORS_BARS";
						this.IndicatorErrorsOnBacktestStartingAppend(msg);
						Assembler.PopupException(msg + msig);
					}
					// v2 self-registered earlier
					Bars rescaled = this.Executor.NotOnChartBarsHelper.RescaledBarsGetRegisteredFor(key);
					if (rescaled == null) {
						// v1
						rescaled = this.Executor.NotOnChartBarsHelper.RescaleBarsAndRegister(key);
					}
					if (rescaled == null) {
						string msg = "BARS_NOT_RESCALABLE[" + this.Executor.Bars.SymbolIntervalScale + "]>[" + key + "]";
						this.IndicatorErrorsOnBacktestStartingAppend(msg);
						Assembler.PopupException(msg + msig);
					}
				}
			}
			
			string paramerersAllValidatedErrors = this.ParametersAllValidate();
			this.IndicatorErrorsOnBacktestStartingAppend(paramerersAllValidatedErrors);

			string indicatorSelfValidationErrors = this.BacktestStartingPreCheckErrors();
			this.IndicatorErrorsOnBacktestStartingAppend(indicatorSelfValidationErrors);
			
			if (string.IsNullOrEmpty(indicatorSelfValidationErrors) == false) {
				string msig2 = " Indicator[" + this.NameWithParameters + "].BacktestStartingPreCheck()";
				Assembler.PopupException(indicatorSelfValidationErrors + msig2);
			}
			bool backtestCanStart = string.IsNullOrEmpty(paramerersAllValidatedErrors)
								 && string.IsNullOrEmpty(indicatorSelfValidationErrors);
			return backtestCanStart;
		}
		public CommissionCalculator(ScriptExecutor scriptExecutor) {
			this.ScriptExecutor = scriptExecutor;
		}
		public MarketSimStatic(ScriptExecutor executor) {
			this.executor = executor;
			this.stopLossesActivatedOnPreviousBars = new List<Alert>();
		}