public void WarmUp(ITradingObject tradingObject, StockAnalysis.Share.Bar bar) { foreach (var component in _components) { component.WarmUp(tradingObject, bar); } }
public override double[] Update(StockAnalysis.Share.Bar bar) { // calculate AR double up = _sumUp.Update(bar.HighestPrice - bar.OpenPrice); double down = _sumDown.Update(bar.OpenPrice - bar.LowestPrice); double ar = down == 0.0 ? 0.0 : up / down * 100.0; // calculate BR double tempBrBs = _firstBar ? 0.0 : Math.Max(0.0, bar.HighestPrice - _prevBar.ClosePrice); double tempBrSs = _firstBar ? 0.0 : Math.Max(0.0, _prevBar.ClosePrice - bar.LowestPrice); double brbs = _sumBrBs.Update(tempBrBs); double brss = _sumBrSs.Update(tempBrSs); double br = brss == 0.0 ? 0.0 : brbs / brss * 100.0; // calculate CR double tp = Tp(_prevBar); double tempCrBs = _firstBar ? 0.0 : Math.Max(0.0, bar.HighestPrice - tp); double tempCrSs = _firstBar ? 0.0 : Math.Max(0.0, tp - bar.LowestPrice); double crbs = _sumCrBs.Update(tempCrBs); double crss = _sumCrSs.Update(tempCrSs); double cr = crss == 0.0 ? 0.0 : crbs / crss * 100.0; // update bar _prevBar = bar; _firstBar = false; // return results; return(new double[3] { ar, br, cr }); }
public void Update(StockAnalysis.Share.Bar bar) { UpdateState(bar); }
public override double[] Update(StockAnalysis.Share.Bar bar) { // calculate +DM and -DM double pdm, ndm; if (_firstBar) { pdm = 0.0; ndm = 0.0; } else { pdm = Math.Max(0.0, bar.HighestPrice - _prevBar.HighestPrice); ndm = Math.Max(0.0, _prevBar.LowestPrice - bar.LowestPrice); if (pdm > ndm) { ndm = 0.0; } else if (pdm < ndm) { pdm = 0.0; } else { pdm = ndm = 0.0; } } // Calculate +DI and -DI double tr, pdi, ndi; if (_firstBar) { tr = bar.HighestPrice - bar.LowestPrice; } else { tr = Math.Max(Math.Abs(bar.HighestPrice - bar.LowestPrice), Math.Max(Math.Abs(bar.HighestPrice - _prevBar.ClosePrice), Math.Abs(bar.LowestPrice - _prevBar.ClosePrice))); } pdi = pdm * 100.0 / tr; ndi = ndm * 100.0 / tr; // calculate +DIM and -DIM double mspdm = _msPdm.Update(pdm); double msndm = _msNdm.Update(ndm); double mstr = _msTr.Update(tr); double pdim = mspdm * 100.0 / mstr; double ndim = msndm * 100.0 / mstr; // calculate DX and ADX double dx = (pdim + ndim) == 0.0 ? 0.0 : Math.Abs(pdim - ndim) / (pdim + ndim); double adx = _maDx.Update(dx); // calculate ADXR _adx.Add(adx); double adxr = (_adx[_adx.Length - 1] + _adx[0]) / 2.0; // update internal status _prevBar = bar; _firstBar = false; // return result return(new double[4] { pdim, ndim, adx, adxr }); }