//============================================================== // 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 InsideBarSun : Indicator { public InsideBarSun() { IndicatorName = "Inside Bar Sun"; PossibleSlots = SlotTypes.OpenFilter; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "2.0"; IndicatorDescription = "Merges Sunday bar in Monday."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // Setting up the indicator parameters IndParam.IndicatorType = TypeOfIndicator.DateTime; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "There is an Inside Bar formation", }; 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."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Calculation int iFirstBar = 4; double[] adIB = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (Time[iBar].DayOfWeek == DayOfWeek.Monday && Time[iBar - 1].DayOfWeek == DayOfWeek.Sunday) { // Today is Monday and a Sunday bar exists // Friday double friHigh = High[iBar - 2]; double friLow = Low[iBar - 2]; // Thursday double thuHigh = High[iBar - 3]; double thuLow = Low[iBar - 3]; adIB[iBar] = (friHigh < thuHigh && friLow > thuLow) ? 1 : 0; } else if (Time[iBar].DayOfWeek == DayOfWeek.Tuesday && Time[iBar - 2].DayOfWeek == DayOfWeek.Sunday) { // Today is Tuesday and a Sunday bar exists. // Monday high and low include eventual Sunday extreme. double monLow = Math.Min(Low[iBar - 1], Low[iBar - 2]); double monHigh = Math.Max(High[iBar - 1], High[iBar - 2]); // Friday double friHigh = High[iBar - 3]; double friLow = Low[iBar - 3]; adIB[iBar] = (monHigh < friHigh && monLow > friLow) ? 1 : 0; } else { adIB[iBar] = (High[iBar - 1] < High[iBar - 2] && Low[iBar - 1] > Low[iBar - 2]) ? 1 : 0; } if (Time[iBar].DayOfWeek == DayOfWeek.Sunday) { // Today is Sunday - no entry adIB[iBar] = 0; } } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = iFirstBar; Component[0].Value = adIB; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = iFirstBar; Component[1].Value = adIB; } public override void SetDescription() { EntryFilterLongDescription = "there is an Inside Bar formation"; EntryFilterShortDescription = "there is an Inside Bar formation"; } public override string ToString() { return IndicatorName; } } }