Ergodic Indicator by zuijaideai
4473 downloads / 4306 views / Created: 23.05.2013




Average Rating: 0
Indicator Description
Hi All,
I posted a new indicator called Ergodic Indicator, sometimes recognized as True Strength Index indicator. This indicator is a variation of the Relative Strength Index, developed by William Blau, it uses a differencing function to measure momentum and an averaging function to correlate the momentum to the price trend. In other words, the indicator combines the leading characteristic of a differencing momentum calculation with the lagging characteristic of an averaging function to create an indicator that reflects price direction and is in sync with market turns.

Forum link: Ergodic Indicator
Rgds
Denny Imanuel
imanuel.denny@gmail.com
I posted a new indicator called Ergodic Indicator, sometimes recognized as True Strength Index indicator. This indicator is a variation of the Relative Strength Index, developed by William Blau, it uses a differencing function to measure momentum and an averaging function to correlate the momentum to the price trend. In other words, the indicator combines the leading characteristic of a differencing momentum calculation with the lagging characteristic of an averaging function to create an indicator that reflects price direction and is in sync with market turns.

Forum link: Ergodic Indicator
Rgds
Denny Imanuel
imanuel.denny@gmail.com
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
//==============================================================
// 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 ErgodicIndicator : Indicator
{
public ErgodicIndicator()
{
IndicatorName = "Ergodic Indicator";
PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
SeparatedChart = true;
IndicatorAuthor = "Denny Imanuel";
IndicatorVersion = "2.1";
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[]
{
"The Ergodic line rises",
"The Ergodic line falls",
"The Ergodic line is higher than zero",
"The Ergodic line is lower than zero",
"The Ergodic line crosses the zero line upward",
"The Ergodic line crosses the zero line downward",
"The Ergodic line changes its direction upward",
"The Ergodic line changes its direction downward",
"The Ergodic line crosses the Signal line upward",
"The Ergodic line crosses the Signal line downward",
"The Ergodic line is higher than the Signal line",
"The Ergodic line is lower than the Signal line"
};
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.";
IndParam.ListParam[1].Caption = "Smoothing method";
IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
IndParam.ListParam[1].Index = (int)MAMethod.Exponential;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "The smoothing method of Moving Average.";
IndParam.ListParam[2].Caption = "Base price";
IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
IndParam.ListParam[2].Index = (int)BasePrice.Close;
IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
IndParam.ListParam[2].Enabled = true;
IndParam.ListParam[2].ToolTip = "The price the Moving Average is based on.";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "R Parameter";
IndParam.NumParam[0].Value = 7;
IndParam.NumParam[0].Min = 1;
IndParam.NumParam[0].Max = 200;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The period of first Exponential MA.";
IndParam.NumParam[1].Caption = "S Parameter";
IndParam.NumParam[1].Value = 27;
IndParam.NumParam[1].Min = 1;
IndParam.NumParam[1].Max = 200;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "The period of second Exponential MA.";
IndParam.NumParam[2].Caption = "U Parameter";
IndParam.NumParam[2].Value = 1;
IndParam.NumParam[2].Min = 1;
IndParam.NumParam[2].Max = 200;
IndParam.NumParam[2].Enabled = true;
IndParam.NumParam[2].ToolTip = "The period of third Exponential MA.";
IndParam.NumParam[3].Caption = "Smoothing Length";
IndParam.NumParam[3].Value = 7;
IndParam.NumParam[3].Min = 1;
IndParam.NumParam[3].Max = 200;
IndParam.NumParam[3].Enabled = true;
IndParam.NumParam[3].ToolTip = "The period of Smoothing MA.";
// 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
MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index;
BasePrice price = (BasePrice)IndParam.ListParam[2].Index;
int iR = (int)IndParam.NumParam[0].Value;
int iS = (int)IndParam.NumParam[1].Value;
int iU = (int)IndParam.NumParam[2].Value;
int iSmtLen = (int)IndParam.NumParam[3].Value;
int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;
// Calculation
int iFirstBar = Math.Max(Math.Max(iR,iS),Math.Max(iU,iSmtLen)) + 10;
double[] adPrice = Price(price);
double[] adErgodic = new double[Bars];
double[] adErgodicSig = new double[Bars];
double[] adPriceMov = new double[Bars];
double[] adAbsPriceMov = new double[Bars];
double[] adNum = new double[Bars];
double[] adDen = new double[Bars];
for (int iBar = 1; iBar < Bars; iBar++)
{
adPriceMov[iBar] = adPrice[iBar]-adPrice[iBar-1];
adAbsPriceMov[iBar] = Math.Abs(adPriceMov[iBar]);
}
adNum = TripleMovingAverage(iR, iS, iU, 0, maMethod, adPriceMov);
adDen = TripleMovingAverage(iR, iS, iU, 0, maMethod, adAbsPriceMov);
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
if (adDen[iBar]!=0)
adErgodic[iBar] = 100*adNum[iBar]/adDen[iBar];
else
adErgodic[iBar] = 0;
}
adErgodicSig = MovingAverage(iSmtLen, 0, maMethod, adErgodic);
// Saving the components
Component = new IndicatorComp[4];
Component[0] = new IndicatorComp();
Component[0].CompName = "Ergodic Line";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Line;
Component[0].ChartColor = Color.Purple;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adErgodic;
Component[1] = new IndicatorComp();
Component[1].CompName = "Signal line";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Line;
Component[1].ChartColor = Color.Pink;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adErgodicSig;
Component[2] = new IndicatorComp();
Component[2].ChartType = IndChartType.NoChart;
Component[2].FirstBar = iFirstBar;
Component[2].Value = new double[Bars];
Component[3] = new IndicatorComp();
Component[3].ChartType = IndChartType.NoChart;
Component[3].FirstBar = iFirstBar;
Component[3].Value = new double[Bars];
// Sets the Component's type
if (SlotType == SlotTypes.OpenFilter)
{
Component[2].DataType = IndComponentType.AllowOpenLong;
Component[2].CompName = "Is long entry allowed";
Component[3].DataType = IndComponentType.AllowOpenShort;
Component[3].CompName = "Is short entry allowed";
}
else if (SlotType == SlotTypes.CloseFilter)
{
Component[2].DataType = IndComponentType.ForceCloseLong;
Component[2].CompName = "Close out long position";
Component[3].DataType = IndComponentType.ForceCloseShort;
Component[3].CompName = "Close out short position";
}
switch (IndParam.ListParam[0].Text)
{
case "The Ergodic line rises":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises);
break;
case "The Ergodic line falls":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls);
break;
case "The Ergodic line is higher than zero":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_higher_than_the_level_line);
break;
case "The Ergodic line is lower than zero":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_lower_than_the_level_line);
break;
case "The Ergodic line crosses the zero line upward":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_upward);
break;
case "The Ergodic line crosses the zero line downward":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_downward);
break;
case "The Ergodic line changes its direction upward":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward);
break;
case "The Ergodic line changes its direction downward":
OscillatorLogic(iFirstBar, iPrvs, adErgodic, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward);
break;
case "The Ergodic line crosses the Signal line upward":
IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adErgodic, adErgodicSig, ref Component[2], ref Component[3]);
break;
case "The Ergodic line crosses the Signal line downward":
IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adErgodic, adErgodicSig, ref Component[2], ref Component[3]);
break;
case "The Ergodic line is higher than the Signal line":
IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adErgodic, adErgodicSig, ref Component[2], ref Component[3]);
break;
case "The Ergodic line is lower than the Signal line":
IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar, iPrvs, adErgodic, adErgodicSig, ref Component[2], ref Component[3]);
break;
}
}
public override void SetDescription()
{
EntryFilterLongDescription = ToString() + "; the Ergodic line ";
EntryFilterShortDescription = ToString() + "; the Ergodic line ";
ExitFilterLongDescription = ToString() + "; the Ergodic line ";
ExitFilterShortDescription = ToString() + "; the Ergodic line ";
switch (IndParam.ListParam[0].Text)
{
case "The Ergodic line rises":
EntryFilterLongDescription += "rises";
EntryFilterShortDescription += "falls";
ExitFilterLongDescription += "rises";
ExitFilterShortDescription += "falls";
break;
case "The Ergodic line falls":
EntryFilterLongDescription += "falls";
EntryFilterShortDescription += "rises";
ExitFilterLongDescription += "falls";
ExitFilterShortDescription += "rises";
break;
case "The Ergodic line is higher than zero":
EntryFilterLongDescription += "is higher than the zero line";
EntryFilterShortDescription += "is lower than the zero line";
ExitFilterLongDescription += "is higher than the zero line";
ExitFilterShortDescription += "is lower than the zero line";
break;
case "The Ergodic line is lower than zero":
EntryFilterLongDescription += "is lower than the zero line";
EntryFilterShortDescription += "is higher than the zero line";
ExitFilterLongDescription += "is lower than the zero line";
ExitFilterShortDescription += "is higher than the zero line";
break;
case "The Ergodic line crosses the zero line upward":
EntryFilterLongDescription += "crosses the zero line upward";
EntryFilterShortDescription += "crosses the zero line downward";
ExitFilterLongDescription += "crosses the zero line upward";
ExitFilterShortDescription += "crosses the zero line downward";
break;
case "The Ergodic line crosses the zero line downward":
EntryFilterLongDescription += "crosses the zero line downward";
EntryFilterShortDescription += "crosses the zero line upward";
ExitFilterLongDescription += "crosses the zero line downward";
ExitFilterShortDescription += "crosses the zero line upward";
break;
case "The Ergodic line changes its direction upward":
EntryFilterLongDescription += "changes its direction upward";
EntryFilterShortDescription += "changes its direction downward";
ExitFilterLongDescription += "changes its direction upward";
ExitFilterShortDescription += "changes its direction downward";
break;
case "The Ergodic line changes its direction downward":
EntryFilterLongDescription += "changes its direction downward";
EntryFilterShortDescription += "changes its direction upward";
ExitFilterLongDescription += "changes its direction downward";
ExitFilterShortDescription += "changes its direction upward";
break;
case "The Ergodic line is higher than the Signal line":
EntryFilterLongDescription += "is higher than the Signal line";
EntryFilterShortDescription += "is lower than the Signal line";
ExitFilterLongDescription += "is higher than the Signal line";
ExitFilterShortDescription += "is lower than the Signal line";
break;
case "The Ergodic line is lower than the Signal line":
EntryFilterLongDescription += "is lower than the Signal line";
EntryFilterShortDescription += "is higher than the Signal line";
ExitFilterLongDescription += "is lower than the Signal line";
ExitFilterShortDescription += "is higher than the Signal line";
break;
case "The Ergodic line crosses the Signal line upward":
EntryFilterLongDescription += "crosses the Signal line upward";
EntryFilterShortDescription += "crosses the Signal line downward";
ExitFilterLongDescription += "crosses the Signal line upward";
ExitFilterShortDescription += "crosses the Signal line downward";
break;
case "The Ergodic line crosses the Signal line downward":
EntryFilterLongDescription += "crosses the Signal line downward";
EntryFilterShortDescription += "crosses the Signal line upward";
ExitFilterLongDescription += "crosses the Signal line downward";
ExitFilterShortDescription += "crosses the Signal line upward";
break;
}
}
public override string ToString()
{
return IndicatorName +
(IndParam.CheckParam[0].Checked ? "* (" : " (") +
IndParam.NumParam[0].ValueToString + ")"; // Ergodic period
}
protected double[] TripleMovingAverage(int iR, int iS, int iU, int iShift, MAMethod maMethod, double[] adPrice)
{
double[] adSingleMA = new double[Bars];
double[] adDoubleMA = new double[Bars];
double[] adTripleMA = new double[Bars];
adSingleMA = MovingAverage(iR, iShift, maMethod, adPrice);
adDoubleMA = MovingAverage(iS, iShift, maMethod, adSingleMA);
adTripleMA = MovingAverage(iU, iShift, maMethod, adDoubleMA);
return adTripleMA;
}
}
}
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.;