Parent: Object
The HeikinAshi static class converts a BarHistory into a Heikin-Ashi representation. It supports both standard Heikin-Ashi calculations and an alternate smoothed version that first smooths the source OHLC series using a specified Indicator.
The first overload converts bars to a standard Heikin-Ashi BarHistory and returns the transformed data. The resulting BarHistory is cached in the source BarHistory using the key "HeikinAshi", so subsequent calls with the same source return the cached result.
For the first bar, the Heikin-Ashi Close is calculated as the average of the source Open, High, Low, and Close. Subsequent bars use the previous Heikin-Ashi Open and Close to calculate the new Open, while the High and Low are adjusted to include the Heikin-Ashi Open and Close when necessary.
The second overload creates a smoothed Heikin-Ashi BarHistory. The source Open, High, Low, and Close series are first smoothed using the Indicator specified by smoother and the period specified by period. The default smoother is "TEMA" with a period of 21.
The candleSmoothing parameter controls the formula used to calculate the Heikin-Ashi Close. If its value is "Valcu" (case-insensitive), the Close is calculated from the average of the smoothed Open, High, Low, and Close values. Any other value causes the alternate Vervoort-style formula to be used.
If the specified smoothing Indicator cannot be created or populated, the original unsmoothed TimeSeries is used instead. The smoothed result is also cached in the source BarHistory using a key that incorporates the smoother name, period, and candle smoothing method.
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { BarHistory ha = HeikinAshi.Convert(bars); PlotBarHistory(ha, "HA"); } public override void Execute(BarHistory bars, int idx) { } } }