Example #1
0
        /// <summary>
        /// Sets the indicator overview and warning message.
        /// </summary>
        private void SetIndicatorNotification(Indicator indicator)
        {
            // Warning message.
            _warningMessage             = indicator.WarningMessage;
            LblIndicatorWarning.Visible = !string.IsNullOrEmpty(_warningMessage);

            // Set description.
            indicator.SetDescription(SlotType);
            _description = "Long position:" + Environment.NewLine;
            if (SlotType == SlotTypes.Open)
            {
                _description += "   Open a long position " + indicator.EntryPointLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Open a short position " + indicator.EntryPointShortDescription + ".";
            }
            else if (SlotType == SlotTypes.OpenFilter)
            {
                _description += "   Open a long position when " + indicator.EntryFilterLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Open a short position when " + indicator.EntryFilterShortDescription + ".";
            }
            else if (SlotType == SlotTypes.Close)
            {
                _description += "   Close a long position " + indicator.ExitPointLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Close a short position " + indicator.ExitPointShortDescription + ".";
            }
            else
            {
                _description += "   Close a long position when " + indicator.ExitFilterLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Close a short position when " + indicator.ExitFilterShortDescription + ".";
            }

            for (int i = 0; i < 2; i++)
            {
                if (indicator.IndParam.CheckParam[i].Caption == "Use previous bar value")
                {
                    _description += Environment.NewLine + "-------------" + Environment.NewLine + "* Use the value of " +
                                    indicator.IndicatorName + " from the previous bar.";
                }
            }

            _toolTip.SetToolTip(LblIndicatorInfo, _description);
        }
