/// <summary>
        ///     Initializes the strategy field
        /// </summary>
        public StrategyLayout(Strategy strategy)
        {
            SlotPropertiesTipText = Language.T("Averaging, Trading size, Protection.");
            SlotToolTipText = Language.T("Long position logic.");
            ShowRemoveSlotButtons = true;
            ShowAddSlotButtons = true;
            this.strategy = strategy;
            slots = strategy.Slots;
            SlotMinMidMax = SlotSizeMinMidMax.mid;
            pnlStrategy = new FlowLayoutPanel();
            scrollBar = new VScrollBar();
            SlotPanelsList = new ContextPanel[slots];
            PanelProperties = new Panel();

            for (int slot = 0; slot < slots; slot++)
                SlotPanelsList[slot] = new ContextPanel();

            // FlowLayoutStrategy
            pnlStrategy.Parent = this;
            pnlStrategy.AutoScroll = false;

            //VScrollBarStrategy
            scrollBar.Parent = this;
            scrollBar.TabStop = true;
            scrollBar.Scroll += VScrollBarStrategyScroll;

            if (ShowAddSlotButtons)
            {
                var toolTip = new ToolTip();
                ButtonAddOpenFilter = new Button
                    {
                        Tag = strategy.OpenSlot,
                        Text = Language.T("Add an Opening Logic Condition"),
                        Margin = new Padding(30, 0, 0, Space),
                        UseVisualStyleBackColor = true
                    };
                toolTip.SetToolTip(ButtonAddOpenFilter, Language.T("Add a new entry logic slot to the strategy."));

                ButtonAddCloseFilter = new Button
                    {
                        Tag = strategy.CloseSlot,
                        Text = Language.T("Add a Closing Logic Condition"),
                        Margin = new Padding(30, 0, 0, Space),
                        UseVisualStyleBackColor = true
                    };
                toolTip.SetToolTip(ButtonAddCloseFilter, Language.T("Add a new exit logic slot to the strategy."));

                btnClosingFilterHelp = new Button
                    {
                        Image = Resources.info,
                        Margin = new Padding(2, 2, 0, Space),
                        TabStop = false
                    };
                btnClosingFilterHelp.Click += BtnClosingFilterHelpClick;
                btnClosingFilterHelp.UseVisualStyleBackColor = true;
            }
        }
        /// <summary>
        ///     Represents the Strategy as a XmlDocument.
        /// </summary>
        public static XmlDocument CreateStrategyXmlDoc(Strategy strategy)
        {
            // Create the XmlDocument.
            var xmlDocStrategy = new XmlDocument();
            xmlDocStrategy.LoadXml("<strategy></strategy>");

            //Create the XML declaration.
            XmlDeclaration xmldecl = xmlDocStrategy.CreateXmlDeclaration("1.0", null, null);

            //Add new node to the document.
            XmlElement root = xmlDocStrategy.DocumentElement;
            xmlDocStrategy.InsertBefore(xmldecl, root);

            AppendStringElement(xmlDocStrategy, "programName", Data.ProgramName);
            AppendStringElement(xmlDocStrategy, "programVersion", Data.ProgramVersion);
            AppendStringElement(xmlDocStrategy, "strategyName", strategy.StrategyName);
            AppendStringElement(xmlDocStrategy, "instrumentSymbol", strategy.Symbol);
            AppendStringElement(xmlDocStrategy, "instrumentPeriod", (int) strategy.DataPeriod);
            AppendStringElement(xmlDocStrategy, "sameDirSignalAction", strategy.SameSignalAction.ToString());
            AppendStringElement(xmlDocStrategy, "oppDirSignalAction", strategy.OppSignalAction.ToString());

            // Add the Permanent Stop Loss
            XmlElement newElem = xmlDocStrategy.CreateElement("permanentStopLoss");
            newElem.InnerText = strategy.PermanentSL.ToString(CultureInfo.InvariantCulture);
            newElem.SetAttribute("usePermanentSL", strategy.UsePermanentSL.ToString(CultureInfo.InvariantCulture));
            newElem.SetAttribute("permanentSLType", strategy.PermanentSLType.ToString());
            if (xmlDocStrategy.DocumentElement != null) xmlDocStrategy.DocumentElement.AppendChild(newElem);

            // Add the Permanent Take Profit
            newElem = xmlDocStrategy.CreateElement("permanentTakeProfit");
            newElem.InnerText = strategy.PermanentTP.ToString(CultureInfo.InvariantCulture);
            newElem.SetAttribute("usePermanentTP", strategy.UsePermanentTP.ToString(CultureInfo.InvariantCulture));
            newElem.SetAttribute("permanentTPType", strategy.PermanentTPType.ToString());
            if (xmlDocStrategy.DocumentElement != null) xmlDocStrategy.DocumentElement.AppendChild(newElem);

            // Add the Break Even
            newElem = xmlDocStrategy.CreateElement("breakEven");
            newElem.InnerText = strategy.BreakEven.ToString(CultureInfo.InvariantCulture);
            newElem.SetAttribute("useBreakEven", strategy.UseBreakEven.ToString(CultureInfo.InvariantCulture));
            if (xmlDocStrategy.DocumentElement != null) xmlDocStrategy.DocumentElement.AppendChild(newElem);

            AppendStringElement(xmlDocStrategy, "maxOpenLots", strategy.MaxOpenLots);
            AppendStringElement(xmlDocStrategy, "useAccountPercentEntry", strategy.UseAccountPercentEntry);
            AppendStringElement(xmlDocStrategy, "entryLots", strategy.EntryLots);
            AppendStringElement(xmlDocStrategy, "addingLots", strategy.AddingLots);
            AppendStringElement(xmlDocStrategy, "reducingLots", strategy.ReducingLots);
            AppendStringElement(xmlDocStrategy, "useMartingale", strategy.UseMartingale);
            AppendStringElement(xmlDocStrategy, "martingaleMultiplier", strategy.MartingaleMultiplier);
            AppendStringElement(xmlDocStrategy, "description", strategy.Description);

            // Add the slots.
            AppendStringElement(xmlDocStrategy, "openFilters", strategy.OpenFilters);
            AppendStringElement(xmlDocStrategy, "closeFilters", strategy.CloseFilters);
            for (int slot = 0; slot < strategy.Slots; slot++)
            {
                IndicatorSlot stratSlot = strategy.Slot[slot];
                SlotTypes slType = stratSlot.SlotType;

                // Add a slot element.
                XmlElement newSlot = xmlDocStrategy.CreateElement("slot");
                newSlot.SetAttribute("slotNumber", slot.ToString(CultureInfo.InvariantCulture));
                newSlot.SetAttribute("slotType", slType.ToString());
                newSlot.SetAttribute("slotStatus", stratSlot.SlotStatus.ToString());

                if (slType == SlotTypes.OpenFilter || slType == SlotTypes.CloseFilter)
                    newSlot.SetAttribute("logicalGroup", stratSlot.LogicalGroup);

                // Add an element.
                newElem = xmlDocStrategy.CreateElement("indicatorName");
                newElem.InnerText = stratSlot.IndicatorName;
                newSlot.AppendChild(newElem);

                // Add the list parameters.
                for (int param = 0; param < stratSlot.IndParam.ListParam.Length; param++)
                {
                    if (!stratSlot.IndParam.ListParam[param].Enabled) continue;

                    // Add an element.
                    XmlElement newListElem = xmlDocStrategy.CreateElement("listParam");
                    newListElem.SetAttribute("paramNumber", param.ToString(CultureInfo.InvariantCulture));

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("caption");
                    newElem.InnerText = stratSlot.IndParam.ListParam[param].Caption;
                    newListElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("index");
                    newElem.InnerText = stratSlot.IndParam.ListParam[param].Index.ToString(CultureInfo.InvariantCulture);
                    newListElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("value");
                    newElem.InnerText = stratSlot.IndParam.ListParam[param].Text;
                    newListElem.AppendChild(newElem);

                    newSlot.AppendChild(newListElem);
                }

                // Add the num parameters.
                for (int param = 0; param < stratSlot.IndParam.NumParam.Length; param++)
                {
                    if (!stratSlot.IndParam.NumParam[param].Enabled) continue;

                    // Add an element.
                    XmlElement newNumElem = xmlDocStrategy.CreateElement("numParam");
                    newNumElem.SetAttribute("paramNumber", param.ToString(CultureInfo.InvariantCulture));

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("caption");
                    newElem.InnerText = stratSlot.IndParam.NumParam[param].Caption;
                    newNumElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("value");
                    newElem.InnerText = stratSlot.IndParam.NumParam[param].ValueToString;
                    newNumElem.AppendChild(newElem);

                    newSlot.AppendChild(newNumElem);
                }

                // Add the check parameters.
                for (int param = 0; param < stratSlot.IndParam.CheckParam.Length; param++)
                {
                    if (!stratSlot.IndParam.CheckParam[param].Enabled) continue;

                    // Add an element.
                    XmlElement newCheckElem = xmlDocStrategy.CreateElement("checkParam");
                    newCheckElem.SetAttribute("paramNumber", param.ToString(CultureInfo.InvariantCulture));

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("caption");
                    newElem.InnerText = stratSlot.IndParam.CheckParam[param].Caption;
                    newCheckElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("value");
                    newElem.InnerText =
                        stratSlot.IndParam.CheckParam[param].Checked.ToString(CultureInfo.InvariantCulture);
                    newCheckElem.AppendChild(newElem);

                    newSlot.AppendChild(newCheckElem);
                }

                if (xmlDocStrategy.DocumentElement != null)
                    xmlDocStrategy.DocumentElement.AppendChild(newSlot);
            }

            // Add statistics meta data.
            string unit = " " + Configs.AccountCurrency;
            AppendStringElement(xmlDocStrategy, "AccountBalance", Backtester.NetMoneyBalance.ToString("F2") + unit);
            AppendStringElement(xmlDocStrategy, "ProfitPerDay", Backtester.MoneyProfitPerDay.ToString("F2") + unit);
            AppendStringElement(xmlDocStrategy, "WinLossRatio", Backtester.WinLossRatio.ToString("F2"));
            AppendStringElement(xmlDocStrategy, "AccountStatsParam", String.Join(";", Backtester.AccountStatsParam));
            AppendStringElement(xmlDocStrategy, "AccountStatsValue", String.Join(";", Backtester.AccountStatsValue));
            AppendStringElement(xmlDocStrategy, "MarketStatsParam", String.Join(";", Data.MarketStatsParam));
            AppendStringElement(xmlDocStrategy, "MarketStatsValue", String.Join(";", Data.MarketStatsValue));

            // Add chart data
            int length = Data.Bars - StatsBuffer.FirstBar;
            var balanceLine = new double[length];
            var equityLine = new double[length];
            for (int bar = 0; bar < length; bar++)
            {
                balanceLine[bar] = Backtester.MoneyBalance(bar);
                equityLine[bar] = Backtester.MoneyEquity(bar);
            }
            int size = Math.Min(600, length);
            string[] balanceList = MathUtils.ArrayToStringArray(MathUtils.ArrayResize(balanceLine, size));
            string[] equityList = MathUtils.ArrayToStringArray(MathUtils.ArrayResize(equityLine, size));
            AppendStringElement(xmlDocStrategy, "BalanceLine", String.Join(";", balanceList));
            AppendStringElement(xmlDocStrategy, "EquityLine", String.Join(";", equityList));

            return xmlDocStrategy;
        }
        /// <summary>
        ///     Pareses a strategy from a xml document.
        /// </summary>
        public Strategy ParseXmlStrategy(XmlDocument xmlDocStrategy)
        {
            // Read the number of slots
            int openFilters = int.Parse(xmlDocStrategy.GetElementsByTagName("openFilters")[0].InnerText);
            int closeFilters = int.Parse(xmlDocStrategy.GetElementsByTagName("closeFilters")[0].InnerText);

            // Create the strategy.
// ReSharper disable UseObjectOrCollectionInitializer
            var tempStrategy = new Strategy(openFilters, closeFilters);
// ReSharper restore UseObjectOrCollectionInitializer

            // Same and Opposite direction Actions
            tempStrategy.SameSignalAction =
                (SameDirSignalAction)
                Enum.Parse(typeof (SameDirSignalAction),
                           xmlDocStrategy.GetElementsByTagName("sameDirSignalAction")[0].InnerText);
            tempStrategy.OppSignalAction =
                (OppositeDirSignalAction)
                Enum.Parse(typeof (OppositeDirSignalAction),
                           xmlDocStrategy.GetElementsByTagName("oppDirSignalAction")[0].InnerText);

            // Market
            tempStrategy.Symbol = xmlDocStrategy.GetElementsByTagName("instrumentSymbol")[0].InnerText;
            string period = xmlDocStrategy.GetElementsByTagName("instrumentPeriod")[0].InnerText;
            tempStrategy.DataPeriod = ImportDataPeriod(period);

            // Permanent Stop Loss
            tempStrategy.PermanentSL =
                Math.Abs(int.Parse(xmlDocStrategy.GetElementsByTagName("permanentStopLoss")[0].InnerText));
            // Math.Abs() removes the negative sign from previous versions.
            XmlAttributeCollection xmlAttributeCollection =
                xmlDocStrategy.GetElementsByTagName("permanentStopLoss")[0].Attributes;
            if (xmlAttributeCollection != null)
            {
                tempStrategy.UsePermanentSL = bool.Parse(xmlAttributeCollection["usePermanentSL"].InnerText);
                try
                {
                    tempStrategy.PermanentSLType =
                        (PermanentProtectionType)
                        Enum.Parse(typeof (PermanentProtectionType), xmlAttributeCollection["permanentSLType"].InnerText);
                }
                catch
                {
                    tempStrategy.PermanentSLType = PermanentProtectionType.Relative;
                }
            }

            // Permanent Take Profit
            tempStrategy.PermanentTP = int.Parse(xmlDocStrategy.GetElementsByTagName("permanentTakeProfit")[0].InnerText);
            XmlAttributeCollection attributeCollection =
                xmlDocStrategy.GetElementsByTagName("permanentTakeProfit")[0].Attributes;
            if (attributeCollection != null)
            {
                tempStrategy.UsePermanentTP = bool.Parse(attributeCollection["usePermanentTP"].InnerText);
                try
                {
                    tempStrategy.PermanentTPType =
                        (PermanentProtectionType)
                        Enum.Parse(typeof (PermanentProtectionType), attributeCollection["permanentTPType"].InnerText);
                }
                catch
                {
                    tempStrategy.PermanentTPType = PermanentProtectionType.Relative;
                }
            }

            // Break Even
            try
            {
                tempStrategy.BreakEven = int.Parse(xmlDocStrategy.GetElementsByTagName("breakEven")[0].InnerText);
                XmlAttributeCollection attributes = xmlDocStrategy.GetElementsByTagName("breakEven")[0].Attributes;
                if (attributes != null)
                    tempStrategy.UseBreakEven = bool.Parse(attributes["useBreakEven"].InnerText);
            }
            catch (Exception exception)
            {
                Console.Write(exception.Message);
            }

            // Money Management
            try
            {
                tempStrategy.UseAccountPercentEntry =
                    bool.Parse(xmlDocStrategy.GetElementsByTagName("useAccountPercentEntry")[0].InnerText);
            }
            catch
            {
                tempStrategy.UseAccountPercentEntry =
                    bool.Parse(xmlDocStrategy.GetElementsByTagName("useAcountPercentEntry")[0].InnerText);
            }
            tempStrategy.MaxOpenLots = StringToDouble(xmlDocStrategy.GetElementsByTagName("maxOpenLots")[0].InnerText);
            tempStrategy.EntryLots = StringToDouble(xmlDocStrategy.GetElementsByTagName("entryLots")[0].InnerText);
            tempStrategy.AddingLots = StringToDouble(xmlDocStrategy.GetElementsByTagName("addingLots")[0].InnerText);
            tempStrategy.ReducingLots = StringToDouble(xmlDocStrategy.GetElementsByTagName("reducingLots")[0].InnerText);
            try
            {
                tempStrategy.UseMartingale =
                    bool.Parse(xmlDocStrategy.GetElementsByTagName("useMartingale")[0].InnerText);
                tempStrategy.MartingaleMultiplier =
                    StringToDouble(xmlDocStrategy.GetElementsByTagName("martingaleMultiplier")[0].InnerText);
            }
            catch
            {
                tempStrategy.UseMartingale = false;
                tempStrategy.MartingaleMultiplier = 2.0;
            }

            // Description
            tempStrategy.Description = xmlDocStrategy.GetElementsByTagName("description")[0].InnerText;

            // Strategy name.
            tempStrategy.StrategyName = xmlDocStrategy.GetElementsByTagName("strategyName")[0].InnerText;

            // Reading the slots
            XmlNodeList xmlSlotList = xmlDocStrategy.GetElementsByTagName("slot");
            for (int slot = 0; slot < xmlSlotList.Count; slot++)
            {
                XmlNodeList xmlSlotTagList = xmlSlotList[slot].ChildNodes;

                XmlAttributeCollection collection = xmlSlotList[slot].Attributes;
                if (collection != null)
                {
                    // Identify the Slot Type
                    var slotType = (SlotTypes) Enum.Parse(typeof (SlotTypes), collection["slotType"].InnerText);

                    // Identify the Slot Status
                    StrategySlotStatus slotStatus;
                    try
                    {
                        slotStatus =
                            (StrategySlotStatus)
                            Enum.Parse(typeof (StrategySlotStatus), collection["slotStatus"].InnerText);
                    }
                    catch
                    {
                        slotStatus = StrategySlotStatus.Open;
                    }

                    // Logical group
                    if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
                    {
                        XmlAttributeCollection attributes = collection;
                        XmlNode nodeGroup = attributes.GetNamedItem("logicalGroup");
                        string defGroup = GetDefaultGroup(slotType, slot, tempStrategy.CloseSlot);
                        if (nodeGroup != null)
                        {
                            string group = nodeGroup.InnerText;
                            tempStrategy.Slot[slot].LogicalGroup = @group;
                            if (@group != defGroup && @group.ToLower() != "all" && !Configs.UseLogicalGroups)
                            {
                                MessageBox.Show(
                                    Language.T("The strategy requires logical groups.") + Environment.NewLine +
                                    Language.T("\"Use Logical Groups\" option was temporarily switched on."),
                                    Language.T("Logical Groups"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                                Configs.UseLogicalGroups = true;
                            }
                        }
                        else
                            tempStrategy.Slot[slot].LogicalGroup = defGroup;
                    }

                    // Indicator name.
                    string indicatorName = xmlSlotTagList[0].InnerText;
                    if (!IndicatorManager.AllIndicatorsNames.Contains(indicatorName))
                    {
                        string message = string.Format("Indicator \"{0}\" was not found.", indicatorName);
                        throw new MissingIndicatorException(message);
                    }

                    Indicator indicator = IndicatorManager.ConstructIndicator(indicatorName);
                    indicator.Initialize(slotType);

                    for (int tag = 1; tag < xmlSlotTagList.Count; tag++)
                    {
                        // List parameters
                        if (xmlSlotTagList[tag].Name == "listParam")
                        {
                            XmlAttributeCollection attributes = xmlSlotTagList[tag].Attributes;
                            if (attributes != null)
                            {
                                int listParam = int.Parse(attributes["paramNumber"].InnerText);
                                XmlNode xmlListParamNode = xmlSlotTagList[tag].FirstChild;

                                indicator.IndParam.ListParam[listParam].Caption = xmlListParamNode.InnerText;

                                xmlListParamNode = xmlListParamNode.NextSibling;
                                if (xmlListParamNode != null)
                                {
                                    int index = int.Parse(xmlListParamNode.InnerText);
                                    indicator.IndParam.ListParam[listParam].Index = index;
                                    indicator.IndParam.ListParam[listParam].Text =
                                        indicator.IndParam.ListParam[listParam].ItemList[index];
                                }
                            }
                        }

                        // Numeric parameters
                        if (xmlSlotTagList[tag].Name == "numParam")
                        {
                            XmlNode xmlNumParamNode = xmlSlotTagList[tag].FirstChild;
                            XmlAttributeCollection attributes = xmlSlotTagList[tag].Attributes;
                            if (attributes != null)
                            {
                                int numParam = int.Parse(attributes["paramNumber"].InnerText);
                                indicator.IndParam.NumParam[numParam].Caption = xmlNumParamNode.InnerText;

                                xmlNumParamNode = xmlNumParamNode.NextSibling;
                                if (xmlNumParamNode != null)
                                {
                                    string numParamValue = xmlNumParamNode.InnerText;
                                    numParamValue = numParamValue.Replace(',', Data.PointChar);
                                    numParamValue = numParamValue.Replace('.', Data.PointChar);
                                    float value = float.Parse(numParamValue);

                                    // Removing of the Stop Loss negative sign used in previous versions.
                                    string parCaption = indicator.IndParam.NumParam[numParam].Caption;
                                    if (parCaption == "Trailing Stop" ||
                                        parCaption == "Initial Stop Loss" ||
                                        parCaption == "Stop Loss")
                                        value = Math.Abs(value);
                                    indicator.IndParam.NumParam[numParam].Value = value;
                                }
                            }
                        }

                        // Check parameters
                        if (xmlSlotTagList[tag].Name == "checkParam")
                        {
                            XmlNode xmlCheckParamNode = xmlSlotTagList[tag].FirstChild;
                            XmlAttributeCollection attributes = xmlSlotTagList[tag].Attributes;
                            if (attributes != null)
                            {
                                int checkParam = int.Parse(attributes["paramNumber"].InnerText);
                                indicator.IndParam.CheckParam[checkParam].Caption = xmlCheckParamNode.InnerText;

                                xmlCheckParamNode = xmlCheckParamNode.NextSibling;
                                if (xmlCheckParamNode != null)
                                    indicator.IndParam.CheckParam[checkParam].Checked =
                                        bool.Parse(xmlCheckParamNode.InnerText);
                            }
                        }
                    }

                    // Set the Slot Status (Open, Locked, or Linked)
                    tempStrategy.Slot[slot].SlotStatus = slotStatus;

                    // Calculate the indicator.
                    indicator.Calculate(Data.DataSet);
                    tempStrategy.Slot[slot].IndicatorName = indicator.IndicatorName;
                    tempStrategy.Slot[slot].IndParam = indicator.IndParam;
                    tempStrategy.Slot[slot].Component = indicator.Component;
                    tempStrategy.Slot[slot].SeparatedChart = indicator.SeparatedChart;
                    tempStrategy.Slot[slot].SpecValue = indicator.SpecialValues;
                    tempStrategy.Slot[slot].MinValue = indicator.SeparatedChartMinValue;
                    tempStrategy.Slot[slot].MaxValue = indicator.SeparatedChartMaxValue;
                }
                tempStrategy.Slot[slot].IsDefined = true;
            }

            return tempStrategy;
        }
        /// <summary>
        ///     Returns a copy of the current strategy.
        /// </summary>
        public Strategy Clone()
        {
            // Creates a new strategy.
            var tempStrategy = new Strategy(OpenFilters, CloseFilters)
                {
                    FirstBar = FirstBar,
                    OpenFilters = OpenFilters,
                    CloseFilters = CloseFilters,
                    StrategyName = StrategyName,
                    Description = Description,
                    Symbol = Symbol,
                    DataPeriod = DataPeriod,
                    SameSignalAction = SameSignalAction,
                    OppSignalAction = OppSignalAction,
                    UseAccountPercentEntry = UseAccountPercentEntry,
                    MaxOpenLots = MaxOpenLots,
                    EntryLots = EntryLots,
                    AddingLots = AddingLots,
                    ReducingLots = ReducingLots,
                    UseMartingale = UseMartingale,
                    MartingaleMultiplier = MartingaleMultiplier,
                    UsePermanentSL = UsePermanentSL,
                    PermanentSLType = PermanentSLType,
                    PermanentSL = PermanentSL,
                    UsePermanentTP = UsePermanentTP,
                    PermanentTPType = PermanentTPType,
                    PermanentTP = PermanentTP,
                    UseBreakEven = UseBreakEven,
                    BreakEven = BreakEven
                };

            // Reading the slots
            for (int slot = 0; slot < Slots; slot++)
                tempStrategy.Slot[slot] = Slot[slot].Clone();

            return tempStrategy;
        }
예제 #5
0
        public static void CheckStrategyCompatibility(Strategy strategy)
        {
            bool isProFeatures = false;
            foreach (IndicatorSlot indicatorSlot in strategy.Slot)
            {
                if (indicatorSlot.SignalShift > 0 ||
                    (!string.IsNullOrEmpty(indicatorSlot.IndicatorSymbol) && indicatorSlot.IndicatorSymbol != strategy.Symbol) ||
                    (indicatorSlot.IndicatorPeriod != DataPeriod.M1 && indicatorSlot.IndicatorPeriod != strategy.DataPeriod))
                    isProFeatures = true;
            }

            if (isProFeatures)
            {
                const string message = "This strategy uses features from FSB Pro. It may not trade as expected.";
                MessageBox.Show(message, "Load strategy", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #6
0
        /// <summary>
        ///     Represents the Strategy as a XmlDocument.
        /// </summary>
        public static XmlDocument CreateStrategyXmlDoc(Strategy strategy)
        {
            // Create the XmlDocument.
            var xmlDocStrategy = new XmlDocument();
            xmlDocStrategy.LoadXml("<strategy></strategy>");

            //Create the XML declaration.
            XmlDeclaration xmldecl = xmlDocStrategy.CreateXmlDeclaration("1.0", null, null);

            //Add new node to the document.
            XmlElement root = xmlDocStrategy.DocumentElement;
            xmlDocStrategy.InsertBefore(xmldecl, root);

            AppendStringElement(xmlDocStrategy, "programName", Data.ProgramName);
            AppendStringElement(xmlDocStrategy, "programVersion", Data.ProgramVersion);
            AppendStringElement(xmlDocStrategy, "strategyName", strategy.StrategyName);
            AppendStringElement(xmlDocStrategy, "instrumentSymbol", strategy.Symbol);
            AppendStringElement(xmlDocStrategy, "instrumentPeriod", (int)strategy.DataPeriod);
            AppendStringElement(xmlDocStrategy, "sameDirSignalAction", strategy.SameSignalAction.ToString());
            AppendStringElement(xmlDocStrategy, "oppDirSignalAction", strategy.OppSignalAction.ToString());

            // Add the Permanent Stop Loss
            XmlElement newElem = xmlDocStrategy.CreateElement("permanentStopLoss");
            newElem.InnerText = strategy.PermanentSL.ToString(CultureInfo.InvariantCulture);
            newElem.SetAttribute("usePermanentSL", strategy.UsePermanentSL.ToString(CultureInfo.InvariantCulture));
            newElem.SetAttribute("permanentSLType", strategy.PermanentSLType.ToString());
            if (xmlDocStrategy.DocumentElement != null) xmlDocStrategy.DocumentElement.AppendChild(newElem);

            // Add the Permanent Take Profit
            newElem = xmlDocStrategy.CreateElement("permanentTakeProfit");
            newElem.InnerText = strategy.PermanentTP.ToString(CultureInfo.InvariantCulture);
            newElem.SetAttribute("usePermanentTP", strategy.UsePermanentTP.ToString(CultureInfo.InvariantCulture));
            newElem.SetAttribute("permanentTPType", strategy.PermanentTPType.ToString());
            if (xmlDocStrategy.DocumentElement != null) xmlDocStrategy.DocumentElement.AppendChild(newElem);

            // Add the Break Even
            newElem = xmlDocStrategy.CreateElement("breakEven");
            newElem.InnerText = strategy.BreakEven.ToString(CultureInfo.InvariantCulture);
            newElem.SetAttribute("useBreakEven", strategy.UseBreakEven.ToString(CultureInfo.InvariantCulture));
            if (xmlDocStrategy.DocumentElement != null) xmlDocStrategy.DocumentElement.AppendChild(newElem);

            AppendStringElement(xmlDocStrategy, "maxOpenLots", strategy.MaxOpenLots);
            AppendStringElement(xmlDocStrategy, "useAccountPercentEntry", strategy.UseAccountPercentEntry);
            AppendStringElement(xmlDocStrategy, "entryLots", strategy.EntryLots);
            AppendStringElement(xmlDocStrategy, "addingLots", strategy.AddingLots);
            AppendStringElement(xmlDocStrategy, "reducingLots", strategy.ReducingLots);
            AppendStringElement(xmlDocStrategy, "useMartingale", strategy.UseMartingale);
            AppendStringElement(xmlDocStrategy, "martingaleMultiplier", strategy.MartingaleMultiplier);
            AppendStringElement(xmlDocStrategy, "description", strategy.Description);

            // Add the slots.
            AppendStringElement(xmlDocStrategy, "openFilters", strategy.OpenFilters);
            AppendStringElement(xmlDocStrategy, "closeFilters", strategy.CloseFilters);
            for (int slot = 0; slot < strategy.Slots; slot++)
            {
                IndicatorSlot stratSlot = strategy.Slot[slot];
                SlotTypes slType = stratSlot.SlotType;

                // Add a slot element.
                XmlElement newSlot = xmlDocStrategy.CreateElement("slot");
                newSlot.SetAttribute("slotNumber", slot.ToString(CultureInfo.InvariantCulture));
                newSlot.SetAttribute("slotType", slType.ToString());

                if (slType == SlotTypes.OpenFilter || slType == SlotTypes.CloseFilter)
                    newSlot.SetAttribute("logicalGroup", stratSlot.LogicalGroup);

                // Add an element.
                newElem = xmlDocStrategy.CreateElement("indicatorName");
                newElem.InnerText = stratSlot.IndicatorName;
                newSlot.AppendChild(newElem);

                // Add the list parameters.
                for (int param = 0; param < stratSlot.IndParam.ListParam.Length; param++)
                {
                    if (!stratSlot.IndParam.ListParam[param].Enabled) continue;

                    // Add an element.
                    XmlElement newListElem = xmlDocStrategy.CreateElement("listParam");
                    newListElem.SetAttribute("paramNumber", param.ToString(CultureInfo.InvariantCulture));

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("caption");
                    newElem.InnerText = stratSlot.IndParam.ListParam[param].Caption;
                    newListElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("index");
                    newElem.InnerText = stratSlot.IndParam.ListParam[param].Index.ToString(CultureInfo.InvariantCulture);
                    newListElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("value");
                    newElem.InnerText = stratSlot.IndParam.ListParam[param].Text;
                    newListElem.AppendChild(newElem);

                    newSlot.AppendChild(newListElem);
                }

                // Add the num parameters.
                for (int param = 0; param < stratSlot.IndParam.NumParam.Length; param++)
                {
                    if (!stratSlot.IndParam.NumParam[param].Enabled) continue;

                    // Add an element.
                    XmlElement newNumElem = xmlDocStrategy.CreateElement("numParam");
                    newNumElem.SetAttribute("paramNumber", param.ToString(CultureInfo.InvariantCulture));

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("caption");
                    newElem.InnerText = stratSlot.IndParam.NumParam[param].Caption;
                    newNumElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("value");
                    newElem.InnerText = stratSlot.IndParam.NumParam[param].ValueToString;
                    newNumElem.AppendChild(newElem);

                    newSlot.AppendChild(newNumElem);
                }

                // Add the check parameters.
                for (int param = 0; param < stratSlot.IndParam.CheckParam.Length; param++)
                {
                    if (!stratSlot.IndParam.CheckParam[param].Enabled) continue;

                    // Add an element.
                    XmlElement newCheckElem = xmlDocStrategy.CreateElement("checkParam");
                    newCheckElem.SetAttribute("paramNumber", param.ToString(CultureInfo.InvariantCulture));

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("caption");
                    newElem.InnerText = stratSlot.IndParam.CheckParam[param].Caption;
                    newCheckElem.AppendChild(newElem);

                    // Add an element.
                    newElem = xmlDocStrategy.CreateElement("value");
                    newElem.InnerText =
                        stratSlot.IndParam.CheckParam[param].Checked.ToString(CultureInfo.InvariantCulture);
                    newCheckElem.AppendChild(newElem);

                    newSlot.AppendChild(newCheckElem);
                }

                if (xmlDocStrategy.DocumentElement != null)
                    xmlDocStrategy.DocumentElement.AppendChild(newSlot);
            }

            return xmlDocStrategy;
        }
 /// <summary>
 ///     Repaints the strategy slots
 /// </summary>
 public void RepaintStrategyControls(Strategy newStrategy)
 {
     strategy = newStrategy;
     slots = strategy.Slots;
     pnlStrategy.SuspendLayout();
     foreach (ContextPanel pnl in SlotPanelsList)
         pnl.Invalidate();
     PanelProperties.Invalidate();
     pnlStrategy.ResumeLayout();
 }
 /// <summary>
 ///     Rebuilds all the controls in panel Strategy
 /// </summary>
 public void RebuildStrategyControls(Strategy newStrategy)
 {
     strategy = newStrategy;
     slots = newStrategy.Slots;
     pnlStrategy.SuspendLayout();
     pnlStrategy.Controls.Clear();
     InitializeStrategySlots();
     ArrangeStrategyControls();
     if (ShowAddSlotButtons) SetAddSlotButtons();
     pnlStrategy.ResumeLayout();
 }