Ergodic Indicator by zuijaideai

3984 downloads / 3845 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.

Ergodic

Forum link: Ergodic Indicator

Rgds
Denny Imanuel
imanuel.denny@gmail.com

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 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 - 2024, Forex Software Ltd.;