Example #2
0
        /// <summary>
        /// Tests general parameters of a custom indicator.
        /// </summary>
        /// <returns>True, if the test succeed.</returns>
        public static bool CustomIndicatorFastTest(Indicator indicator, out string errorList)
        {
            bool isOk = true;

            var sb = new StringBuilder();

            sb.AppendLine("ERROR: Indicator test failed for the '" + indicator.IndicatorName + "' indicator.");

            // Tests the IndicatorName property.
            if (string.IsNullOrEmpty(indicator.IndicatorName))
            {
                sb.AppendLine("\tThe property 'IndicatorName' is not set.");
                isOk = false;
            }

            // Tests the PossibleSlots property.
            if (!indicator.TestPossibleSlot(SlotTypes.Open) &&
                !indicator.TestPossibleSlot(SlotTypes.OpenFilter) &&
                !indicator.TestPossibleSlot(SlotTypes.Close) &&
                !indicator.TestPossibleSlot(SlotTypes.CloseFilter))
            {
                sb.AppendLine("\tThe property 'PossibleSlots' is not set.");
                isOk = false;
            }

            // Tests the CustomIndicator property.
            if (!indicator.CustomIndicator)
            {
                sb.AppendLine("\tThe indicator '" + indicator.IndicatorName +
                              "' is not marked as custom. Set CustomIndicator = true;");
                isOk = false;
            }

            // Tests the SeparatedChartMaxValue properties.
            if (!indicator.SeparatedChart && indicator.SeparatedChartMaxValue != double.MinValue)
            {
                sb.AppendLine("\tSet SeparatedChart = true; or remove the property: SeparatedChartMaxValue = " +
                              indicator.SeparatedChartMaxValue.ToString(CultureInfo.InvariantCulture));
                isOk = false;
            }

            // Tests the SeparatedChartMinValue properties.
            if (!indicator.SeparatedChart && indicator.SeparatedChartMinValue != double.MaxValue)
            {
                sb.AppendLine("\tSet SeparatedChart = true; or remove the property: SeparatedChartMinValue = " +
                              indicator.SeparatedChartMinValue.ToString(CultureInfo.InvariantCulture));
                isOk = false;
            }

            // Tests the SpecialValues properties.
            if (!indicator.SeparatedChart && indicator.SpecialValues.Length > 0)
            {
                sb.AppendLine("\tSet SeparatedChart = true; or remove the property SpecialValues");
                isOk = false;
            }

            // Tests the IndParam properties.
            if (indicator.IndParam == null)
            {
                sb.AppendLine("\tThe property IndParam is not set. Set IndParam = new IndicatorParam();");
                isOk = false;
            }

            // Tests the IndParam.IndicatorName properties.
            if (indicator.IndParam.IndicatorName != indicator.IndicatorName)
            {
                sb.AppendLine(
                    "\tThe property IndParam.IndicatorName is not set. Set IndParam.IndicatorName = IndicatorName;");
                isOk = false;
            }

            // Tests the IndParam.SlotType properties.
            if (indicator.IndParam.SlotType != SlotTypes.NotDefined)
            {
                sb.AppendLine("\tThe property IndParam.SlotType is not set. Set IndParam.SlotType = slotType;");
                isOk = false;
            }

            // Tests the IndParam.ListParam properties.
            for (int iParam = 0; iParam < indicator.IndParam.ListParam.Length; iParam++)
            {
                ListParam listParam = indicator.IndParam.ListParam[iParam];
                if (!listParam.Enabled)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(listParam.Caption))
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].Caption is not set.");
                    isOk = false;
                }

                if (listParam.ItemList.Length == 0)
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].ItemList is not set.");
                    isOk = false;
                }

                if (listParam.ItemList[listParam.Index] != listParam.Text)
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].Text is wrong." +
                                  " Set " + "IndParam.ListParam[" + iParam + "].Text = IndParam.ListParam[" + iParam +
                                  "].ItemList[IndParam.ListParam[" + iParam + "].Index];");
                    isOk = false;
                }

                if (string.IsNullOrEmpty(listParam.ToolTip))
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].ToolTip is not set.");
                    isOk = false;
                }
            }

            // Tests the IndParam.NumParam properties.
            for (int param = 0; param < indicator.IndParam.NumParam.Length; param++)
            {
                NumericParam numParam = indicator.IndParam.NumParam[param];
                if (!numParam.Enabled)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(numParam.Caption))
                {
                    sb.AppendLine("\tThe property IndParam.NumParam[" + param + "].Caption is not set.");
                    isOk = false;
                }

                double value = numParam.Value;
                double min   = numParam.Min;
                double max   = numParam.Max;
                double point = numParam.Point;

                if (min > max)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Min > IndParam.NumParam[" + param + "].Max.");
                    isOk = false;
                }

                if (value > max)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Value > IndParam.NumParam[" + param + "].Max.");
                    isOk = false;
                }

                if (value < min)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Value < IndParam.NumParam[" + param + "].Min.");
                    isOk = false;
                }

                if (point < 0)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Point cannot be < 0");
                    isOk = false;
                }

                if (point > 6)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Point cannot be > 6");
                    isOk = false;
                }

                if (string.IsNullOrEmpty(numParam.ToolTip))
                {
                    sb.AppendLine("\tThe property IndParam.NumParam[" + param + "].ToolTip is not set.");
                    isOk = false;
                }
            }

            // Tests the IndParam.CheckParam properties.
            for (int param = 0; param < indicator.IndParam.CheckParam.Length; param++)
            {
                CheckParam checkParam = indicator.IndParam.CheckParam[param];
                if (!checkParam.Enabled)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(checkParam.Caption))
                {
                    sb.AppendLine("\tThe property IndParam.CheckParam[" + param + "].Caption is not set.");
                    isOk = false;
                }

                if (string.IsNullOrEmpty(checkParam.ToolTip))
                {
                    sb.AppendLine("\tThe property IndParam.CheckParam[" + param + "].ToolTip is not set.");
                    isOk = false;
                }
            }

            try
            {
                indicator.Calculate(SlotTypes.NotDefined);
            }
            catch (Exception exc)
            {
                sb.AppendLine("\tError when executing Calculate(SlotTypes.NotDefined). " + exc.Message);
                isOk = false;
            }

            try
            {
                indicator.SetDescription(SlotTypes.NotDefined);
            }
            catch (Exception exc)
            {
                sb.AppendLine("\tError when executing SetDescription(SlotTypes.NotDefined). " + exc.Message);
                isOk = false;
            }

            try
            {
                indicator.ToString();
            }
            catch (Exception exc)
            {
                sb.AppendLine("\tError when executing ToString(). " + exc.Message);
                isOk = false;
            }

            errorList = isOk ? string.Empty : sb.ToString();

            return(isOk);
        }
        /// <summary>
        /// Sets the indicator overview and warning message.
        /// </summary>
        private void SetIndicatorNotification(Indicator indicator)
        {
            // Warning message.
            _warningMessage = indicator.WarningMessage;
            LblIndicatorWarning.Visible = !string.IsNullOrEmpty(_warningMessage);

            // Set description.
            indicator.SetDescription(SlotType);
            _description = "Long position:" + Environment.NewLine;
            if (SlotType == SlotTypes.Open)
            {
                _description += "   Open a long position " + indicator.EntryPointLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Open a short position " + indicator.EntryPointShortDescription + ".";
            }
            else if (SlotType == SlotTypes.OpenFilter)
            {
                _description += "   Open a long position when " + indicator.EntryFilterLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Open a short position when " + indicator.EntryFilterShortDescription + ".";
            }
            else if (SlotType == SlotTypes.Close)
            {
                _description += "   Close a long position " + indicator.ExitPointLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Close a short position " + indicator.ExitPointShortDescription + ".";
            }
            else
            {
                _description += "   Close a long position when " + indicator.ExitFilterLongDescription + "." +
                                Environment.NewLine + Environment.NewLine;
                _description += "Short position:" + Environment.NewLine;
                _description += "   Close a short position when " + indicator.ExitFilterShortDescription + ".";
            }

            for (int i = 0; i < 2; i++)
                if (indicator.IndParam.CheckParam[i].Caption == "Use previous bar value")
                    _description += Environment.NewLine + "-------------" + Environment.NewLine + "* Use the value of " +
                                    indicator.IndicatorName + " from the previous bar.";

            _toolTip.SetToolTip(LblIndicatorInfo, _description);
        }
        /// <summary>
        /// Tests general parameters of a custom indicator.
        /// </summary>
        /// <returns>True, if the test succeed.</returns>
        public static bool CustomIndicatorFastTest(Indicator indicator, out string errorList)
        {
            bool isOk = true;

            var sb = new StringBuilder();

            sb.AppendLine("ERROR: Indicator test failed for the '" + indicator.IndicatorName + "' indicator.");

            // Tests the IndicatorName property.
            if (string.IsNullOrEmpty(indicator.IndicatorName))
            {
                sb.AppendLine("\tThe property 'IndicatorName' is not set.");
                isOk = false;
            }

            // Tests the PossibleSlots property.
            if (!indicator.TestPossibleSlot(SlotTypes.Open) &&
                !indicator.TestPossibleSlot(SlotTypes.OpenFilter) &&
                !indicator.TestPossibleSlot(SlotTypes.Close) &&
                !indicator.TestPossibleSlot(SlotTypes.CloseFilter))
            {
                sb.AppendLine("\tThe property 'PossibleSlots' is not set.");
                isOk = false;
            }

            // Tests the CustomIndicator property.
            if (!indicator.CustomIndicator)
            {
                sb.AppendLine("\tThe indicator '" + indicator.IndicatorName +
                              "' is not marked as custom. Set CustomIndicator = true;");
                isOk = false;
            }

            // Tests the SeparatedChartMaxValue properties.
            if (!indicator.SeparatedChart && indicator.SeparatedChartMaxValue != double.MinValue)
            {
                sb.AppendLine("\tSet SeparatedChart = true; or remove the property: SeparatedChartMaxValue = " +
                              indicator.SeparatedChartMaxValue.ToString(CultureInfo.InvariantCulture));
                isOk = false;
            }

            // Tests the SeparatedChartMinValue properties.
            if (!indicator.SeparatedChart && indicator.SeparatedChartMinValue != double.MaxValue)
            {
                sb.AppendLine("\tSet SeparatedChart = true; or remove the property: SeparatedChartMinValue = " +
                              indicator.SeparatedChartMinValue.ToString(CultureInfo.InvariantCulture));
                isOk = false;
            }

            // Tests the SpecialValues properties.
            if (!indicator.SeparatedChart && indicator.SpecialValues.Length > 0)
            {
                sb.AppendLine("\tSet SeparatedChart = true; or remove the property SpecialValues");
                isOk = false;
            }

            // Tests the IndParam properties.
            if (indicator.IndParam == null)
            {
                sb.AppendLine("\tThe property IndParam is not set. Set IndParam = new IndicatorParam();");
                isOk = false;
            }

            // Tests the IndParam.IndicatorName properties.
            if (indicator.IndParam.IndicatorName != indicator.IndicatorName)
            {
                sb.AppendLine(
                    "\tThe property IndParam.IndicatorName is not set. Set IndParam.IndicatorName = IndicatorName;");
                isOk = false;
            }

            // Tests the IndParam.SlotType properties.
            if (indicator.IndParam.SlotType != SlotTypes.NotDefined)
            {
                sb.AppendLine("\tThe property IndParam.SlotType is not set. Set IndParam.SlotType = slotType;");
                isOk = false;
            }

            // Tests the IndParam.ListParam properties.
            for (int iParam = 0; iParam < indicator.IndParam.ListParam.Length; iParam++)
            {
                ListParam listParam = indicator.IndParam.ListParam[iParam];
                if (!listParam.Enabled)
                    continue;

                if (string.IsNullOrEmpty(listParam.Caption))
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].Caption is not set.");
                    isOk = false;
                }

                if (listParam.ItemList.Length == 0)
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].ItemList is not set.");
                    isOk = false;
                }

                if (listParam.ItemList[listParam.Index] != listParam.Text)
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].Text is wrong." +
                                  " Set " + "IndParam.ListParam[" + iParam + "].Text = IndParam.ListParam[" + iParam +
                                  "].ItemList[IndParam.ListParam[" + iParam + "].Index];");
                    isOk = false;
                }

                if (string.IsNullOrEmpty(listParam.ToolTip))
                {
                    sb.AppendLine("\tThe property IndParam.ListParam[" + iParam + "].ToolTip is not set.");
                    isOk = false;
                }
            }

            // Tests the IndParam.NumParam properties.
            for (int param = 0; param < indicator.IndParam.NumParam.Length; param++)
            {
                NumericParam numParam = indicator.IndParam.NumParam[param];
                if (!numParam.Enabled)
                    continue;

                if (string.IsNullOrEmpty(numParam.Caption))
                {
                    sb.AppendLine("\tThe property IndParam.NumParam[" + param + "].Caption is not set.");
                    isOk = false;
                }

                double value = numParam.Value;
                double min = numParam.Min;
                double max = numParam.Max;
                double point = numParam.Point;

                if (min > max)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Min > IndParam.NumParam[" + param + "].Max.");
                    isOk = false;
                }

                if (value > max)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Value > IndParam.NumParam[" + param + "].Max.");
                    isOk = false;
                }

                if (value < min)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Value < IndParam.NumParam[" + param + "].Min.");
                    isOk = false;
                }

                if (point < 0)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Point cannot be < 0");
                    isOk = false;
                }

                if (point > 6)
                {
                    sb.AppendLine("\tIndParam.NumParam[" + param + "].Point cannot be > 6");
                    isOk = false;
                }

                if (string.IsNullOrEmpty(numParam.ToolTip))
                {
                    sb.AppendLine("\tThe property IndParam.NumParam[" + param + "].ToolTip is not set.");
                    isOk = false;
                }
            }

            // Tests the IndParam.CheckParam properties.
            for (int param = 0; param < indicator.IndParam.CheckParam.Length; param++)
            {
                CheckParam checkParam = indicator.IndParam.CheckParam[param];
                if (!checkParam.Enabled)
                    continue;

                if (string.IsNullOrEmpty(checkParam.Caption))
                {
                    sb.AppendLine("\tThe property IndParam.CheckParam[" + param + "].Caption is not set.");
                    isOk = false;
                }

                if (string.IsNullOrEmpty(checkParam.ToolTip))
                {
                    sb.AppendLine("\tThe property IndParam.CheckParam[" + param + "].ToolTip is not set.");
                    isOk = false;
                }
            }

            try
            {
                indicator.Calculate(SlotTypes.NotDefined);
            }
            catch (Exception exc)
            {
                sb.AppendLine("\tError when executing Calculate(SlotTypes.NotDefined). " + exc.Message);
                isOk = false;
            }

            try
            {
                indicator.SetDescription(SlotTypes.NotDefined);
            }
            catch (Exception exc)
            {
                sb.AppendLine("\tError when executing SetDescription(SlotTypes.NotDefined). " + exc.Message);
                isOk = false;
            }

            try
            {
                indicator.ToString();
            }
            catch (Exception exc)
            {
                sb.AppendLine("\tError when executing ToString(). " + exc.Message);
                isOk = false;
            }

            errorList = isOk ? string.Empty : sb.ToString();

            return isOk;
        }
