private bool ContinueSequentialCount(int index) { var result = true; if (index == LastSequentialBar.Index) { return(result); } // Setup completed if (LastSequentialBar.Number >= MaxSequentialBarsNumber) { result = false; } // Not completed yet else { LastSequentialBar.Index = index; LastSequentialBar.Number += 1; } if (LastSequentialBar.Number == AlertOnSequentialBarNumber) { TriggerAlertAction?.Invoke(index, LastSequentialBar.Type == BarType.Bullish ? TradeType.Sell : TradeType.Buy, false); } return(result); }
private void ContinueCountdownCount(int index) { var setupsCopy = ReversalSetups.ToList(); foreach (var setup in setupsCopy) { var lastCountdownBarNumber = setup.CountdownBarNumber; if (setup.Type == TdReversalSetupType.Buy && _source[index] <= _bars.LowPrices[index - 1] && _source[index] <= _bars.LowPrices[index - 2]) { if (setup.CountdownBarNumber == MaxCountdownBarsNumber - 1 && _bars.LowPrices[index] > _source[setup.EighthCountdownBarIndex]) { continue; } setup.CountdownBarNumber += 1; } else if (setup.Type == TdReversalSetupType.Sell && _source[index] >= _bars.HighPrices[index - 1] && _source[index] >= _bars.HighPrices[index - 2]) { if (setup.CountdownBarNumber == MaxCountdownBarsNumber - 1 && _bars.HighPrices[index] < _source[setup.EighthCountdownBarIndex]) { continue; } setup.CountdownBarNumber += 1; } if (lastCountdownBarNumber == setup.CountdownBarNumber) { continue; } var bar = new TdBar { Index = index, Number = setup.CountdownBarNumber, Type = setup.Type == TdReversalSetupType.Buy ? BarType.Bearish : BarType.Bullish }; CountdownBars.Add(bar); PlotCountdownBarNumberAction?.Invoke(bar); if (setup.CountdownBarNumber == 1) { setup.FirstCountdownBarIndex = index; } else if (setup.CountdownBarNumber == 8) { setup.EighthCountdownBarIndex = index; } if (setup.CountdownBarNumber == MaxCountdownBarsNumber) { setup.LastCountdownBarIndex = MaxCountdownBarsNumber; ReversalSetups.Remove(setup); } if (setup.CountdownBarNumber == AlertOnCountdownBarNumber) { TriggerAlertAction?.Invoke(index, setup.Type == TdReversalSetupType.Buy ? TradeType.Buy : TradeType.Sell, true); } } }