using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class BullishDisparityPercent : WealthScript { StrategyParameter _pctDix; StrategyParameter _trigger; public BullishDisparityPercent() { _pctDix = CreateParameter("Pct Disparity", 2.5, 0, 8, 0.5); _trigger = CreateParameter("Trigger", 5, 1, 20, 1); } public DataSeries DIXN(Bars bars, int dixPeriod, int atrPeriod) { DataSeries ema = EMA.Series(bars.Close, dixPeriod, EMACalculation.Modern); DataSeries atr = ATRP.Series(bars, atrPeriod); DataSeries dixN = 100 * (bars.Close/ema - 1) / atr; dixN.Description = "DIXN(" + dixPeriod + "," + atrPeriod + ")"; return dixN; } public DataSeries BullishDIX (int dixPeriod, int atrPeriod, double disparity) { DataSeries dixMO = new DataSeries(Bars, "dixMO"); DataSeries contribs = new DataSeries(Bars, "Contributing Symbol Count"); foreach(string symbol in DataSetSymbols) { SetContext(symbol, true); PrintStatusBar("Processing: " + symbol); DataSeries dixN = DIXN(Bars, dixPeriod, atrPeriod); for (int bar = Bars.FirstActualBar; bar < Bars.Count; bar ++) { contribs[bar]++; if( dixN[bar] > disparity ) dixMO[bar]++; } RestoreContext(); } Community.Components.Utility u = new Community.Components.Utility(this); dixMO = 100 * dixMO / contribs; dixMO.Description = u.GetDataSetName() + " Bullish Disparity Percent(" + dixPeriod + "," + atrPeriod + "," + disparity + ")"; return dixMO; } protected override void Execute() { ChartPane dixPane = CreatePane(50, true, true); DataSeries dixBull = BullishDIX(100, 10, _pctDix.Value); PlotSeries(dixPane, dixBull, Color.Green, LineStyle.Solid, 1); // Find an associated index ChartPane idxPane = CreatePane( 100, true, true ); idxPane.LogScale = true; Bars idxBars = null; if (DataSetSymbols[0] == "AAPL") idxBars = GetExternalSymbol(".NDX", true); else if (DataSetSymbols[2] == "ABT") idxBars = GetExternalSymbol(".SPX", true); else idxBars = GetExternalSymbol(".DJI", true); PlotSymbol(idxPane, idxBars, Color.Green, Color.Red); // Highlight buy zones for (int bar = 100; bar < Bars.Count; bar++) { if( dixBull[bar - 1] < _trigger.Value && CrossOver(bar, dixBull, _trigger.Value) ) SetBackgroundColor(bar, Color.Aquamarine); } } } }