//============================================================== // Forex Strategy Builder // Copyright Р’В© Miroslav Popov. All rights reserved. //============================================================== // THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. //============================================================== using System; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class SpreadLevelPro : Indicator { public SpreadLevelPro() { IndicatorName = "Spread Level Pro"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; IsDeafultGroupAll = true; IsGeneratable = false; WarningMessage = "The indicator works properly only on Trader mode."; IndicatorAuthor = "Popov"; IndicatorVersion = "2.2"; IndicatorDescription = "A custom indicator for FST. Based on Footon's Spread Limiter"; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; IndParam.IndicatorType = TypeOfIndicator.Additional; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new[] { "Spread is lower than the selected level", "Spread is higher than the selected level" }; IndParam.ListParam[0].Index = 0; IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index]; IndParam.ListParam[0].Enabled = true; IndParam.ListParam[0].ToolTip = "Indicator's logic."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Spread level in points"; IndParam.NumParam[0].Value = 20; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 500; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "Spread in points."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters double spreadLevel = IndParam.NumParam[0].Value; // Calculation const int firstBar = 1; double spread = IsBacktester ? DataSet.Properties.Spread : (DataSet.Ask - DataSet.Bid)/Point; var spr = new double[Bars]; var showspread = new double[Bars]; switch (IndParam.ListParam[0].Text) { case "Spread is lower than the selected level": if (spread < spreadLevel - Epsilon) for (int bar = 1; bar < Bars; bar++) spr[bar] = 1; break; case "Spread is higher than the selected level": if (spread > spreadLevel + Epsilon) for (int bar = 1; bar < Bars; bar++) spr[bar] = 1; break; } for (int bar = 1; bar < Bars; bar++) showspread[bar] = spread; Component = SlotType == SlotTypes.OpenFilter ? new IndicatorComp[3] : new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Spread", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = showspread }; if (SlotType == SlotTypes.OpenFilter) { Component[1] = new IndicatorComp { CompName = "Is long entry allowed", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = spr }; Component[2] = new IndicatorComp { CompName = "Is short entry allowed", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = spr }; } else if (SlotType == SlotTypes.CloseFilter) { Component[1] = new IndicatorComp { CompName = "Force close", DataType = IndComponentType.ForceClose, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = spr }; } } public override void SetDescription() { var spreadLevel = IndParam.NumParam[0].Value.ToString("F1"); switch (IndParam.ListParam[0].Text) { case "Spread is lower than the selected level": var lowerThan = "Spread is lower than " + spreadLevel; EntryFilterLongDescription = lowerThan; EntryFilterShortDescription = lowerThan; ExitFilterLongDescription = lowerThan; ExitFilterShortDescription = lowerThan; break; case "Spread is higher than the selected level": var higherThan = "Spread is higher than " + spreadLevel; EntryFilterLongDescription = higherThan; EntryFilterShortDescription = higherThan; ExitFilterLongDescription = higherThan; ExitFilterShortDescription = higherThan; break; } } public override string ToString() { return IndicatorName; } } }