//============================================================== // Forex Strategy Builder // Copyright (c) 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 System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class ThreeBarsSwing : Indicator { public ThreeBarsSwing() { IndicatorName = "Three Bars Swing"; PossibleSlots = SlotTypes.OpenFilter; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "2.0"; IndicatorDescription = "A custom indicator for FSB and FST."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "Three bars swing pattern" }; 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 = "Logic of application of the indicator."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int firstBar = 4; double[] longSignals = new double[Bars]; double[] shortSignals = new double[Bars]; for (int bar = firstBar; bar < Bars; bar++) { // Long trade if (Close[bar - 3] < Open[bar - 3] && // Candle 1 is black Low[bar - 2] < Low[bar - 3] && // Candle 2 has lower low than candle 1 Close[bar - 1] > Open[bar - 1] && // Candle 3 is white Low[bar - 1] > Low[bar - 2] && // Candle 3 has higher low than candle 2 Close[bar - 1] > Open[bar - 3]) // Candle 3 closes above candle 1 open longSignals[bar] = 1; // Short trade if (Close[bar - 3] > Open[bar - 3] && // Candle 1 is white High[bar - 2] > High[bar - 3] && // Candle 2 has higher high than candle 1 Close[bar - 1] < Open[bar - 1] && // Candle 3 is black High[bar - 1] < High[bar - 2] && // Candle 3 has lower high than candle 2 Close[bar - 1] < Open[bar - 3]) // Candle 3 closes below candle 1 open shortSignals[bar] = 1; } // 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 = firstBar; Component[0].Value = longSignals; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = firstBar; Component[1].Value = shortSignals; } public override void SetDescription() { EntryFilterLongDescription = "there is a Three Bars Swing pattern"; EntryFilterShortDescription = "there is a Three Bars Swing pattern"; } public override string ToString() { return IndicatorName; } } }