Ejemplo n.º 1
0
        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);
        }