private bool IsReversalSetupPerfect(TdReversalSetup setup) { if (setup.Type == TdReversalSetupType.Buy) { var lastBarLow = _bars.LowPrices[setup.LastSequentialBarIndex]; var previousBarLow = _bars.LowPrices[setup.LastSequentialBarIndex - 1]; var sixthBarLow = _bars.LowPrices[setup.FirstSequentialBarIndex + 5]; var seventhBarLow = _bars.LowPrices[setup.FirstSequentialBarIndex + 6]; if (lastBarLow <= sixthBarLow && lastBarLow <= seventhBarLow || previousBarLow <= sixthBarLow && previousBarLow <= seventhBarLow) { return(true); } } else { var lastBarHigh = _bars.HighPrices[setup.LastSequentialBarIndex]; var previousBarHigh = _bars.HighPrices[setup.LastSequentialBarIndex - 1]; var sixthBarHigh = _bars.HighPrices[setup.FirstSequentialBarIndex + 5]; var seventhBarHigh = _bars.HighPrices[setup.FirstSequentialBarIndex + 6]; if (lastBarHigh >= sixthBarHigh && lastBarHigh >= seventhBarHigh || previousBarHigh >= sixthBarHigh && previousBarHigh >= seventhBarHigh) { return(true); } } return(false); }
public void Calculate(int index) { // Sets last sequential bar to Null if the setup interrupted if (LastSequentialBar != null) { if (index > LastSequentialBar.Index) { SequentialBars.Add(LastSequentialBar); } CancelCountIfInvalidated(index); } var priceFlipType = GetPriceFlipType(index); PlotPriceFlipAction?.Invoke(index, priceFlipType); // Start new counting if (LastSequentialBar == null) { StartNewSequentialCount(index, priceFlipType); } // Continue count else { var continueResult = ContinueSequentialCount(index); if (!continueResult) { StartNewSequentialCount(index, priceFlipType); var reversalSetup = new TdReversalSetup { Type = LastSequentialBar.Type == BarType.Bullish ? TdReversalSetupType.Sell : TdReversalSetupType.Buy, FirstSequentialBarIndex = LastSequentialBar.Index - MaxSequentialBarsNumber, LastSequentialBarIndex = LastSequentialBar.Index }; if (IsReversalSetupPerfect(reversalSetup)) { PlotPerfectReversalSetupAction?.Invoke(reversalSetup); } ReversalSetups.Add(reversalSetup); } } if (LastSequentialBar != null) { PlotSequentialBarNumberAction?.Invoke(LastSequentialBar); } ContinueCountdownCount(index - 1); }