public void To(PortfolioVM portf) { portf.Quantity = this.Quantity; portf.MaxPosition = this.MaxQuantity; if (Leg1) { LegVM leg; if (portf.LegCount < 1) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(0); } leg.Symbol = Symbol1; leg.Side = Side1; leg.Ratio = Ratio1; leg.SetIsPreferred(PreferLeg1); } if (Leg2 || StrategyName == StrategySetting.ChangePositionStrategyName) { LegVM leg; if (portf.LegCount < 2) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(1); } leg.Symbol = Symbol2; leg.Side = Side2; leg.Ratio = Ratio2; leg.IsPreferred = PreferLeg2; } portf.StrategySetting = StrategySetting.Create(StrategyName); if (StrategyName == StrategySetting.ChangePositionStrategyName) { portf.AutoOpen = true; portf.AutoStopGain = false; portf.AutoStopLoss = false; portf.EnablePrefer = true; portf.AutoTracking = true; ChangePositionSetting setting = (ChangePositionSetting)portf.StrategySetting; setting.CloseLeg = Symbol1; setting.CloseLegSide = Side1; } else if (StrategyName == StrategySetting.ScalperStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ScalperSetting setting = (ScalperSetting)portf.StrategySetting; setting.PriceTick = this.PriceTick; setting.Threshold = this.Threshold; } } }
public void To(PortfolioVM portf) { portf.Quantity = this.Quantity; portf.TotalOpenLimit = this.TotalOpenLimit; portf.MaxCancel = this.MaxCancelVol; portf.MaxOpenPerStart = this.MaxOpenPerStart; portf.EndTimePointsExpr = this.EndTimePointsExpr; if (Leg1) { LegVM leg; if (portf.LegCount < 1) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(0); } leg.Symbol = Symbol1; leg.Side = Side1; leg.Ratio = Ratio1; leg.SetIsPreferred(PreferLeg1); } if (Leg2 || StrategyName == StrategySetting.ChangePositionStrategyName) { LegVM leg; if (portf.LegCount < 2) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(1); } leg.Symbol = Symbol2; leg.Side = Side2; leg.Ratio = Ratio2; leg.IsPreferred = PreferLeg2; } portf.StrategySetting = StrategySetting.Create(StrategyName); if (StrategyName == StrategySetting.ArbitrageStrategyName) { ArbitrageStrategySetting setting = (ArbitrageStrategySetting)portf.StrategySetting; setting.BollPeriod = AR_BollPeriod; setting.StdDevMultiplier = AR_StdDevMultiplier; setting.TimeFrame = 60; setting.FirstLegSymbol = Symbol1; setting.SecondLegSymbol = Symbol2; foreach (var l in portf.Legs) { l.MinPriceChange = PriceTick; } } else if (StrategyName == StrategySetting.ChangePositionStrategyName) { portf.AutoOpen = true; portf.AutoStopGain = false; portf.AutoStopLoss = false; portf.EnablePrefer = true; portf.AutoTracking = true; ChangePositionSetting setting = (ChangePositionSetting)portf.StrategySetting; setting.CloseLeg = Symbol1; setting.CloseLegSide = Side1; } else if (StrategyName == StrategySetting.ScalperStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ScalperSetting setting = (ScalperSetting)portf.StrategySetting; setting.PriceTick = this.PriceTick; setting.Threshold = this.Threshold; } } else if (StrategyName == StrategySetting.MACDHistSlopeStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { MACDHistSlopeStrategySetting setting = (MACDHistSlopeStrategySetting)portf.StrategySetting; setting.Symbol = Symbol1; setting.MACD_Short = 12; setting.MACD_Long = 26; setting.MACD_M = 9; setting.FastPeriod = this.FastPeriod; setting.SlowPeriod = this.SlowPeriod; setting.FastStdDiff = this.FastStdDiff; setting.SlowStdDiff = this.SlowStdDiff; setting.FastAngleThreshold = 45; setting.SlowAngleThreshold = 30; setting.TrailingStopValue = this.TrailingStop; } } else if (StrategyName == StrategySetting.WMATrendStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { WMATrendStrategySettings setting = (WMATrendStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = WT_Period; setting.WMA_Param = WMA_Param; setting.MA_N = MA_N; //setting.TrailingStopValue = this.TrailingStop; } } else if (StrategyName == StrategySetting.LinerRegressionStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { LinerRegStrategySettings setting = (LinerRegStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = LR_Period; setting.Number = LR_Number; setting.OpenThreshold = LR_OpenThreshold; setting.CloseThreshold = LR_CloseThreshold; } } else if (StrategyName == StrategySetting.ASCTrendStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ASCTrendStrategySettings setting = (ASCTrendStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = AS_Period; setting.Risk = AS_Risk; setting.AvergatePeriod = AS_AveragePeriod; setting.BreakoutLength = AS_BreakoutLength; } } else if (StrategyName == StrategySetting.RangeTrendStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { RangeTrendStrategySettings setting = (RangeTrendStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = RT_TimeFrame; setting.OpenPeriod = RT_OpenPeriod; setting.ClosePeriod = RT_ClosePeriod; setting.StopLossFactor = RT_StopLossFactor; setting.TrendFactor = RT_TrendFactor; } } else if (StrategyName == StrategySetting.ManualStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ManualStrategySetting setting = (ManualStrategySetting)portf.StrategySetting; setting.RetryTimes = RetryTimes; } } }