Example #5
0
        /// <summary>
        /// Generates a HTML report about the closing logic.
        /// </summary>
        StringBuilder ClosingLogicHTMLReport()
        {
            StringBuilder sb = new StringBuilder();

            int    iClosingSlotNmb = Data.Strategy.CloseSlot;
            string sIndicatorName  = Data.Strategy.Slot[iClosingSlotNmb].IndicatorName;

            Indicator indClose = Indicator_Store.ConstructIndicator(sIndicatorName, SlotTypes.Close);

            indClose.IndParam = Data.Strategy.Slot[iClosingSlotNmb].IndParam;
            indClose.SetDescription(SlotTypes.Close);

            bool          bGroups     = false;
            List <string> closegroups = new List <string>();

            if (Data.Strategy.CloseFilters > 0)
            {
                foreach (IndicatorSlot slot in Data.Strategy.Slot)
                {
                    if (slot.SlotType == SlotTypes.CloseFilter)
                    {
                        if (slot.LogicalGroup == "all" && Data.Strategy.CloseFilters > 1)
                        {
                            bGroups = true;
                        }

                        if (closegroups.Contains(slot.LogicalGroup))
                        {
                            bGroups = true;
                        }
                        else if (slot.LogicalGroup != "all")
                        {
                            closegroups.Add(slot.LogicalGroup);
                        }
                    }
                }
            }

            if (closegroups.Count == 0 && Data.Strategy.CloseFilters > 0)
            {
                closegroups.Add("all"); // If all the slots are in "all" group, adds "all" to the list.
            }
            // Long position
            string sColoseLong = "<p>" + Language.T("Close an existing long position") + " " + indClose.ExitPointLongDescription;

            if (Data.Strategy.CloseFilters == 0)
            {
                sColoseLong += ".</p>";
            }
            else if (Data.Strategy.CloseFilters == 1)
            {
                sColoseLong += " " + Language.T("when the following logic condition is satisfied") + ":</p>";
            }
            else if (bGroups)
            {
                sColoseLong += " " + Language.T("when") + ":</p>";
            }
            else
            {
                sColoseLong += " " + Language.T("when at least one of the following logic conditions is satisfied") + ":</p>";
            }

            sb.AppendLine(sColoseLong);

            // Close Filters
            if (Data.Strategy.CloseFilters > 0)
            {
                int groupnumb = 1;
                sb.AppendLine("<ul>");

                foreach (string group in closegroups)
                {
                    if (bGroups)
                    {
                        sb.AppendLine("<li>" + (groupnumb == 1 ? "" : Language.T("or") + " ") + Language.T("logical group [#] is satisfied").Replace("#", group) + ":");
                        sb.AppendLine("<ul>");
                        groupnumb++;
                    }

                    int indInGroup = 0;
                    for (int iSlot = iClosingSlotNmb + 1; iSlot < Data.Strategy.Slots; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup == group || Data.Strategy.Slot[iSlot].LogicalGroup == "all")
                        {
                            indInGroup++;
                        }
                    }

                    int indnumb = 1;
                    for (int iSlot = iClosingSlotNmb + 1; iSlot < Data.Strategy.Slots; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup != group && Data.Strategy.Slot[iSlot].LogicalGroup != "all")
                        {
                            continue;
                        }

                        Indicator indCloseFilter = Indicator_Store.ConstructIndicator(Data.Strategy.Slot[iSlot].IndicatorName, SlotTypes.CloseFilter);
                        indCloseFilter.IndParam = Data.Strategy.Slot[iSlot].IndParam;
                        indCloseFilter.SetDescription(SlotTypes.CloseFilter);

                        if (bGroups)
                        {
                            if (indnumb < indInGroup)
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterLongDescription + "; " + Language.T("and") + "</li>");
                            }
                            else
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterLongDescription + ".</li>");
                            }
                        }
                        else
                        {
                            if (iSlot < Data.Strategy.Slots - 1)
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterLongDescription + "; " + Language.T("or") + "</li>");
                            }
                            else
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterLongDescription + ".</li>");
                            }
                        }
                        indnumb++;
                    }

                    if (bGroups)
                    {
                        sb.AppendLine("</ul>");
                        sb.AppendLine("</li>");
                    }
                }

                sb.AppendLine("</ul>");
            }

            // Short position
            string sColoseShort = "<p>" + Language.T("Close an existing short position") + " " + indClose.ExitPointShortDescription;

            if (Data.Strategy.CloseFilters == 0)
            {
                sColoseShort += ".</p>";
            }
            else if (Data.Strategy.CloseFilters == 1)
            {
                sColoseShort += " " + Language.T("when the following logic condition is satisfied") + ":</p>";
            }
            else if (bGroups)
            {
                sColoseShort += " " + Language.T("when") + ":</p>";
            }
            else
            {
                sColoseShort += " " + Language.T("when at least one of the following logic conditions is satisfied") + ":</p>";
            }

            sb.AppendLine(sColoseShort);

            // Close Filters
            if (Data.Strategy.CloseFilters > 0)
            {
                int groupnumb = 1;
                sb.AppendLine("<ul>");

                foreach (string group in closegroups)
                {
                    if (bGroups)
                    {
                        sb.AppendLine("<li>" + (groupnumb == 1 ? "" : Language.T("or") + " ") + Language.T("logical group [#] is satisfied").Replace("#", group) + ":");
                        sb.AppendLine("<ul>");
                        groupnumb++;
                    }

                    int indInGroup = 0;
                    for (int iSlot = iClosingSlotNmb + 1; iSlot < Data.Strategy.Slots; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup == group || Data.Strategy.Slot[iSlot].LogicalGroup == "all")
                        {
                            indInGroup++;
                        }
                    }

                    int indnumb = 1;
                    for (int iSlot = iClosingSlotNmb + 1; iSlot < Data.Strategy.Slots; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup != group && Data.Strategy.Slot[iSlot].LogicalGroup != "all")
                        {
                            continue;
                        }

                        Indicator indCloseFilter = Indicator_Store.ConstructIndicator(Data.Strategy.Slot[iSlot].IndicatorName, SlotTypes.CloseFilter);
                        indCloseFilter.IndParam = Data.Strategy.Slot[iSlot].IndParam;
                        indCloseFilter.SetDescription(SlotTypes.CloseFilter);

                        if (bGroups)
                        {
                            if (indnumb < indInGroup)
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterShortDescription + "; " + Language.T("and") + "</li>");
                            }
                            else
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterShortDescription + ".</li>");
                            }
                        }
                        else
                        {
                            if (iSlot < Data.Strategy.Slots - 1)
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterShortDescription + "; " + Language.T("or") + "</li>");
                            }
                            else
                            {
                                sb.AppendLine("<li>" + indCloseFilter.ExitFilterShortDescription + ".</li>");
                            }
                        }
                        indnumb++;
                    }

                    if (bGroups)
                    {
                        sb.AppendLine("</ul>");
                        sb.AppendLine("</li>");
                    }
                }

                sb.AppendLine("</ul>");
            }

            return(sb);
        }
