using System; using System.Drawing; using System.Collections.Generic; using System.Text; using RightEdge.Common; using RightEdge.Indicators; /* Heikin-Ashi Close * This indicator is taken from "Trading Medium-Term Divergences" by Sylvain Vervoort, page 17, TASC, February 2008. * There are 6 versions of this indicator in this issue of TASC, not all in agreement, and including a typo in the * main article. Best I can tell, this is the most likely one. See pages 10-11, 21 and 80-87. * 1/27/2008 */ namespace HeiAshClose { // Use the Indicator Attribute to provide information such as the // name and description of your indicator. If you do not include // this attribute, your indicator will not show up in the indicator // list. [Indicator(System.Drawing.KnownColor.Chocolate, // Pick a color. Author = "Peter Gum", // Author's name. CompanyName = "phgyh@Yahoo.com", // Author's email address. Description = "The Heikin-Ashi Close.", // Brief title. GroupName = "User", // Indicator category. HelpText = "The Heikin-Ashi close is derived by an algorithm from the OHLC from the current and previous bar.", // The Id attribute needs to be set to a unique code that will identify // your indicator. A GUID is a good candidate. // Visual Studio can generate these (MS GuidGen tool), or see www.guidgen.com Id = "{7a63c187-a4f3-4a89-907d-ab888ea04e2e}", // Generated at www.guidgen.com Name = "HeiAshClose", // Name of the indicator. DefaultDrawingPane = "Price Pane")] // Plot pane default. // Indicators must be marked Serializable in order to be used in trading systems. [Serializable] // Class public class HeiAshClose : IndicatorBase { // Set class-level (instantiation) variables. double haO = 0; // Current ah open double haOprev = 0; // Previous ah open double haClose = 0; // Heikin-Ashi close for this bar // Next item in series /// Calculates the next value in the indicator series. public override double CalcNextValue(BarData bar) { if (haOprev == 0) // First bar { haOprev = (bar.Close + bar.Open + bar.High + bar.Low) / 4; // Bar average return double.NaN; } else // All other bars { double barAvg = (bar.Close + bar.Open + bar.High + bar.Low) / 4; // Bar average haO = (barAvg + haOprev)/2; // Open amalgam haClose= (barAvg + // Bar average haO + // Open amalgam for this bar Math.Max(bar.High,haO) + // Max of high and amalgam Math.Min(bar.Low, haO) ) /4; // Min of low and amalgam haOprev = barAvg; // Set for next bar. return haClose; } } // Next } // Class } // Namespace