Exemple #1
0
        private void StartNewSequentialCount(int index, TdPriceFlipType priceFlipType)
        {
            if (PriceFlip && priceFlipType != TdPriceFlipType.None)
            {
                LastSequentialBar = new TdBar
                {
                    Type = priceFlipType == TdPriceFlipType.Bullish ? BarType.Bullish : BarType.Bearish
                };
            }
            else if (!PriceFlip)
            {
                if (_source[index] > _source[index - Period])
                {
                    LastSequentialBar = new TdBar
                    {
                        Type = BarType.Bullish
                    };
                }
                else if (_source[index] < _source[index - Period])
                {
                    LastSequentialBar = new TdBar
                    {
                        Type = BarType.Bearish
                    };
                }
            }

            if (LastSequentialBar != null)
            {
                LastSequentialBar.Index  = index;
                LastSequentialBar.Number = 1;
            }
        }
Exemple #2
0
        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);
                }
            }
        }