Example #6
0
        /// <summary>
        /// Generates a HTML report about the opening logic.
        /// </summary>
        StringBuilder OpeningLogicHTMLReport()
        {
            StringBuilder sb             = new StringBuilder();
            string        sIndicatorName = Data.Strategy.Slot[0].IndicatorName;

            Indicator indOpen = Indicator_Store.ConstructIndicator(sIndicatorName, SlotTypes.Open);

            indOpen.IndParam = Data.Strategy.Slot[0].IndParam;
            indOpen.SetDescription(SlotTypes.Open);

            // Logical groups of the opening conditions.
            List <string> opengroups = new List <string>();

            for (int iSlot = 1; iSlot <= Data.Strategy.OpenFilters; iSlot++)
            {
                string group = Data.Strategy.Slot[iSlot].LogicalGroup;
                if (!opengroups.Contains(group) && group != "All")
                {
                    opengroups.Add(group); // Adds all groups except "All"
                }
            }
            if (opengroups.Count == 0 && Data.Strategy.OpenFilters > 0)
            {
                opengroups.Add("All"); // If all the slots are in "All" group, adds "All" to the list.
            }
            // Long position
            string sOpenLong = "<p>";

            if (Data.Strategy.sameDirSignlAct == SameDirSignalAction.Add)
            {
                sOpenLong = Language.T("Open a new long position or add to an existing position");
            }
            else if (Data.Strategy.sameDirSignlAct == SameDirSignalAction.Winner)
            {
                sOpenLong = Language.T("Open a new long position or add to a winning position");
            }
            else if (Data.Strategy.sameDirSignlAct == SameDirSignalAction.Nothing)
            {
                sOpenLong = Language.T("Open a new long position");
            }

            if (OppSignalAction == OppositeDirSignalAction.Close)
            {
                sOpenLong += " " + Language.T("or close a short position");
            }
            else if (OppSignalAction == OppositeDirSignalAction.Reduce)
            {
                sOpenLong += " " + Language.T("or reduce a short position");
            }
            else if (OppSignalAction == OppositeDirSignalAction.Reverse)
            {
                sOpenLong += " " + Language.T("or reverse a short position");
            }
            else if (OppSignalAction == OppositeDirSignalAction.Nothing)
            {
                sOpenLong += "";
            }

            sOpenLong += " " + indOpen.EntryPointLongDescription;

            if (Data.Strategy.OpenFilters == 0)
            {
                sOpenLong += ".</p>";
            }
            else if (Data.Strategy.OpenFilters == 1)
            {
                sOpenLong += " " + Language.T("when the following logic condition is satisfied") + ":</p>";
            }
            else if (opengroups.Count > 1)
            {
                sOpenLong += " " + Language.T("when") + ":</p>";
            }
            else
            {
                sOpenLong += " " + Language.T("when all the following logic conditions are satisfied") + ":</p>";
            }

            sb.AppendLine(sOpenLong);

            // Open Filters
            if (Data.Strategy.OpenFilters > 0)
            {
                int groupnumb = 1;
                if (opengroups.Count > 1)
                {
                    sb.AppendLine("<ul>");
                }

                foreach (string group in opengroups)
                {
                    if (opengroups.Count > 1)
                    {
                        sb.AppendLine("<li>" + (groupnumb == 1 ? "" : Language.T("or") + " ") + Language.T("logical group [#] is satisfied").Replace("#", group) + ":");
                        groupnumb++;
                    }

                    sb.AppendLine("<ul>");
                    int indInGroup = 0;
                    for (int iSlot = 1; iSlot <= Data.Strategy.OpenFilters; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup == group || Data.Strategy.Slot[iSlot].LogicalGroup == "All")
                        {
                            indInGroup++;
                        }
                    }

                    int indnumb = 1;
                    for (int iSlot = 1; iSlot <= Data.Strategy.OpenFilters; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup != group && Data.Strategy.Slot[iSlot].LogicalGroup != "All")
                        {
                            continue;
                        }

                        Indicator indOpenFilter = Indicator_Store.ConstructIndicator(Data.Strategy.Slot[iSlot].IndicatorName, SlotTypes.OpenFilter);
                        indOpenFilter.IndParam = Data.Strategy.Slot[iSlot].IndParam;
                        indOpenFilter.SetDescription(SlotTypes.OpenFilter);

                        if (indnumb < indInGroup)
                        {
                            sb.AppendLine("<li>" + indOpenFilter.EntryFilterLongDescription + "; " + Language.T("and") + "</li>");
                        }
                        else
                        {
                            sb.AppendLine("<li>" + indOpenFilter.EntryFilterLongDescription + ".</li>");
                        }

                        indnumb++;
                    }
                    sb.AppendLine("</ul>");

                    if (opengroups.Count > 1)
                    {
                        sb.AppendLine("</li>");
                    }
                }

                if (opengroups.Count > 1)
                {
                    sb.AppendLine("</ul>");
                }
            }

            // Short position
            string sOpenShort = "<p>";

            if (Data.Strategy.sameDirSignlAct == SameDirSignalAction.Add)
            {
                sOpenShort = Language.T("Open a new short position or add to an existing position");
            }
            else if (Data.Strategy.sameDirSignlAct == SameDirSignalAction.Winner)
            {
                sOpenShort = Language.T("Open a new short position or add to a winning position");
            }
            else if (Data.Strategy.sameDirSignlAct == SameDirSignalAction.Nothing)
            {
                sOpenShort = Language.T("Open a new short position");
            }

            if (OppSignalAction == OppositeDirSignalAction.Close)
            {
                sOpenShort += " " + Language.T("or close a long position");
            }
            else if (OppSignalAction == OppositeDirSignalAction.Reduce)
            {
                sOpenShort += " " + Language.T("or reduce a long position");
            }
            else if (OppSignalAction == OppositeDirSignalAction.Reverse)
            {
                sOpenShort += " " + Language.T("or reverse a long position");
            }
            else if (OppSignalAction == OppositeDirSignalAction.Nothing)
            {
                sOpenShort += "";
            }

            sOpenShort += " " + indOpen.EntryPointShortDescription;

            if (Data.Strategy.OpenFilters == 0)
            {
                sOpenShort += ".</p>";
            }
            else if (Data.Strategy.OpenFilters == 1)
            {
                sOpenShort += " " + Language.T("when the following logic condition is satisfied") + ":</p>";
            }
            else if (opengroups.Count > 1)
            {
                sOpenShort += " " + Language.T("when") + ":</p>";
            }
            else
            {
                sOpenShort += " " + Language.T("when all the following logic conditions are satisfied") + ":</p>";
            }

            sb.AppendLine(sOpenShort);

            // Open Filters
            if (Data.Strategy.OpenFilters > 0)
            {
                int groupnumb = 1;
                if (opengroups.Count > 1)
                {
                    sb.AppendLine("<ul>");
                }

                foreach (string group in opengroups)
                {
                    if (opengroups.Count > 1)
                    {
                        sb.AppendLine("<li>" + (groupnumb == 1 ? "" : Language.T("or") + " ") + Language.T("logical group [#] is satisfied").Replace("#", group) + ":");
                        groupnumb++;
                    }

                    sb.AppendLine("<ul>");
                    int indInGroup = 0;
                    for (int iSlot = 1; iSlot <= Data.Strategy.OpenFilters; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup == group || Data.Strategy.Slot[iSlot].LogicalGroup == "All")
                        {
                            indInGroup++;
                        }
                    }

                    int indnumb = 1;
                    for (int iSlot = 1; iSlot <= Data.Strategy.OpenFilters; iSlot++)
                    {
                        if (Data.Strategy.Slot[iSlot].LogicalGroup != group && Data.Strategy.Slot[iSlot].LogicalGroup != "All")
                        {
                            continue;
                        }

                        Indicator indOpenFilter = Indicator_Store.ConstructIndicator(Data.Strategy.Slot[iSlot].IndicatorName, SlotTypes.OpenFilter);
                        indOpenFilter.IndParam = Data.Strategy.Slot[iSlot].IndParam;
                        indOpenFilter.SetDescription(SlotTypes.OpenFilter);

                        if (indnumb < indInGroup)
                        {
                            sb.AppendLine("<li>" + indOpenFilter.EntryFilterShortDescription + "; " + Language.T("and") + "</li>");
                        }
                        else
                        {
                            sb.AppendLine("<li>" + indOpenFilter.EntryFilterShortDescription + ".</li>");
                        }

                        indnumb++;
                    }
                    sb.AppendLine("</ul>");

                    if (opengroups.Count > 1)
                    {
                        sb.AppendLine("</li>");
                    }
                }
                if (opengroups.Count > 1)
                {
                    sb.AppendLine("</ul>");
                }
            }

            return(sb);
        }