private void Transition(BarAnalyzerResult result, IBarDatum datum) { IMove prevMove = CurrentMove.Close(datum); var newMove = Move.Open(MoveList.Count, datum, (int)result.Trend); MoveList.Add(newMove); CurrentTrendType = result.Trend; MoveSubject.OnNext(prevMove); }
private void Update(BarAnalyzerResult result) { // set WorkingBar to result.WorkingBar if CurrentTrend is Unknown or result.IsValidTrendBar is true // if (!HighList.Any() && !LowList.Any()) if (CurrentTrendType == Trend.TrendType.Unknown) { if (result.Trend == Trend.TrendType.Up) { LowList.Add(result.WorkingBar); } else if (result.Trend == Trend.TrendType.Down) { HighList.Add(result.WorkingBar); } CurrentTrendType = result.Trend; WorkingBar = result.WorkingBar; MoveList.Add(Move.Open(MoveList.Count, result.WorkingBar, (int)result.Trend)); } else { if (result.IsValidTrendBar) { WorkingBar = result.WorkingBar; // currentTrend: undetermined: currentTrend = trend // currentTrend: Up: if( trend.Down) changecurrentTrend to down and add bar Highest high series I {Working ... barDatum} // currentTrend: Down: if (trend.up) changcurrentTrend to up and add bar with Lowest low in series {WorkingBar .. barDatum} switch (CurrentTrendType) { case Trend.TrendType.Up: { if (result.Trend == Trend.TrendType.Down) { TransitionToDownFromUp(result); } } break; case Trend.TrendType.Down: { if (result.Trend == Trend.TrendType.Up) { TransitionToUpFromDown(result); } } break; } } } }
public static BarAnalyzerResult Analyze(IBarDatum workingBar, IBarDatum datum, Trend.TrendType trend) { BarAnalyzerResult result = new BarAnalyzerResult(); if (workingBar == null && datum != null) { result.WorkingBar = datum; result.Trend = GetBarTrend(datum); result.IsValidTrendBar = true; } else { bool isValidHigh = datum.High > workingBar.High && datum.Low > workingBar.Low; bool isValidLow = datum.High < workingBar.High && datum.Low < workingBar.Low; result.IsValidTrendBar = isValidHigh || isValidLow; if (result.IsValidTrendBar) { result.WorkingBar = datum; result.Trend = isValidHigh ? Trend.TrendType.Up : isValidLow ? Trend.TrendType.Down : Trend.TrendType.Unknown; } else { result.WorkingBar = workingBar; result.Trend = trend; } } return(result); }