Skip to content

Candlestick pattern functions skip most recent 2 bars — today’s signals appear only after a few days #15

@bollaramesh

Description

@bollaramesh

Description

First, I want to thank the maintainers for this fantastic open-source library. TALib.NETCore has been very helpful in building candlestick-based analysis, and we appreciate the effort in maintaining and updating it.

We are using the v0.5 TALib.NETCore candlestick API to detect patterns (like CdlAbandonedBaby, CdlAdvanceBlock, etc.) based on daily OHLC data.
The calculations run fine, but the output indicators are always missing the most recent 1–2 bars, even though today’s OHLC data is available.

**Interestingly, if we check the same data after a few days, indicators for that date appear correctly.

Here’s a simplified version of our code:

public static List<ScanResultViewModel> GetCandleStickScan(List<Quote> tradedata)
{
    var allIndicators = new List<SimpleScanResultViewModel>();

    tradedata = tradedata.OrderBy(it => it.Date).ToList();

    ReadOnlySpan<float> opens  = tradedata.Select(it => (float)it.Open).ToArray();
    ReadOnlySpan<float> highs  = tradedata.Select(it => (float)it.High).ToArray();
    ReadOnlySpan<float> lows   = tradedata.Select(it => (float)it.Low).ToArray();
    ReadOnlySpan<float> closes = tradedata.Select(it => (float)it.Close).ToArray();
    ReadOnlySpan<DateTime> dates = tradedata.Select(it => it.Date).ToArray();

    var inRange = new Range(0, tradedata.Count - 1);
    Span<int> outInt = stackalloc int[tradedata.Count];

    var result = Candles.AbandonedBaby<float>(
        opens, highs, lows, closes, inRange, outInt, out Range outRange
    );

    if (result == Core.RetCode.Success)
    {
        AccumulateCandleResults(dates.ToArray(), outInt.ToArray(),
            CandleScanTypes.CdlAbandonedBaby, ref allIndicators, outRange.Start.Value);
    }
    return allIndicators;
}
        private static void AccumulateCandleResults(DateTime[] tradeDates, int[] outInteger, CandleScanTypes scanType, ref List<SimpleScanResultViewModel> allIndicators, int outBegIndex = 0)
        {
            switch (scanType)
            {
                case CandleScanTypes.Cdl2Crows:
                    for (int i = outBegIndex; i < outInteger.Length; i++)
                    {
                        if (outInteger[i] == -100)
                        {
                            allIndicators.Add(new SimpleScanResultViewModel
                            {
                                TradeDate = tradeDates[i],
                                Indicator = BearishCandleScanTypes.Bearish_Cdl2Crows.ToString()
                            });
                        }
                    }

                    break;
                case CandleScanTypes.Cdl3BlackCrows:
                    for (int i = outBegIndex; i < outInteger.Length; i++)
                    {
                        if (outInteger[i] == -100)
                        {
                            allIndicators.Add(new SimpleScanResultViewModel
                            {
                                TradeDate = tradeDates[i],
                                Indicator = BearishCandleScanTypes.Bearish_Cdl3BlackCrows.ToString()
                            });
                        }
                    }
                    break;
    }
}

Problem Summary

  • The library executes without errors.
  • But pattern results (e.g., -100 signals) always appear for older dates — usually up to two days before the last candle.
  • We expect indicators for the latest bar (today’s OHLC), but nothing is returned.
  • Input data and ordering are correct (ascending by date).

Expected Behavior

When full OHLC history including today’s bar is passed,
the pattern detection should include today’s candle if it forms part of a valid pattern.

Notes

  1. We’re using full historical data with inRange = new Range(0, tradedata.Count - 1).
  2. Tested multiple patterns — all skip the most recent day.
  3. Based on our debugging, TA-Lib seems to apply an internal lookback window, but it’s unclear how much data it needs to generate the final-day result.
  4. Adding dummy future candles does produce output for the latest bar, which suggests the current-day pattern isn’t computed because of internal indexing.

Request

Can you please clarify:

  1. How TA-Lib determines which bars to generate pattern results for?
  2. Is this behavior expected (lookback limitation), or should the final bar be included in pattern evaluation?
  3. If expected, could you document how many bars of lookback each candlestick function uses, so we can compensate in our code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions