public override void CopyFrom(StrategySetting settings)
        {
            ChangePositionSetting strategySettings = (ChangePositionSetting)settings;

            this.CloseLeg         = strategySettings.CloseLeg;
            this.CloseLegSide     = strategySettings.CloseLegSide;
            this.TriggerCondition = strategySettings.TriggerCondition;
            this.Threshold        = strategySettings.Threshold;
        }
        protected override void OnSetPortfolio(Account.PortfolioVM portfVm)
        {
            OptionalLegs = from l in portfVm.Legs select l.Symbol;

            ChangePositionSetting settings = (ChangePositionSetting)portfVm.StrategySetting;

            this.CloseLeg         = settings.CloseLeg;
            this.CloseLegSide     = settings.CloseLegSide;
            this.TriggerCondition = settings.TriggerCondition;
            this.Threshold        = settings.Threshold;
        }
        protected override void OnApplySetting()
        {
            ChangePositionSetting settings = (ChangePositionSetting)CurrentPortfolio.StrategySetting;

            settings.CloseLeg         = this.CloseLeg;
            settings.CloseLegSide     = this.CloseLegSide;
            settings.TriggerCondition = this.TriggerCondition;
            settings.Threshold        = this.Threshold;

            base.OnApplySetting();
        }
Exemplo n.º 4
0
        public static StrategySetting Create(string name)
        {
            StrategySetting setting = null;

            switch (name)
            {
            case ArbitrageStrategyName:
                setting = new ArbitrageStrategySetting();
                break;

            case ChangePositionStrategyName:
                setting = new ChangePositionSetting();
                break;

            case ScalperStrategyName:
                setting = new ScalperSetting();
                break;

            case MACDHistSlopeStrategyName:
                setting = new MACDHistSlopeStrategySetting();
                break;

            case WMATrendStrategyName:
                setting = new WMATrendStrategySettings();
                break;

            case LinerRegressionStrategyName:
                setting = new LinerRegStrategySettings();
                break;

            case ASCTrendStrategyName:
                setting = new ASCTrendStrategySettings();
                break;

            case RangeTrendStrategyName:
                setting = new RangeTrendStrategySettings();
                break;

            case ManualStrategyName:
                setting = new ManualStrategySetting();
                break;

            default:
                throw new ArgumentException(string.Format("Unexpected strategy setting ({0})", name));
            }
            return(setting);
        }
Exemplo n.º 5
0
        public static StrategySetting Create(string name)
        {
            if (name == ArbitrageStrategyName)
            {
                ArbitrageStrategySetting setting = new ArbitrageStrategySetting();
                setting.Direction         = entity.PosiDirectionType.LONG;
                setting.OpenCondition     = CompareCondition.LESS_EQUAL_THAN;
                setting.OpenThreshold     = 0;
                setting.StopGainCondition = CompareCondition.GREATER_THAN;
                setting.StopGainThreshold = 0;
                setting.StopLossCondition = CompareCondition.GREATER_THAN;
                setting.StopLossThreshold = 0;
                return(setting);
            }
            else if (name == ChangePositionStrategyName)
            {
                ChangePositionSetting setting = new ChangePositionSetting();
                setting.TriggerCondition = CompareCondition.GREATER_EQUAL_THAN;
                setting.Threshold        = 100;

                return(setting);
            }
            else if (name == ScalperStrategyName)
            {
                ScalperSetting setting = new ScalperSetting();
                setting.Threshold           = 0;
                setting.PriceTick           = 0.2;
                setting.CaseLE2Tick         = entity.DirectionDepends.ON_SMALL_SIZE;
                setting.CaseLE3Tick         = entity.DirectionDepends.ON_BIG_SIZE;
                setting.CaseGE4Tick         = entity.DirectionDepends.ON_SMALL_CHANGE;
                setting.CaseNoChange        = entity.DirectionDepends.ON_BIG_SIZE;
                setting.StopLossCloseMethod = entity.StopLossCloseMethods.BASED_ON_NEXT_QUOTE;
                setting.RetryTimes          = 8;
                setting.OpenTimeout         = 100;
                return(setting);
            }
            else
            {
                throw new ArgumentException(string.Format("Unexpected strategy type - {0}", name));
            }
        }
Exemplo n.º 6
0
        public static StrategySetting Load(string name, string xmlText)
        {
            if (name == ArbitrageStrategyName)
            {
                ArbitrageStrategySetting setting = new ArbitrageStrategySetting();

                XElement elem = XElement.Parse(xmlText);

                XAttribute attr = elem.Attribute("direction");
                if (attr != null)
                {
                    setting.Direction = (entity.PosiDirectionType)Enum.Parse(typeof(entity.PosiDirectionType), attr.Value);
                }

                XElement elemOpen = elem.Element("open");
                attr = elemOpen.Attribute("condition");
                if (attr != null)
                {
                    setting.OpenCondition = (CompareCondition)Enum.Parse(typeof(CompareCondition), attr.Value);
                }
                attr = elemOpen.Attribute("threshold");
                if (attr != null)
                {
                    setting.OpenThreshold = double.Parse(attr.Value);
                }

                XElement elemStopGain = elem.Element("stopGain");
                attr = elemStopGain.Attribute("condition");
                if (attr != null)
                {
                    setting.StopGainCondition = (CompareCondition)Enum.Parse(typeof(CompareCondition), attr.Value);
                }
                attr = elemStopGain.Attribute("threshold");
                if (attr != null)
                {
                    setting.StopGainThreshold = double.Parse(attr.Value);
                }

                XElement elemStopLoss = elem.Element("stopLoss");
                attr = elemStopLoss.Attribute("condition");
                if (attr != null)
                {
                    setting.StopLossCondition = (CompareCondition)Enum.Parse(typeof(CompareCondition), attr.Value);
                }
                attr = elemStopLoss.Attribute("threshold");
                if (attr != null)
                {
                    setting.StopLossThreshold = double.Parse(attr.Value);
                }

                return(setting);
            }
            else if (name == ChangePositionStrategyName)
            {
                ChangePositionSetting setting = new ChangePositionSetting();

                XElement elem = XElement.Parse(xmlText);

                XAttribute attr = elem.Attribute("closeLeg");
                if (attr != null)
                {
                    setting.CloseLeg = attr.Value;
                }

                attr = elem.Attribute("side");
                if (attr != null)
                {
                    setting.CloseLegSide = (entity.PosiDirectionType)Enum.Parse(typeof(entity.PosiDirectionType), attr.Value);
                }

                attr = elem.Attribute("triggerCondition");
                if (attr != null)
                {
                    setting.TriggerCondition = (CompareCondition)Enum.Parse(typeof(CompareCondition), attr.Value);
                }

                attr = elem.Attribute("threshold");
                if (attr != null)
                {
                    setting.Threshold = double.Parse(attr.Value);
                }

                return(setting);
            }
            else if (name == ScalperStrategyName)
            {
                ScalperSetting setting = new ScalperSetting();
                XElement       elem    = XElement.Parse(xmlText);
                XAttribute     attr    = elem.Attribute("threshold");
                if (attr != null)
                {
                    setting.Threshold = double.Parse(attr.Value);
                }
                attr = elem.Attribute("prickTick");
                if (attr != null)
                {
                    setting.PriceTick = double.Parse(attr.Value);
                }
                attr = elem.Attribute("caseLE2Tick");
                if (attr != null)
                {
                    setting.CaseLE2Tick = (entity.DirectionDepends)Enum.Parse(typeof(entity.DirectionDepends), attr.Value);
                }
                attr = elem.Attribute("caseLE3Tick");
                if (attr != null)
                {
                    setting.CaseLE3Tick = (entity.DirectionDepends)Enum.Parse(typeof(entity.DirectionDepends), attr.Value);
                }
                attr = elem.Attribute("caseGE4Tick");
                if (attr != null)
                {
                    setting.CaseGE4Tick = (entity.DirectionDepends)Enum.Parse(typeof(entity.DirectionDepends), attr.Value);
                }
                attr = elem.Attribute("caseNoChange");
                if (attr != null)
                {
                    setting.CaseNoChange = (entity.DirectionDepends)Enum.Parse(typeof(entity.DirectionDepends), attr.Value);
                }
                attr = elem.Attribute("stopLossCloseStrategy");
                if (attr != null)
                {
                    setting.StopLossCloseMethod = (entity.StopLossCloseMethods)Enum.Parse(typeof(entity.StopLossCloseMethods), attr.Value);
                }
                attr = elem.Attribute("retryTimes");
                if (attr != null)
                {
                    setting.RetryTimes = int.Parse(attr.Value);
                }
                attr = elem.Attribute("openTimeout");
                if (attr != null)
                {
                    setting.OpenTimeout = int.Parse(attr.Value);
                }
                return(setting);
            }
            else
            {
                throw new ArgumentException(string.Format("Unexpected strategy setting ({0})", name));
            }
        }