Candle Direction by ahmedalhoseny

3903 downloads / 4072 views / Created: 12.06.2015
 Average Rating: 4.5

Indicator Description

It uses all available directions combinations of last two candles for open and close logics
using shift function allow us to use the indicator more than one time if we need to use the direction combinations of more than two candles

Comments

//============================================================== // 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 System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class CandleDirection : Indicator { public CandleDirection() { IndicatorName = "Candle Direction"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; IndicatorAuthor = "ahmedalhoseny@gmail.com"; IndicatorVersion = "2.0"; IndicatorDescription = "Custom Indicator."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; if (SlotType == SlotTypes.OpenFilter) IndParam.ListParam[0].ItemList = new[] { "Up", "Dn", "Up Up", "Up Dn", "Dn Up", "Dn Dn" }; else if (SlotType == SlotTypes.CloseFilter) IndParam.ListParam[0].ItemList = new[] { "Dn Dn", "Dn Up", "Up Dn", "Up Up", "Dn", "Up" }; else IndParam.ListParam[0].ItemList = new[] { "Not Defined" }; 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 Donchian Channel."; IndParam.NumParam[0].Caption = "Shift"; IndParam.NumParam[0].Value = 0; IndParam.NumParam[0].Min = 0; IndParam.NumParam[0].Max = 4; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The number of bars to shift with."; // 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."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iFirstBar = 4 + iPrvs; var iShift = (int)IndParam.NumParam[0].Value; // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].CompName = "Is long entry allowed"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[0].DataType = IndComponentType.ForceCloseLong; Component[0].CompName = "Close out long position"; Component[1].DataType = IndComponentType.ForceCloseShort; Component[1].CompName = "Close out short position"; } switch (IndParam.ListParam[0].Text) { case "Up": for (int iBar = iFirstBar; iBar < Bars - iShift; iBar++) { Component[0].Value[iBar + iShift] = Close[iBar - iPrvs] > Open[iBar - iPrvs] ? 1 : 0; Component[1].Value[iBar + iShift] = Close[iBar - iPrvs] < Open[iBar - iPrvs] ? 1 : 0; } break; case "Dn": for (int iBar = 2; iBar < Bars - iShift; iBar++) { Component[0].Value[iBar + iShift] = Close[iBar - iPrvs] < Open[iBar - iPrvs] ? 1 : 0; Component[1].Value[iBar + iShift] = Close[iBar - iPrvs] > Open[iBar - iPrvs] ? 1 : 0; } break; case "Up Up": for (int iBar = 2; iBar < Bars - iShift; iBar++) { Component[0].Value[iBar + iShift] = Close[iBar - iPrvs] > Open[iBar - iPrvs] && Close[iBar - iPrvs - 1] > Open[iBar - iPrvs - 1] ? 1 : 0; Component[1].Value[iBar + iShift] = Close[iBar - iPrvs] < Open[iBar - iPrvs] && Close[iBar - iPrvs - 1] < Open[iBar - iPrvs - 1] ? 1 : 0; } break; case "Up Dn": for (int iBar = iFirstBar; iBar < Bars - iShift; iBar++) { Component[0].Value[iBar + iShift] = Close[iBar - iPrvs - 1] > Open[iBar - iPrvs - 1] && Close[iBar - iPrvs] < Open[iBar - iPrvs] ? 1 : 0; Component[1].Value[iBar + iShift] = Close[iBar - iPrvs - 1] < Open[iBar - iPrvs - 1] && Close[iBar - iPrvs] > Open[iBar - iPrvs] ? 1 : 0; } break; case "Dn Up": for (int iBar = iFirstBar; iBar < Bars - iShift; iBar++) { Component[0].Value[iBar + iShift] = Close[iBar - iPrvs - 1] < Open[iBar - iPrvs - 1] && Close[iBar - iPrvs] > Open[iBar - iPrvs] ? 1 : 0; Component[1].Value[iBar + iShift] = Close[iBar - iPrvs - 1] > Open[iBar - iPrvs - 1] && Close[iBar - iPrvs] < Open[iBar - iPrvs] ? 1 : 0; } break; case "Dn Dn": for (int iBar = iFirstBar; iBar < Bars - iShift; iBar++) { Component[0].Value[iBar + iShift] = Close[iBar - iPrvs - 1] < Open[iBar - iPrvs - 1] && Close[iBar - iPrvs] < Open[iBar - iPrvs] ? 1 : 0; Component[1].Value[iBar + iShift] = Close[iBar - iPrvs - 1] > Open[iBar - iPrvs - 1] && Close[iBar - iPrvs] > Open[iBar - iPrvs] ? 1 : 0; } break; } } } }
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2024, Forex Software Ltd.;