Candle Direction by ahmedalhoseny
4958 downloads / 5642 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
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
//==============================================================
// 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 - 2025, Forex Software Ltd.;
Copyright © 2006 - 2025, Forex Software Ltd.;