Repository navigation
Multi-Array Parameter Bug #12
Description
Hi. Thanks for creating this FFI wrapper. I'm using it in place of my own code. I ran into this problem and decided to ask my robot to look into it for us.
Summary
ta_lib_ffi version 0.3.0 fails when calling TA-Lib functions that require multiple array parameters (e.g., high, low, close). The library incorrectly processes these arrays, resulting in NoMethodError: undefined method 'length' for an instance of Float.
Environment
- Ruby Version: 3.4.7
- ta_lib_ffi Version: 0.3.0
- Platform: macOS (Darwin 25.0.0)
- TA-Lib C Library: 0.4.0 (installed via Homebrew)
Affected Functions
All TA-Lib functions requiring multiple array inputs fail, including:
- Volatility Indicators:
atr,natr,sar,trange - Momentum Indicators:
cci,willr,adx,stoch - Volume Indicators:
obv,ad,adosc - All Candlestick Patterns:
cdl_doji,cdl_hammer,cdl_engulfing, etc.
Working Functions
Single-array functions work correctly:
sma,ema,rsi,macd,bbands,roc, etc.
Minimal Reproducible Example
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'ta_lib_ffi', '0.3.0'
end
require 'ta_lib_ffi'
# Sample OHLC data (10 periods)
high = [102.0, 103.0, 104.0, 103.0, 105.0, 106.0, 107.0, 106.5, 108.0, 109.0]
low = [99.5, 100.0, 101.0, 100.5, 102.0, 103.0, 104.0, 103.5, 105.0, 106.0]
close = [101.0, 102.0, 101.5, 103.0, 104.0, 105.0, 105.5, 106.0, 107.0, 108.0]
puts "Ruby Version: #{RUBY_VERSION}"
puts "ta_lib_ffi Version: #{TALibFFI::VERSION}"
puts "Data arrays length: #{high.length}"
puts "\nAttempting to calculate ATR (Average True Range)...\n\n"
begin
# This should work but fails with NoMethodError
result = TALibFFI.atr(high, low, close, time_period: 5)
puts "SUCCESS: ATR calculated successfully"
puts "Result: #{result.inspect}"
rescue NoMethodError => e
puts "ERROR: #{e.class}"
puts "Message: #{e.message}"
puts "\nFull backtrace:"
puts e.backtrace.first(10).join("\n")
end
puts "\n" + ("=" * 80)
puts "Testing with single-array function (SMA) for comparison..."
puts "=" * 80 + "\n"
begin
# This works fine
sma_result = TALibFFI.sma(close, time_period: 5)
puts "SUCCESS: SMA calculated successfully"
puts "Result: #{sma_result.compact.inspect}"
rescue => e
puts "ERROR: #{e.class} - #{e.message}"
endExpected Behavior
The atr function should:
- Accept three arrays (high, low, close) as parameters
- Calculate the Average True Range indicator
- Return an array of ATR values
Actual Behavior
The function raises a NoMethodError:
ERROR: NoMethodError
Message: undefined method 'length' for an instance of Float
Full backtrace:
/path/to/gems/ta_lib_ffi-0.3.0/lib/ta_lib_ffi.rb:475:in 'TALibFFI.prepare_double_array'
/path/to/gems/ta_lib_ffi-0.3.0/lib/ta_lib_ffi.rb:783:in 'block in TALibFFI.setup_price_inputs'
/path/to/gems/ta_lib_ffi-0.3.0/lib/ta_lib_ffi.rb:781:in 'TALibFFI.setup_price_inputs'
Root Cause Analysis
The error occurs in ta_lib_ffi.rb:475 at this line:
array_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE * array.length)
^^^^^^^The array parameter is receiving a Float value instead of an Array, suggesting that the multi-array parameter setup in setup_price_inputs (line 781-783) is incorrectly processing the input arrays.
Workaround
Currently, there is no workaround for this issue. Users must skip all multi-array indicator functions when using ta_lib_ffi 0.3.0.
Impact
This bug affects:
- ~60% of TA-Lib indicators (122 out of 200+ functions)
- All users requiring volatility analysis (ATR, NATR)
- All users needing candlestick pattern recognition
- All users analyzing with OHLC data
Activity
MadBomber commentedon Nov 6, 2025
My robot wrote this extension for me to monkey patch your library.
Youngv commentedon Nov 6, 2025
Thanks for opening this issue — the parameters in your example don’t match the gem’s Usage conventions, which expect inputs as a single first argument and options as keyword arguments.
For single‑input indicators, pass one array as the first argument and set options via keywords (e.g., time_period).
For multi‑input indicators, pass an array of input series as the first argument in the documented order, and still use keyword options; passing high, low, close as three separate positional arguments is not supported.
Examples:
You can also check the doc for TALibFFI.atr on RubyDoc.
MadBomber commentedon Nov 6, 2025
That actually makes sense. Some dataframe libraries support that kind of convention.
I will let my robot know that it failed to read the documentation correctly. :)
Dewayne
o-*