// Doji Indicator // Last changed on 2010-09-20 // Part of Forex Strategy Builder & Forex Strategy Trader // Website http://forexsb.com/ // Copyright (c) 2006 - 2010 Miroslav Popov - All rights reserved. // This code or any part of it cannot be used in other applications without a permission. using System; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { /// /// Doji Indicator /// public class PinBar : Indicator { /// /// Sets the default indicator parameters for the designated slot type /// public PinBar() { // General properties IndicatorName = "Pin Bar"; PossibleSlots = SlotTypes.OpenFilter; IndicatorAuthor = "Footon"; IndicatorVersion = "2.0"; IndicatorDescription = "A custom indicator for FSB and FST"; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; IndParam.IndicatorType = TypeOfIndicator.IndicatorsMA; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "Long on Pin Bar", "Short on Pin Bar", "Long on inverted Pin Bar", "Short on inverted Pin Bar", }; 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 CheckBox parameters IndParam.CheckParam[0].Caption = "Use previous bar value"; IndParam.CheckParam[0].Enabled = true; IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "PERCENT defining doji"; IndParam.NumParam[0].Value = 8; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 100; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "Percent body of the candle."; IndParam.NumParam[1].Caption = "PERCENT defining pin bar"; IndParam.NumParam[1].Value = 30; IndParam.NumParam[1].Min = 1; IndParam.NumParam[1].Max = 100; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "PERCENT defining pin bar"; return; } /// /// Calculates the indicator's components /// public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int iPERCENT = (int)IndParam.NumParam[0].Value; int iPERCENTpb = (int)IndParam.NumParam[1].Value; // Calculation int iFirstBar = 1; double[] doji = new double[Bars]; double[] buy = new double[Bars]; double[] sell = new double[Bars]; double point = (Digits == 5 || Digits == 3) ? 10 * Point : Point; for (int iBar = 1; iBar < Bars; iBar++) { if (Math.Abs(Close[iBar - 1] - Open[iBar - 1]) < iPERCENT * 0.01 * (High[iBar - 1] - Low[iBar - 1])) doji[iBar] = 1; if (doji[iBar] == 1) { if (IndParam.ListParam[0].Text == "Long on Pin Bar") { if (Math.Abs(Close[iBar - 1] - High[iBar - 1]) <= iPERCENTpb * 0.01 * (High[iBar - 1] - Low[iBar - 1])) buy[iBar] = 1; } if (IndParam.ListParam[0].Text == "Short on Pin Bar") { if (Math.Abs(Close[iBar - 1] - High[iBar - 1]) <= iPERCENTpb * 0.01 * (High[iBar - 1] - Low[iBar - 1])) sell[iBar] = 1; } //------------------------------------------------------------------------------------------------------------------------------------ if (IndParam.ListParam[0].Text == "Long on inverted Pin Bar") { if (Math.Abs(Close[iBar - 1] - Low[iBar - 1]) <= iPERCENTpb * 0.01 * (High[iBar - 1] - Low[iBar - 1])) buy[iBar] = 1; } if (IndParam.ListParam[0].Text == "Short on inverted Pin Bar") { if (Math.Abs(Close[iBar - 1] - Low[iBar - 1]) <= iPERCENTpb * 0.01 * (High[iBar - 1] - Low[iBar - 1])) sell[iBar] = 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 = iFirstBar; Component[0].Value = buy; 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 = sell; return; } /// /// Sets the indicator logic description /// public override void SetDescription() { EntryFilterLongDescription = "there is a PinBar formation"; EntryFilterShortDescription = "there is a PinBar formation"; return; } /// /// Indicator to string /// public override string ToString() { string sString = IndicatorName; return sString; } } }