/// <summary> /// The Average Directional Index measures the strength of a prevailing trend as well as whether movement exists in the market. The ADX is measured on a scale of 0 100. A low ADX value (generally less than 20) can indicate a non-trending market with low volumes whereas a cross above 20 may indicate the start of a trend (either up or down). If the ADX is over 40 and begins to fall, it can indicate the slowdown of a current trend. /// </summary> /// <returns></returns> public ADX ADX(Data.IDataSeries input, int period) { if (cacheADX != null) { for (int idx = 0; idx < cacheADX.Length; idx++) { if (cacheADX[idx].Period == period && cacheADX[idx].EqualsInput(input)) { return(cacheADX[idx]); } } } lock (checkADX) { checkADX.Period = period; period = checkADX.Period; if (cacheADX != null) { for (int idx = 0; idx < cacheADX.Length; idx++) { if (cacheADX[idx].Period == period && cacheADX[idx].EqualsInput(input)) { return(cacheADX[idx]); } } } ADX indicator = new ADX(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); ADX[] tmp = new ADX[cacheADX == null ? 1 : cacheADX.Length + 1]; if (cacheADX != null) { cacheADX.CopyTo(tmp, 0); } tmp[tmp.Length - 1] = indicator; cacheADX = tmp; return(indicator); } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { fastEma.Set(Input[0]); macdAvg2.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); } else { fastEma.Set((ZeroLagEMA(Input, (int)(Fast / Acceleration))[0]) - (ZeroLagEMA(Input, (int)(Slow / Acceleration))[0])); double macd = fastEma[0]; macdAvg2.Set(ZeroLagEMA(fastEma, Smooth)[0]); double macdAvg = macdAvg2[0]; Value.Set(macd); Avg.Set(macdAvg); ADX.Set(ADXVMA(Value, (int)(Fast / Acceleration))[0]); Diff.Set(macd - macdAvg); //Print (Time[0] + ": Value = " + Value[0].ToString("0.00") + ", Avg = " + Avg[0].ToString("0.00") + ", ADX = " + ADX[0].ToString("0.00")); if ((Value[0] > ADX[0]) && (Value[0] > Threshold)) { MacdUp.Set(0); MacdDn.Reset(); MacdNeutral.Reset(); signal.Set(1); } else if ((Value[0] < ADX[0]) && (Value[0] < -Threshold)) { MacdDn.Set(0); MacdUp.Reset(); MacdNeutral.Reset(); signal.Set(-1); } else { MacdNeutral.Set(0); MacdDn.Reset(); MacdUp.Reset(); signal.Set(0); } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { var oldHigh = bars.High; var oldClose = bars.Close; var oldLow = bars.Low; bars.update(); // true range... var trval = truerange.next(Math.Max(bars.High - bars.Low, Math.Max(bars.High - oldClose, oldClose - bars.Low))); if (trval == 0.0) { trval = 0.000001; } // RWT try upmove/dnmove = Median[0] - Median[1]; // instead of High - Close[1] , Close[1] - Low[0]; var upmove = Math.Max(0, bars.High - oldHigh); var dnmove = Math.Max(0, oldLow - bars.Low); if (upmove > dnmove) { dnmove = 0; } else { upmove = 0; } var dplusval = dplus.next(upmove); var dminval = dminus.next(dnmove); var dmiplus = 100.0 * dplusval / trval; var dmiminus = 100.0 * dminval / trval; var dmisum = dmiplus + dmiminus; var dmidiff = Math.Abs(dmiplus - dmiminus); var adxval = 100.0 * adx.next((dmisum > 0)?(dmidiff / dmisum):0.5); ADX.Set(adxval); if (adxval < oldADX) { PlotColors[0][0] = Color.Gray; } DMPlus.Set(dmiplus); DMMinus.Set(dmiminus); oldADX = adxval; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar <= BarsRequired) { return; } if (_emaSlow == null) { _emaSlow = EMA(Open, slowEMAPeriod); } if (_emaFast == null) { _emaFast = EMA(fastEMAPeriod); } if (_adx == null) { _adx = ADX(_adxPeriod); } if (_adx[0] >= _adxMin) { PlotColors[0][0] = Color.Blue; } else { PlotColors[0][0] = Color.LightBlue; } FastEMAPlot.Set(_emaFast[0]); SlowEMAPlot.Set(_emaSlow[0]); if (CrossAbove(_emaFast, _emaSlow, 1) && _adx[0] >= _adxMin) { _signal = 1; BackColor = Color.LightGreen; } else if (CrossBelow(_emaFast, _emaSlow, 1) && _adx[0] >= _adxMin) { _signal = -1; BackColor = Color.Pink; } else { _signal = 0; BackColor = Color.White; } }
protected override void OnStartUp() { var b1 = RWT_HA.OHLCFactory.createPrimary(barsType, Open, High, Low, Close, Input); bars = RWT_HA.OHLCFactory.createSecondary(b1, barSmoothType, barSmoothArg); truerange = RWT_MA.MAFactory.create(dMType, dMLength); dplus = RWT_MA.MAFactory.create(dMType, dMLength); dminus = RWT_MA.MAFactory.create(dMType, dMLength); adx = RWT_MA.MAFactory.create(aDXType, aDXLength); truerange.init(bars.High - bars.Low); dplus.init(0); dminus.init(0); adx.init(.5); ADX.Set(0); oldADX = 0; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar <= BarsRequired) return; if (_emaSlow == null) _emaSlow = EMA(Open, slowEMAPeriod); if (_emaFast == null) _emaFast = EMA(fastEMAPeriod); if (_adx == null) _adx = ADX(_adxPeriod); if (_adx[0] >= _adxMin) { PlotColors[0][0] = Color.Blue; } else { PlotColors[0][0] = Color.LightBlue; } FastEMAPlot.Set(_emaFast[0]); SlowEMAPlot.Set(_emaSlow[0]); if (CrossAbove(_emaFast, _emaSlow, 1)&& _adx[0] >= _adxMin) { _signal = 1; BackColor = Color.LightGreen; } else if (CrossBelow(_emaFast, _emaSlow, 1) && _adx[0] >= _adxMin) { _signal = -1; BackColor = Color.Pink; } else { _signal = 0; BackColor = Color.White; } }
public void SetupObjects() { if (_emaSlow == null) { _emaSlow = EMA(_emaSlowPeriod); } if (_emaFast == null) { _emaFast = EMA(_emaFastPeriod); } if (_rsi == null) { _rsi = RSI(Median, _rsiPeriod, 1); } if (_adx == null) { _adx = ADX(_adxPeriod); } if (_atr == null) { _atr = ATR(_atrPeriod); } }
/// <summary> /// The Average Directional Index measures the strength of a prevailing trend as well as whether movement exists in the market. The ADX is measured on a scale of 0 100. A low ADX value (generally less than 20) can indicate a non-trending market with low volumes whereas a cross above 20 may indicate the start of a trend (either up or down). If the ADX is over 40 and begins to fall, it can indicate the slowdown of a current trend. /// </summary> /// <returns></returns> public ADX ADX(Data.IDataSeries input, int period) { if (cacheADX != null) for (int idx = 0; idx < cacheADX.Length; idx++) if (cacheADX[idx].Period == period && cacheADX[idx].EqualsInput(input)) return cacheADX[idx]; lock (checkADX) { checkADX.Period = period; period = checkADX.Period; if (cacheADX != null) for (int idx = 0; idx < cacheADX.Length; idx++) if (cacheADX[idx].Period == period && cacheADX[idx].EqualsInput(input)) return cacheADX[idx]; ADX indicator = new ADX(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); ADX[] tmp = new ADX[cacheADX == null ? 1 : cacheADX.Length + 1]; if (cacheADX != null) cacheADX.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheADX = tmp; return indicator; } }
public void SetupObjects() { if (_emaSlow == null) _emaSlow = EMA(_emaSlowPeriod); if (_emaFast == null) _emaFast = EMA(_emaFastPeriod); if (_rsi == null) _rsi = RSI(Median, _rsiPeriod, 1); if (_adx == null) _adx = ADX(_adxPeriod); if (_atr == null) _atr = ATR(_atrPeriod); }