Module: TALibFFI

Extended by:
Fiddle::Importer
Defined in:
lib/ta_lib_ffi.rb

Overview

Ruby FFI wrapper for TA-Lib (Technical Analysis Library)

This module provides a Ruby interface to the TA-Lib technical analysis library using FFI (Foreign Function Interface). It allows you to perform various technical analysis calculations on financial market data.

Examples:

Basic usage

require 'ta_lib_ffi'

# Calculate Simple Moving Average
prices = [10.0, 11.0, 12.0, 11.0, 10.0]
result = TALibFFI.sma(prices, time_period: 3)

See Also:

Defined Under Namespace

Classes: TALibError

Constant Summary collapse

VERSION =
"0.2.0"
TA_SUCCESS =
0
TA_LIB_NOT_INITIALIZE =
1
TA_BAD_PARAM =
2
TA_ALLOC_ERR =
3
TA_GROUP_NOT_FOUND =
4
TA_FUNC_NOT_FOUND =
5
TA_INVALID_HANDLE =
6
TA_INVALID_PARAM_HOLDER =
7
TA_INVALID_PARAM_HOLDER_TYPE =
8
TA_INVALID_PARAM_FUNCTION =
9
TA_INPUT_NOT_ALL_INITIALIZE =
10
TA_OUTPUT_NOT_ALL_INITIALIZE =
11
TA_OUT_OF_RANGE_START_INDEX =
12
TA_OUT_OF_RANGE_END_INDEX =
13
TA_INVALID_LIST_TYPE =
14
TA_BAD_OBJECT =
15
TA_NOT_SUPPORTED =
16
TA_INTERNAL_ERROR =
5000
TA_UNKNOWN_ERR =
0xFFFF
TA_StringTable =
struct [
  "unsigned int size",
  "const char **string",
  "void *hiddenData"
]
TA_FuncInfo =
struct [
  "const char *name",
  "const char *group",
  "const char *hint",
  "const char *camelCaseName",
  "TA_FuncFlags flags",
  "unsigned int nbInput",
  "unsigned int nbOptInput",
  "unsigned int nbOutput",
  "const TA_FuncHandle *handle"
]
TA_ParamHolder =
struct [
  "void *hiddenData"
]
TA_InputParameterInfo =
struct [
  "TA_InputParameterType type",
  "const char *paramName",
  "TA_InputFlags flags"
]
TA_OptInputParameterInfo =
struct [
  "TA_OptInputParameterType type",
  "const char *paramName",
  "TA_OptInputFlags flags",
  "const char *displayName",
  "const void *dataSet",
  "TA_Real defaultValue",
  "const char *hint",
  "const char *helpFile"
]
TA_OutputParameterInfo =
struct [
  "TA_OutputParameterType type",
  "const char *paramName",
  "TA_OutputFlags flags"
]
TA_PARAM_TYPE =
{
  TA_Input_Price: 0,
  TA_Input_Real: 1,
  TA_Input_Integer: 2,
  TA_OptInput_RealRange: 0,
  TA_OptInput_RealList: 1,
  TA_OptInput_IntegerRange: 2,
  TA_OptInput_IntegerList: 3,
  TA_Output_Real: 0,
  TA_Output_Integer: 1
}.freeze
TA_FLAGS =
{
  TA_InputFlags: {
    TA_IN_PRICE_OPEN: 0x00000001,
    TA_IN_PRICE_HIGH: 0x00000002,
    TA_IN_PRICE_LOW: 0x00000004,
    TA_IN_PRICE_CLOSE: 0x00000008,
    TA_IN_PRICE_VOLUME: 0x00000010,
    TA_IN_PRICE_OPENINTEREST: 0x00000020,
    TA_IN_PRICE_TIMESTAMP: 0x00000040
  },
  TA_OptInputFlags: {
    TA_OPTIN_IS_PERCENT: 0x00100000,
    TA_OPTIN_IS_DEGREE: 0x00200000,
    TA_OPTIN_IS_CURRENCY: 0x00400000,
    TA_OPTIN_ADVANCED: 0x01000000
  },
  TA_OutputFlags: {
    TA_OUT_LINE: 0x00000001,
    TA_OUT_DOT_LINE: 0x00000002,
    TA_OUT_DASH_LINE: 0x00000004,
    TA_OUT_DOT: 0x00000008,
    TA_OUT_HISTO: 0x00000010,
    TA_OUT_PATTERN_BOOL: 0x00000020,
    TA_OUT_PATTERN_BULL_BEAR: 0x00000040,
    TA_OUT_PATTERN_STRENGTH: 0x00000080,
    TA_OUT_POSITIVE: 0x00000100,
    TA_OUT_NEGATIVE: 0x00000200,
    TA_OUT_ZERO: 0x00000400,
    TA_OUT_UPPER_LIMIT: 0x00000800,
    TA_OUT_LOWER_LIMIT: 0x00001000
  }
}.freeze

Class Method Summary collapse

Class Method Details

.accbands(price_hlc, time_period: 20.0) ⇒ Hash

GENERATED DOCUMENTATION START ### Acceleration Bands

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 20.0)

    Number of period (default: 20.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 796

.acos(real) ⇒ Array<Float>

Vector Trigonometric ACos

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 808

.ad(price_hlcv) ⇒ Array<Float>

Chaikin A/D Line

Parameters:

  • price_hlcv (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close, volume

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 815

.add(real0, real1) ⇒ Array<Float>

Vector Arithmetic Add

Parameters:

  • real0 (Array<Float>)

    Input values

  • real1 (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 822

.adosc(price_hlcv, fast_period: 3.0, slow_period: 10.0) ⇒ Array<Float>

Chaikin A/D Oscillator

Parameters:

  • price_hlcv (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close, volume

  • fast_period (Integer) (defaults to: 3.0)

    Number of period for the fast MA (default: 3.0)

  • slow_period (Integer) (defaults to: 10.0)

    Number of period for the slow MA (default: 10.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 830

.adx(price_hlc, time_period: 14.0) ⇒ Array<Float>

Average Directional Movement Index

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 839

.adxr(price_hlc, time_period: 14.0) ⇒ Array<Float>

Average Directional Movement Index Rating

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 847

.apo(real, fast_period: 12.0, slow_period: 26.0, ma_type: 0.0) ⇒ Array<Float>

Absolute Price Oscillator

Parameters:

  • real (Array<Float>)

    Input values

  • fast_period (Integer) (defaults to: 12.0)

    Number of period for the fast MA (default: 12.0)

  • slow_period (Integer) (defaults to: 26.0)

    Number of period for the slow MA (default: 26.0)

  • ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average (default: 0.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 855

.aroon(price_hl, time_period: 14.0) ⇒ Hash

Aroon

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 865

.aroonosc(price_hl, time_period: 14.0) ⇒ Array<Float>

Aroon Oscillator

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 875

.asin(real) ⇒ Array<Float>

Vector Trigonometric ASin

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 883

.atan(real) ⇒ Array<Float>

Vector Trigonometric ATan

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 890

.atr(price_hlc, time_period: 14.0) ⇒ Array<Float>

Average True Range

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 897

.avgdev(real, time_period: 14.0) ⇒ Array<Float>

Average Deviation

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 912

.avgprice(price_ohlc) ⇒ Array<Float>

Average Price

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 905

.bbands(real, time_period: 5.0, nb_dev_up: 2.0, nb_dev_dn: 2.0, ma_type: 0.0) ⇒ Hash

Bollinger Bands

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 5.0)

    Number of period (default: 5.0)

  • nb_dev_up (Float) (defaults to: 2.0)

    Deviation multiplier for upper band (default: 2.0)

  • nb_dev_dn (Float) (defaults to: 2.0)

    Deviation multiplier for lower band (default: 2.0)

  • ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average (default: 0.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 920

.beta(real0, real1, time_period: 5.0) ⇒ Array<Float>

Beta

Parameters:

  • real0 (Array<Float>)

    Input values

  • real1 (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 5.0)

    Number of period (default: 5.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 934

.bop(price_ohlc) ⇒ Array<Float>

Balance Of Power

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 943

.build_function_info_mapHash

Builds a map of function information for all functions

Returns:

  • (Hash)

    Map of function information



629
630
631
632
633
634
635
636
637
638
639
640
# File 'lib/ta_lib_ffi.rb', line 629

def build_function_info_map
  info_map = {}
  each_function do |func_info|
    info_map[func_info["name"].to_s] = {
      info: func_info,
      inputs: collect_input_info(func_info),
      outputs: collect_output_info(func_info),
      opt_inputs: collect_opt_input_info(func_info)
    }
  end
  info_map
end

.calculate_lookback(params_ptr) ⇒ Integer

Calculates the lookback period for a function with given parameters

Parameters:

  • params_ptr (Fiddle::Pointer)

    Pointer to parameter holder

Returns:

  • (Integer)

    The lookback period



388
389
390
391
392
393
# File 'lib/ta_lib_ffi.rb', line 388

def calculate_lookback(params_ptr)
  lookback_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
  ret_code = TA_GetLookback(params_ptr, lookback_ptr)
  check_ta_return_code(ret_code)
  lookback_ptr[0, Fiddle::SIZEOF_INT].unpack1("l")
end

.calculate_results(params_ptr, input_arrays, func_name) ⇒ Array, Hash

Calculates function results

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • input_arrays (Array)

    Input data

  • func_name (String)

    Function name

Returns:

  • (Array, Hash)

    Function results



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/ta_lib_ffi.rb', line 529

def calculate_results(params_ptr, input_arrays, func_name) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  func_info = function_info_map[func_name]
  input_size = if func_info[:inputs].first["type"] == TA_PARAM_TYPE[:TA_Input_Price]
                 input_arrays[0][0].length
               else
                 input_arrays[0].length
               end

  out_begin = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
  out_size = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
  output_arrays = setup_output_buffers(params_ptr, input_size, func_name)

  begin
    ret_code = TA_CallFunc(params_ptr, 0, input_size - 1, out_begin, out_size)
    check_ta_return_code(ret_code)

    actual_size = out_size[0, Fiddle::SIZEOF_INT].unpack1("l")
    format_output_results(output_arrays, actual_size, func_name)
  ensure
    out_begin.free
    out_size.free
    output_arrays.each(&:free)
  end
end

.call_func(func_name, args) ⇒ Array, Hash

Calls a TA-Lib function with the given arguments

Parameters:

  • func_name (String)

    The name of the function to call

  • args (Array)

    Array of input arrays and optional parameters

Returns:

  • (Array, Hash)

    Function results (single array or hash of named outputs)

Raises:

  • (TALibError)

    If there is an error in function execution



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/ta_lib_ffi.rb', line 365

def call_func(func_name, args) # rubocop:disable Metrics/MethodLength
  options = args.last.is_a?(Hash) ? args.pop : {}
  input_arrays = args

  validate_inputs!(input_arrays)

  handle_ptr = get_function_handle(func_name)
  params_ptr = create_parameter_holder(handle_ptr)

  begin
    setup_input_parameters(params_ptr, input_arrays, func_name)
    setup_optional_parameters(params_ptr, options, func_name)
    _lookback = calculate_lookback(params_ptr)
    calculate_results(params_ptr, input_arrays, func_name)
  ensure
    TA_ParamHolderFree(params_ptr)
  end
end

.cci(price_hlc, time_period: 14.0) ⇒ Array<Float>

Commodity Channel Index

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 950

.cdl2crows(price_ohlc) ⇒ Array<Integer>

Two Crows

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 958

.cdl3blackcrows(price_ohlc) ⇒ Array<Integer>

Three Black Crows

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 965

.cdl3inside(price_ohlc) ⇒ Array<Integer>

Three Inside Up/Down

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 972

.cdl3linestrike(price_ohlc) ⇒ Array<Integer>

Three-Line Strike

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 979

.cdl3outside(price_ohlc) ⇒ Array<Integer>

Three Outside Up/Down

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 986

.cdl3starsinsouth(price_ohlc) ⇒ Array<Integer>

Three Stars In The South

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 993

.cdl3whitesoldiers(price_ohlc) ⇒ Array<Integer>

Three Advancing White Soldiers

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1000

.cdlabandonedbaby(price_ohlc, penetration: 0.3) ⇒ Array<Integer>

Abandoned Baby

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.3)

    Percentage of penetration of a candle within another candle (default: 0.3)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1007

.cdladvanceblock(price_ohlc) ⇒ Array<Integer>

Advance Block

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1015

.cdlbelthold(price_ohlc) ⇒ Array<Integer>

Belt-hold

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1022

.cdlbreakaway(price_ohlc) ⇒ Array<Integer>

Breakaway

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1029

.cdlclosingmarubozu(price_ohlc) ⇒ Array<Integer>

Closing Marubozu

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1036

.cdlconcealbabyswall(price_ohlc) ⇒ Array<Integer>

Concealing Baby Swallow

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1043

.cdlcounterattack(price_ohlc) ⇒ Array<Integer>

Counterattack

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1050

.cdldarkcloudcover(price_ohlc, penetration: 0.5) ⇒ Array<Integer>

Dark Cloud Cover

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.5)

    Percentage of penetration of a candle within another candle (default: 0.5)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1057

.cdldoji(price_ohlc) ⇒ Array<Integer>

Doji

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1065

.cdldojistar(price_ohlc) ⇒ Array<Integer>

Doji Star

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1072

.cdldragonflydoji(price_ohlc) ⇒ Array<Integer>

Dragonfly Doji

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1079

.cdlengulfing(price_ohlc) ⇒ Array<Integer>

Engulfing Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1086

.cdleveningdojistar(price_ohlc, penetration: 0.3) ⇒ Array<Integer>

Evening Doji Star

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.3)

    Percentage of penetration of a candle within another candle (default: 0.3)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1093

.cdleveningstar(price_ohlc, penetration: 0.3) ⇒ Array<Integer>

Evening Star

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.3)

    Percentage of penetration of a candle within another candle (default: 0.3)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1101

.cdlgapsidesidewhite(price_ohlc) ⇒ Array<Integer>

Up/Down-gap side-by-side white lines

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1109

.cdlgravestonedoji(price_ohlc) ⇒ Array<Integer>

Gravestone Doji

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1116

.cdlhammer(price_ohlc) ⇒ Array<Integer>

Hammer

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1123

.cdlhangingman(price_ohlc) ⇒ Array<Integer>

Hanging Man

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1130

.cdlharami(price_ohlc) ⇒ Array<Integer>

Harami Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1137

.cdlharamicross(price_ohlc) ⇒ Array<Integer>

Harami Cross Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1144

.cdlhighwave(price_ohlc) ⇒ Array<Integer>

High-Wave Candle

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1151

.cdlhikkake(price_ohlc) ⇒ Array<Integer>

Hikkake Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1158

.cdlhikkakemod(price_ohlc) ⇒ Array<Integer>

Modified Hikkake Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1165

.cdlhomingpigeon(price_ohlc) ⇒ Array<Integer>

Homing Pigeon

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1172

.cdlidentical3crows(price_ohlc) ⇒ Array<Integer>

Identical Three Crows

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1179

.cdlinneck(price_ohlc) ⇒ Array<Integer>

In-Neck Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1186

.cdlinvertedhammer(price_ohlc) ⇒ Array<Integer>

Inverted Hammer

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1193

.cdlkicking(price_ohlc) ⇒ Array<Integer>

Kicking

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1200

.cdlkickingbylength(price_ohlc) ⇒ Array<Integer>

Kicking - bull/bear determined by the longer marubozu

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1207

.cdlladderbottom(price_ohlc) ⇒ Array<Integer>

Ladder Bottom

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1214

.cdllongleggeddoji(price_ohlc) ⇒ Array<Integer>

Long Legged Doji

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1221

.cdllongline(price_ohlc) ⇒ Array<Integer>

Long Line Candle

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1228

.cdlmarubozu(price_ohlc) ⇒ Array<Integer>

Marubozu

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1235

.cdlmatchinglow(price_ohlc) ⇒ Array<Integer>

Matching Low

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1242

.cdlmathold(price_ohlc, penetration: 0.5) ⇒ Array<Integer>

Mat Hold

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.5)

    Percentage of penetration of a candle within another candle (default: 0.5)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1249

.cdlmorningdojistar(price_ohlc, penetration: 0.3) ⇒ Array<Integer>

Morning Doji Star

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.3)

    Percentage of penetration of a candle within another candle (default: 0.3)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1257

.cdlmorningstar(price_ohlc, penetration: 0.3) ⇒ Array<Integer>

Morning Star

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

  • penetration (Float) (defaults to: 0.3)

    Percentage of penetration of a candle within another candle (default: 0.3)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1265

.cdlonneck(price_ohlc) ⇒ Array<Integer>

On-Neck Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1273

.cdlpiercing(price_ohlc) ⇒ Array<Integer>

Piercing Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1280

.cdlrickshawman(price_ohlc) ⇒ Array<Integer>

Rickshaw Man

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1287

.cdlrisefall3methods(price_ohlc) ⇒ Array<Integer>

Rising/Falling Three Methods

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1294

.cdlseparatinglines(price_ohlc) ⇒ Array<Integer>

Separating Lines

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1301

.cdlshootingstar(price_ohlc) ⇒ Array<Integer>

Shooting Star

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1308

.cdlshortline(price_ohlc) ⇒ Array<Integer>

Short Line Candle

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1315

.cdlspinningtop(price_ohlc) ⇒ Array<Integer>

Spinning Top

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1322

.cdlstalledpattern(price_ohlc) ⇒ Array<Integer>

Stalled Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1329

.cdlsticksandwich(price_ohlc) ⇒ Array<Integer>

Stick Sandwich

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1336

.cdltakuri(price_ohlc) ⇒ Array<Integer>

Takuri (Dragonfly Doji with very long lower shadow)

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1343

.cdltasukigap(price_ohlc) ⇒ Array<Integer>

Tasuki Gap

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1350

.cdlthrusting(price_ohlc) ⇒ Array<Integer>

Thrusting Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1357

.cdltristar(price_ohlc) ⇒ Array<Integer>

Tristar Pattern

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1364

.cdlunique3river(price_ohlc) ⇒ Array<Integer>

Unique 3 River

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1371

.cdlupsidegap2crows(price_ohlc) ⇒ Array<Integer>

Upside Gap Two Crows

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1378

.cdlxsidegap3methods(price_ohlc) ⇒ Array<Integer>

Upside/Downside Gap Three Methods

Parameters:

  • price_ohlc (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: open, high, low, close

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1385

.ceil(real) ⇒ Array<Float>

Vector Ceil

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1392

.check_ta_return_code(code) ⇒ Object

Checks TA-Lib return codes and raises appropriate errors

Parameters:

  • code (Integer)

    TA-Lib return code

Raises:

  • (TALibError)

    If the return code indicates an error



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/ta_lib_ffi.rb', line 705

def check_ta_return_code(code) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
  return if code == TA_SUCCESS

  error_message = case code
                  when TA_LIB_NOT_INITIALIZE
                    "TA-Lib not initialized, please call TA_Initialize first"
                  when TA_BAD_PARAM
                    "Bad parameter, please check input parameters"
                  when TA_ALLOC_ERR
                    "Memory allocation error, possibly insufficient memory"
                  when TA_GROUP_NOT_FOUND
                    "Function group not found"
                  when TA_FUNC_NOT_FOUND
                    "Function not found"
                  when TA_INVALID_HANDLE
                    "Invalid handle"
                  when TA_INVALID_PARAM_HOLDER
                    "Invalid parameter holder"
                  when TA_INVALID_PARAM_HOLDER_TYPE
                    "Invalid parameter holder type"
                  when TA_INVALID_PARAM_FUNCTION
                    "Invalid parameter function"
                  when TA_INPUT_NOT_ALL_INITIALIZE
                    "Input parameters not fully initialized"
                  when TA_OUTPUT_NOT_ALL_INITIALIZE
                    "Output parameters not fully initialized"
                  when TA_OUT_OF_RANGE_START_INDEX
                    "Start index out of range"
                  when TA_OUT_OF_RANGE_END_INDEX
                    "End index out of range"
                  when TA_INVALID_LIST_TYPE
                    "Invalid list type"
                  when TA_BAD_OBJECT
                    "Invalid object"
                  when TA_NOT_SUPPORTED
                    "Operation not supported"
                  when TA_INTERNAL_ERROR
                    "TA-Lib internal error"
                  when TA_UNKNOWN_ERR
                    "Unknown error"
                  else
                    "Undefined TA-Lib error (Error code: #{code})"
                  end

  raise TALibError, error_message
end

.cmo(real, time_period: 14.0) ⇒ Array<Float>

Chande Momentum Oscillator

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1399

.collect_input_info(func_info) ⇒ Array<Fiddle::CStructEntity>

Collects input parameter information for a function

Parameters:

  • func_info (Fiddle::CStructEntity)

    Function information

Returns:

  • (Array<Fiddle::CStructEntity>)

    Array of input parameter information



646
647
648
649
650
651
652
# File 'lib/ta_lib_ffi.rb', line 646

def collect_input_info(func_info)
  func_info["nbInput"].times.map do |i|
    param_info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
    TA_GetInputParameterInfo(func_info["handle"], i, param_info_ptr.ref)
    TA_InputParameterInfo.new(param_info_ptr)
  end
end

.collect_opt_input_info(func_info) ⇒ Array<Fiddle::CStructEntity>

Collects optional input parameter information for a function

Parameters:

  • func_info (Fiddle::CStructEntity)

    Function information

Returns:

  • (Array<Fiddle::CStructEntity>)

    Array of optional input parameter information



658
659
660
661
662
663
664
# File 'lib/ta_lib_ffi.rb', line 658

def collect_opt_input_info(func_info)
  func_info["nbOptInput"].times.map do |i|
    param_info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
    TA_GetOptInputParameterInfo(func_info["handle"], i, param_info_ptr.ref)
    TA_OptInputParameterInfo.new(param_info_ptr)
  end
end

.collect_output_info(func_info) ⇒ Array<Fiddle::CStructEntity>

Collects output parameter information for a function

Parameters:

  • func_info (Fiddle::CStructEntity)

    Function information

Returns:

  • (Array<Fiddle::CStructEntity>)

    Array of output parameter information



670
671
672
673
674
675
676
# File 'lib/ta_lib_ffi.rb', line 670

def collect_output_info(func_info)
  func_info["nbOutput"].times.map do |i|
    param_info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
    TA_GetOutputParameterInfo(func_info["handle"], i, param_info_ptr.ref)
    TA_OutputParameterInfo.new(param_info_ptr)
  end
end

.correl(real0, real1, time_period: 30.0) ⇒ Array<Float>

Pearson’s Correlation Coefficient ®

Parameters:

  • real0 (Array<Float>)

    Input values

  • real1 (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1407

.cos(real) ⇒ Array<Float>

Vector Trigonometric Cos

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1416

.cosh(real) ⇒ Array<Float>

Vector Trigonometric Cosh

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1423

.create_parameter_holder(handle_ptr) ⇒ Fiddle::Pointer

Creates a parameter holder for a function

Parameters:

  • handle_ptr (Fiddle::Pointer)

    Function handle pointer

Returns:

  • (Fiddle::Pointer)

    Pointer to parameter holder



429
430
431
432
433
434
# File 'lib/ta_lib_ffi.rb', line 429

def create_parameter_holder(handle_ptr)
  params_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  ret_code = TA_ParamHolderAlloc(handle_ptr, params_ptr.ref)
  check_ta_return_code(ret_code)
  params_ptr
end

.define_ta_function(method_name, func_name) ⇒ Object

Defines a TA-Lib function as a Ruby method with documentation

Parameters:

  • method_name (String)

    Name of the Ruby method to define

  • func_name (String)

    Name of the TA-Lib function



766
767
768
769
770
# File 'lib/ta_lib_ffi.rb', line 766

def define_ta_function(method_name, func_name)
  define_singleton_method(method_name) do |*args|
    call_func(func_name, args)
  end
end

.dema(real, time_period: 30.0) ⇒ Array<Float>

Double Exponential Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1430

.div(real0, real1) ⇒ Array<Float>

Vector Arithmetic Div

Parameters:

  • real0 (Array<Float>)

    Input values

  • real1 (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1438

.dx(price_hlc, time_period: 14.0) ⇒ Array<Float>

Directional Movement Index

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1446

.each_function {|func_info| ... } ⇒ Object

Iterates over all available TA-Lib functions

Yields:

  • (func_info)

    Yields function information for each function

Yield Parameters:

  • func_info (Fiddle::CStructEntity)

    Function information struct



292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/ta_lib_ffi.rb', line 292

def each_function(&block)
  callback = Fiddle::Closure::BlockCaller.new(
    Fiddle::TYPE_VOID,
    [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
    Fiddle::Function::DEFAULT
  ) do |func_info_ptr, _|
    block.call TA_FuncInfo.new(func_info_ptr)
  end

  ret_code = TA_ForEachFunc(callback, nil)
  check_ta_return_code(ret_code)
end

.ema(real, time_period: 30.0) ⇒ Array<Float>

Exponential Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1454

.exp(real) ⇒ Array<Float>

Vector Arithmetic Exp

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1462

.extract_flags(value, type) ⇒ Array<Symbol>

Extracts flags from a bitmask value based on the flag type

Parameters:

  • value (Integer)

    The bitmask value to extract flags from

  • type (Symbol)

    The type of flags to extract (:TA_InputFlags, :TA_OptInputFlags, or :TA_OutputFlags)

Returns:

  • (Array<Symbol>)

    Array of flag names that are set in the bitmask



232
233
234
235
236
237
238
# File 'lib/ta_lib_ffi.rb', line 232

def extract_flags(value, type)
  flags_set = []
  TA_FLAGS[type].each do |k, v|
    flags_set << k if (value & v) != 0
  end
  flags_set
end

.floor(real) ⇒ Array<Float>

Vector Floor

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1469

.format_output_results(output_ptrs, size, func_name) ⇒ Array, Hash

Formats output results from TA-Lib function

Parameters:

  • output_ptrs (Array<Fiddle::Pointer>)

    Array of output buffer pointers

  • size (Integer)

    Size of output data

  • func_name (String)

    Function name

Returns:

  • (Array, Hash)

    Formatted results



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/ta_lib_ffi.rb', line 593

def format_output_results(output_ptrs, size, func_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  func_info = function_info_map[func_name]
  results = output_ptrs.zip(func_info[:outputs]).map do |ptr, output|
    case output["type"]
    when TA_PARAM_TYPE[:TA_Output_Real]
      ptr[0, Fiddle::SIZEOF_DOUBLE * size].unpack("d#{size}")
    when TA_PARAM_TYPE[:TA_Output_Integer]
      ptr[0, Fiddle::SIZEOF_INT * size].unpack("l#{size}")
    end
  end

  return results.first if results.length == 1

  output_names = func_info[:outputs].map do |output|
    normalize_parameter_name(output["paramName"].to_s).to_sym
  end
  output_names.zip(results).to_h
end

.function_description_xmlString

Gets XML description of all TA-Lib functions

Returns:

  • (String)

    XML function descriptions



615
616
617
# File 'lib/ta_lib_ffi.rb', line 615

def function_description_xml
  TA_FunctionDescriptionXML().to_s
end

.function_info(name) ⇒ Fiddle::CStructEntity

Gets detailed information about a specific TA-Lib function

Parameters:

  • name (String)

    The name of the function to get information for

Returns:

  • (Fiddle::CStructEntity)

    Struct containing function information



276
277
278
279
280
281
282
283
284
285
286
# File 'lib/ta_lib_ffi.rb', line 276

def function_info(name)
  handle_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  ret_code = TA_GetFuncHandle(name, handle_ptr.ref)
  check_ta_return_code(ret_code)

  info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  ret_code = TA_GetFuncInfo(handle_ptr, info_ptr.ref)
  check_ta_return_code(ret_code)

  TA_FuncInfo.new(info_ptr)
end

.function_info_mapHash

Gets or builds the function information map

Returns:

  • (Hash)

    Map of function information



622
623
624
# File 'lib/ta_lib_ffi.rb', line 622

def function_info_map
  @function_info_map ||= build_function_info_map
end

.function_table(group) ⇒ Array<String>

Returns a list of all functions in a specific group

Parameters:

  • group (String)

    The name of the group to get functions for

Returns:

  • (Array<String>)

    Array of function names in the group



259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/ta_lib_ffi.rb', line 259

def function_table(group)
  string_table_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  ret_code = TA_FuncTableAlloc(group, string_table_ptr.ref)
  check_ta_return_code(ret_code)

  string_table = TA_StringTable.new(string_table_ptr)
  func_names = Fiddle::Pointer.new(string_table["string"])[0, Fiddle::SIZEOF_VOIDP * string_table["size"]].unpack("Q*").collect { |ptr| Fiddle::Pointer.new(ptr).to_s }

  TA_FuncTableFree(string_table)

  func_names
end

.generate_ta_functionsObject

Generates Ruby methods for all TA-Lib functions

This method iterates through all available TA-Lib functions and creates corresponding Ruby methods with proper documentation.



682
683
684
685
686
# File 'lib/ta_lib_ffi.rb', line 682

def generate_ta_functions
  each_function do |func_info|
    define_ta_function(func_info["name"].to_s.downcase, func_info["name"].to_s)
  end
end

.get_function_handle(func_name) ⇒ Fiddle::Pointer

Gets a function handle for a given function name

Parameters:

  • func_name (String)

    The name of the function

Returns:

  • (Fiddle::Pointer)

    Pointer to function handle



418
419
420
421
422
423
# File 'lib/ta_lib_ffi.rb', line 418

def get_function_handle(func_name)
  handle_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  ret_code = TA_GetFuncHandle(func_name, handle_ptr.ref)
  check_ta_return_code(ret_code)
  handle_ptr
end

.group_tableArray<String>

Returns a list of all available function groups in TA-Lib

Returns:

  • (Array<String>)

    Array of group names



243
244
245
246
247
248
249
250
251
252
253
# File 'lib/ta_lib_ffi.rb', line 243

def group_table
  string_table_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
  ret_code = TA_GroupTableAlloc(string_table_ptr.ref)
  check_ta_return_code(ret_code)

  string_table = TA_StringTable.new(string_table_ptr)
  group_names = Fiddle::Pointer.new(string_table["string"])[0, Fiddle::SIZEOF_VOIDP * string_table["size"]].unpack("Q*").collect { |ptr| Fiddle::Pointer.new(ptr).to_s }
  TA_GroupTableFree(string_table_ptr)

  group_names
end

.ht_dcperiod(real) ⇒ Array<Float>

Hilbert Transform - Dominant Cycle Period

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1476

.ht_dcphase(real) ⇒ Array<Float>

Hilbert Transform - Dominant Cycle Phase

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1483

.ht_phasor(real) ⇒ Hash

Hilbert Transform - Phasor Components

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1490

.ht_sine(real) ⇒ Hash

Hilbert Transform - SineWave

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1499

.ht_trendline(real) ⇒ Array<Float>

Hilbert Transform - Instantaneous Trendline

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1508

.ht_trendmode(real) ⇒ Array<Integer>

Hilbert Transform - Trend vs Cycle Mode

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1515

.imi(price_oc, time_period: 14.0) ⇒ Array<Float>

Intraday Momentum Index

Parameters:

  • price_oc (Array<Float>, Array<Float>)

    Required price arrays: open, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1522

.initialize_ta_libObject

Initializes the TA-Lib library



753
754
755
756
757
758
759
760
# File 'lib/ta_lib_ffi.rb', line 753

def initialize_ta_lib
  return if @initialized

  ret_code = TA_Initialize()
  check_ta_return_code(ret_code)
  at_exit { TA_Shutdown() }
  @initialized = true
end

.kama(real, time_period: 30.0) ⇒ Array<Float>

Kaufman Adaptive Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1530

.linearreg(real, time_period: 14.0) ⇒ Array<Float>

Linear Regression

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1538

.linearreg_angle(real, time_period: 14.0) ⇒ Array<Float>

Linear Regression Angle

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1546

.linearreg_intercept(real, time_period: 14.0) ⇒ Array<Float>

Linear Regression Intercept

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1554

.linearreg_slope(real, time_period: 14.0) ⇒ Array<Float>

Linear Regression Slope

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1562

.ln(real) ⇒ Array<Float>

Vector Log Natural

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1570

.log10(real) ⇒ Array<Float>

Vector Log10

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1577

.ma(real, time_period: 30.0, ma_type: 0.0) ⇒ Array<Float>

Moving average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

  • ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average (default: 0.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1584

.macd(real, fast_period: 12.0, slow_period: 26.0, signal_period: 9.0) ⇒ Hash

Moving Average Convergence/Divergence

Parameters:

  • real (Array<Float>)

    Input values

  • fast_period (Integer) (defaults to: 12.0)

    Number of period for the fast MA (default: 12.0)

  • slow_period (Integer) (defaults to: 26.0)

    Number of period for the slow MA (default: 26.0)

  • signal_period (Integer) (defaults to: 9.0)

    Smoothing for the signal line (nb of period) (default: 9.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1593

.macdext(real, fast_period: 12.0, fast_ma_type: 0.0, slow_period: 26.0, slow_ma_type: 0.0, signal_period: 9.0, signal_ma_type: 0.0) ⇒ Hash

MACD with controllable MA type

Parameters:

  • real (Array<Float>)

    Input values

  • fast_period (Integer) (defaults to: 12.0)

    Number of period for the fast MA (default: 12.0)

  • fast_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for fast MA (default: 0.0)

  • slow_period (Integer) (defaults to: 26.0)

    Number of period for the slow MA (default: 26.0)

  • slow_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for slow MA (default: 0.0)

  • signal_period (Integer) (defaults to: 9.0)

    Smoothing for the signal line (nb of period) (default: 9.0)

  • signal_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for signal line (default: 0.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1606

.macdfix(real, signal_period: 9.0) ⇒ Hash

Moving Average Convergence/Divergence Fix 12/26

Parameters:

  • real (Array<Float>)

    Input values

  • signal_period (Integer) (defaults to: 9.0)

    Smoothing for the signal line (nb of period) (default: 9.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1622

.mama(real, fast_limit: 0.5, slow_limit: 0.05) ⇒ Hash

MESA Adaptive Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • fast_limit (Float) (defaults to: 0.5)

    Upper limit use in the adaptive algorithm (default: 0.5)

  • slow_limit (Float) (defaults to: 0.05)

    Lower limit use in the adaptive algorithm (default: 0.05)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1633

.mavp(real, periods, min_period: 2.0, max_period: 30.0, ma_type: 0.0) ⇒ Array<Float>

Moving average with variable period

Parameters:

  • real (Array<Float>)

    Input values

  • periods (Array<Float>)

    Input values

  • min_period (Integer) (defaults to: 2.0)

    Value less than minimum will be changed to Minimum period (default: 2.0)

  • max_period (Integer) (defaults to: 30.0)

    Value higher than maximum will be changed to Maximum period (default: 30.0)

  • ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average (default: 0.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1644

.max(real, time_period: 30.0) ⇒ Array<Float>

Highest value over a specified period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1655

.maxindex(real, time_period: 30.0) ⇒ Array<Integer>

Index of highest value over a specified period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1663

.medprice(price_hl) ⇒ Array<Float>

Median Price

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1671

.mfi(price_hlcv, time_period: 14.0) ⇒ Array<Float>

Money Flow Index

Parameters:

  • price_hlcv (Array<Float>, Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close, volume

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1678

.midpoint(real, time_period: 14.0) ⇒ Array<Float>

MidPoint over period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1686

.midprice(price_hl, time_period: 14.0) ⇒ Array<Float>

Midpoint Price over period

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1694

.min(real, time_period: 30.0) ⇒ Array<Float>

Lowest value over a specified period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1702

.minindex(real, time_period: 30.0) ⇒ Array<Integer>

Index of lowest value over a specified period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Integer>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1710

.minmax(real, time_period: 30.0) ⇒ Hash

Lowest and highest values over a specified period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1718

.minmaxindex(real, time_period: 30.0) ⇒ Hash

Indexes of lowest and highest values over a specified period

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1728

.minus_di(price_hlc, time_period: 14.0) ⇒ Array<Float>

Minus Directional Indicator

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1738

.minus_dm(price_hl, time_period: 14.0) ⇒ Array<Float>

Minus Directional Movement

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1746

.mom(real, time_period: 10.0) ⇒ Array<Float>

Momentum

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 10.0)

    Number of period (default: 10.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1754

.mult(real0, real1) ⇒ Array<Float>

Vector Arithmetic Mult

Parameters:

  • real0 (Array<Float>)

    Input values

  • real1 (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1762

.natr(price_hlc, time_period: 14.0) ⇒ Array<Float>

Normalized Average True Range

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1770

.normalize_parameter_name(name) ⇒ String

Normalizes parameter names to Ruby style

Parameters:

  • name (String)

    Parameter name to normalize

Returns:

  • (String)

    Normalized parameter name



692
693
694
695
696
697
698
699
# File 'lib/ta_lib_ffi.rb', line 692

def normalize_parameter_name(name)
  name.sub(/^(optIn|outReal|outInteger|out|in)/, "")
      .gsub(/::/, "/")
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr("-", "_")
      .downcase
end

.obv(real, price_v) ⇒ Array<Float>

On Balance Volume

Parameters:

  • real (Array<Float>)

    Input values

  • price_v (Array<Float>)

    Required price arrays: volume

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1778

.plus_di(price_hlc, time_period: 14.0) ⇒ Array<Float>

Plus Directional Indicator

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1786

.plus_dm(price_hl, time_period: 14.0) ⇒ Array<Float>

Plus Directional Movement

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1794

.ppo(real, fast_period: 12.0, slow_period: 26.0, ma_type: 0.0) ⇒ Array<Float>

Percentage Price Oscillator

Parameters:

  • real (Array<Float>)

    Input values

  • fast_period (Integer) (defaults to: 12.0)

    Number of period for the fast MA (default: 12.0)

  • slow_period (Integer) (defaults to: 26.0)

    Number of period for the slow MA (default: 26.0)

  • ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average (default: 0.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1802

.prepare_double_array(array) ⇒ Fiddle::Pointer

Prepares a double array for TA-Lib input

Parameters:

  • array (Array<Numeric>)

    Array of numbers to prepare

Returns:

  • (Fiddle::Pointer)

    Pointer to prepared array



474
475
476
477
478
479
480
# File 'lib/ta_lib_ffi.rb', line 474

def prepare_double_array(array)
  array_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE * array.length)
  array.each_with_index do |value, i|
    array_ptr[i * Fiddle::SIZEOF_DOUBLE, Fiddle::SIZEOF_DOUBLE] = [value.to_f].pack("d")
  end
  array_ptr
end

.prepare_integer_array(array) ⇒ Fiddle::Pointer

Prepares an integer array for TA-Lib input

Parameters:

  • array (Array<Numeric>)

    Array of numbers to prepare

Returns:

  • (Fiddle::Pointer)

    Pointer to prepared array



486
487
488
489
490
491
492
# File 'lib/ta_lib_ffi.rb', line 486

def prepare_integer_array(array)
  array_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT * array.length)
  array.each_with_index do |value, i|
    array_ptr[i * Fiddle::SIZEOF_INT, Fiddle::SIZEOF_INT] = [value.to_i].pack("l")
  end
  array_ptr
end

Prints detailed information about a TA-Lib function

Parameters:

  • func_info (Fiddle::CStructEntity)

    Function information struct to print



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/ta_lib_ffi.rb', line 308

def print_function_info(func_info) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  puts "Function Name: #{func_info["name"]}"
  puts "Function Group: #{func_info["group"]}"
  puts "Function Hint: #{func_info["hint"]}"
  puts "Camel Case Name: #{func_info["camelCaseName"]}"
  puts "Flags: #{func_info["flags"]}"
  puts "Number of Inputs: #{func_info["nbInput"]}"
  puts "Number of Optional Inputs: #{func_info["nbOptInput"]}"
  puts "Number of Outputs: #{func_info["nbOutput"]}"
  puts "Function Handle: #{func_info["handle"].to_i}"

  puts "\nInput Parameter Info:"
  func_info["nbInput"].times do |i|
    param_info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
    ret_code = TA_GetInputParameterInfo(func_info["handle"], i, param_info_ptr.ref)
    check_ta_return_code(ret_code)
    param_info = TA_InputParameterInfo.new(param_info_ptr)
    puts "  Parameter #{i + 1}:"
    puts "    Name: #{param_info["paramName"]}"
    puts "    Type: #{param_info["type"]}"
    puts "    Flags: #{extract_flags(param_info["flags"], :TA_InputFlags)}"
  end

  puts "\nOptional Input Parameter Info:"
  func_info["nbOptInput"].times do |i|
    param_info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
    ret_code = TA_GetOptInputParameterInfo(func_info["handle"], i, param_info_ptr.ref)
    check_ta_return_code(ret_code)
    param_info = TA_OptInputParameterInfo.new(param_info_ptr)
    puts "  Parameter #{i + 1}:"
    puts "    Name: #{param_info["paramName"]}"
    puts "    Type: #{param_info["type"]}"
    puts "    Flags: #{extract_flags(param_info["flags"], :TA_OptInputFlags)}"
    puts "    Display Name: #{param_info["displayName"]}"
    puts "    Default Value: #{param_info["defaultValue"]}"
    puts "    Hint: #{param_info["hint"]}"
  end

  puts "\nOutput Parameter Info:"
  func_info["nbOutput"].times do |i|
    param_info_ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
    ret_code = TA_GetOutputParameterInfo(func_info["handle"], i, param_info_ptr.ref)
    check_ta_return_code(ret_code)
    param_info = TA_OutputParameterInfo.new(param_info_ptr)
    puts "  Parameter #{i + 1}:"
    puts "    Name: #{param_info["paramName"]}"
    puts "    Type: #{param_info["type"]}"
    puts "    Flags: #{extract_flags(param_info["flags"], :TA_OutputFlags)}"
  end
end

.roc(real, time_period: 10.0) ⇒ Array<Float>

Rate of change : ((price/prevPrice)-1)*100

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 10.0)

    Number of period (default: 10.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1812

.rocp(real, time_period: 10.0) ⇒ Array<Float>

Rate of change Percentage: (price-prevPrice)/prevPrice

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 10.0)

    Number of period (default: 10.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1820

.rocr(real, time_period: 10.0) ⇒ Array<Float>

Rate of change ratio: (price/prevPrice)

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 10.0)

    Number of period (default: 10.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1828

.rocr100(real, time_period: 10.0) ⇒ Array<Float>

Rate of change ratio 100 scale: (price/prevPrice)*100

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 10.0)

    Number of period (default: 10.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1836

.rsi(real, time_period: 14.0) ⇒ Array<Float>

Relative Strength Index

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1844

.sar(price_hl, acceleration: 0.02, maximum: 0.2) ⇒ Array<Float>

Parabolic SAR

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • acceleration (Float) (defaults to: 0.02)

    Acceleration Factor used up to the Maximum value (default: 0.02)

  • maximum (Float) (defaults to: 0.2)

    Acceleration Factor Maximum value (default: 0.2)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1852

.sarext(price_hl, start_value: 0.0, offset_on_reverse: 0.0, acceleration_init_long: 0.02, acceleration_long: 0.02, acceleration_max_long: 0.2, acceleration_init_short: 0.02, acceleration_short: 0.02, acceleration_max_short: 0.2) ⇒ Array<Float>

Parabolic SAR - Extended

Parameters:

  • price_hl (Array<Float>, Array<Float>)

    Required price arrays: high, low

  • start_value (Float) (defaults to: 0.0)

    Start value and direction. 0 for Auto, >0 for Long, <0 for Short (default: 0.0)

  • offset_on_reverse (Float) (defaults to: 0.0)

    Percent offset added/removed to initial stop on short/long reversal (default: 0.0)

  • acceleration_init_long (Float) (defaults to: 0.02)

    Acceleration Factor initial value for the Long direction (default: 0.02)

  • acceleration_long (Float) (defaults to: 0.02)

    Acceleration Factor for the Long direction (default: 0.02)

  • acceleration_max_long (Float) (defaults to: 0.2)

    Acceleration Factor maximum value for the Long direction (default: 0.2)

  • acceleration_init_short (Float) (defaults to: 0.02)

    Acceleration Factor initial value for the Short direction (default: 0.02)

  • acceleration_short (Float) (defaults to: 0.02)

    Acceleration Factor for the Short direction (default: 0.02)

  • acceleration_max_short (Float) (defaults to: 0.2)

    Acceleration Factor maximum value for the Short direction (default: 0.2)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1861

.set_input_parameter(params_ptr, index, array, input_info) ⇒ Integer

Sets a single input parameter

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • index (Integer)

    Parameter index

  • array (Array)

    Input data array

  • input_info (Hash)

    Input parameter information

Returns:

  • (Integer)

    TA-Lib return code



457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/ta_lib_ffi.rb', line 457

def set_input_parameter(params_ptr, index, array, input_info)
  case input_info["type"]
  when TA_PARAM_TYPE[:TA_Input_Real]
    input_ptr = prepare_double_array(array)
    TA_SetInputParamRealPtr(params_ptr, index, input_ptr)
  when TA_PARAM_TYPE[:TA_Input_Integer]
    input_ptr = prepare_integer_array(array)
    TA_SetInputParamIntegerPtr(params_ptr, index, input_ptr)
  when TA_PARAM_TYPE[:TA_Input_Price]
    setup_price_inputs(params_ptr, index, array, input_info["flags"])
  end
end

.set_optional_parameter(params_ptr, index, value, type) ⇒ Object

Sets a single optional parameter

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • index (Integer)

    Parameter index

  • value (Numeric)

    Parameter value

  • type (Integer)

    Parameter type



513
514
515
516
517
518
519
520
521
# File 'lib/ta_lib_ffi.rb', line 513

def set_optional_parameter(params_ptr, index, value, type)
  case type
  when TA_PARAM_TYPE[:TA_OptInput_RealRange], TA_PARAM_TYPE[:TA_OptInput_RealList]
    ret_code = TA_SetOptInputParamReal(params_ptr, index, value)
  when TA_PARAM_TYPE[:TA_OptInput_IntegerRange], TA_PARAM_TYPE[:TA_OptInput_IntegerList]
    ret_code = TA_SetOptInputParamInteger(params_ptr, index, value)
  end
  check_ta_return_code(ret_code)
end

.setup_input_parameters(params_ptr, input_arrays, func_name) ⇒ Object

Sets up input parameters for a function call

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • input_arrays (Array<Array>)

    Input data arrays

  • func_name (String)

    Function name



441
442
443
444
445
446
447
448
# File 'lib/ta_lib_ffi.rb', line 441

def setup_input_parameters(params_ptr, input_arrays, func_name)
  func_info = function_info_map[func_name]
  input_arrays.each_with_index do |array, index|
    input_info = func_info[:inputs][index]
    ret_code = set_input_parameter(params_ptr, index, array, input_info)
    check_ta_return_code(ret_code)
  end
end

.setup_optional_parameters(params_ptr, options, func_name) ⇒ Object

Sets up optional parameters for a function call

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • options (Hash)

    Optional parameters

  • func_name (String)

    Function name



499
500
501
502
503
504
505
# File 'lib/ta_lib_ffi.rb', line 499

def setup_optional_parameters(params_ptr, options, func_name)
  func_info = function_info_map[func_name]
  func_info[:opt_inputs]&.each_with_index do |opt_input, index|
    param_name = normalize_parameter_name(opt_input["paramName"].to_s)
    set_optional_parameter(params_ptr, index, options[param_name.to_sym], opt_input["type"]) if options.key?(param_name.to_sym)
  end
end

.setup_output_buffers(params_ptr, size, func_name) ⇒ Array<Fiddle::Pointer>

Sets up output buffers for function results

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • size (Integer)

    Size of output buffer

  • func_name (String)

    Function name

Returns:

  • (Array<Fiddle::Pointer>)

    Array of output buffer pointers



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/ta_lib_ffi.rb', line 560

def setup_output_buffers(params_ptr, size, func_name) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  func_info = function_info_map[func_name]
  output_ptrs = []

  func_info[:outputs].each_with_index do |output, index|
    ptr = case output["type"]
          when TA_PARAM_TYPE[:TA_Output_Real]
            Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE * size)
          when TA_PARAM_TYPE[:TA_Output_Integer]
            Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT * size)
          end

    output_ptrs << ptr

    ret_code =  case output["type"]
                when TA_PARAM_TYPE[:TA_Output_Real]
                  TA_SetOutputParamRealPtr(params_ptr, index, ptr)
                when TA_PARAM_TYPE[:TA_Output_Integer]
                  TA_SetOutputParamIntegerPtr(params_ptr, index, ptr)
                end

    check_ta_return_code(ret_code)
  end

  output_ptrs
end

.setup_price_inputs(params_ptr, index, price_data, flags) ⇒ Object

Sets up price inputs for functions that take price data

Parameters:

  • params_ptr (Fiddle::Pointer)

    Parameter holder pointer

  • index (Integer)

    Parameter index

  • price_data (Array)

    Price data array

  • flags (Integer)

    Input flags



778
779
780
781
782
783
784
785
786
787
# File 'lib/ta_lib_ffi.rb', line 778

def setup_price_inputs(params_ptr, index, price_data, flags)
  required_flags = extract_flags(flags, :TA_InputFlags)
  data_pointers = Array.new(6) { Fiddle::Pointer.malloc(0) }
  required_flags.each_with_index do |flag, i|
    flag_index = TA_FLAGS[:TA_InputFlags].keys.index(flag)
    data_pointers[flag_index] = prepare_double_array(price_data[i]) if required_flags.include?(flag)
  end

  TA_SetInputParamPricePtr(params_ptr, index, *data_pointers)
end

.sin(real) ⇒ Array<Float>

Vector Trigonometric Sin

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1876

.sinh(real) ⇒ Array<Float>

Vector Trigonometric Sinh

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1883

.sma(real, time_period: 30.0) ⇒ Array<Float>

Simple Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1890

.sqrt(real) ⇒ Array<Float>

Vector Square Root

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1898

.stddev(real, time_period: 5.0, nb_dev: 1.0) ⇒ Array<Float>

Standard Deviation

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 5.0)

    Number of period (default: 5.0)

  • nb_dev (Float) (defaults to: 1.0)

    Nb of deviations (default: 1.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1905

.stoch(price_hlc, fast_k_period: 5.0, slow_k_period: 3.0, slow_k_ma_type: 0.0, slow_d_period: 3.0, slow_d_ma_type: 0.0) ⇒ Hash

Stochastic

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • fast_k_period (Integer) (defaults to: 5.0)

    Time period for building the Fast-K line (default: 5.0)

  • slow_k_period (Integer) (defaults to: 3.0)

    Smoothing for making the Slow-K line. Usually set to 3 (default: 3.0)

  • slow_k_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for Slow-K (default: 0.0)

  • slow_d_period (Integer) (defaults to: 3.0)

    Smoothing for making the Slow-D line (default: 3.0)

  • slow_d_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for Slow-D (default: 0.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1914

.stochf(price_hlc, fast_k_period: 5.0, fast_d_period: 3.0, fast_d_ma_type: 0.0) ⇒ Hash

Stochastic Fast

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • fast_k_period (Integer) (defaults to: 5.0)

    Time period for building the Fast-K line (default: 5.0)

  • fast_d_period (Integer) (defaults to: 3.0)

    Smoothing for making the Fast-D line. Usually set to 3 (default: 3.0)

  • fast_d_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for Fast-D (default: 0.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1928

.stochrsi(real, time_period: 14.0, fast_k_period: 5.0, fast_d_period: 3.0, fast_d_ma_type: 0.0) ⇒ Hash

Stochastic Relative Strength Index

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

  • fast_k_period (Integer) (defaults to: 5.0)

    Time period for building the Fast-K line (default: 5.0)

  • fast_d_period (Integer) (defaults to: 3.0)

    Smoothing for making the Fast-D line. Usually set to 3 (default: 3.0)

  • fast_d_ma_type (Integer) (defaults to: 0.0)

    Type of Moving Average for Fast-D (default: 0.0)

Returns:

  • (Hash)

    Hash containing the following arrays:

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1940

.sub(real0, real1) ⇒ Array<Float>

Vector Arithmetic Subtraction

Parameters:

  • real0 (Array<Float>)

    Input values

  • real1 (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1953

.sum(real, time_period: 30.0) ⇒ Array<Float>

Summation

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1961

.t3(real, time_period: 5.0, v_factor: 0.7) ⇒ Array<Float>

Triple Exponential Moving Average (T3)

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 5.0)

    Number of period (default: 5.0)

  • v_factor (Float) (defaults to: 0.7)

    Volume Factor (default: 0.7)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1969

.tan(real) ⇒ Array<Float>

Vector Trigonometric Tan

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1978

.tanh(real) ⇒ Array<Float>

Vector Trigonometric Tanh

Parameters:

  • real (Array<Float>)

    Input values

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1985

.tema(real, time_period: 30.0) ⇒ Array<Float>

Triple Exponential Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 1992

.trange(price_hlc) ⇒ Array<Float>

True Range

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2000

.trima(real, time_period: 30.0) ⇒ Array<Float>

Triangular Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2007

.trix(real, time_period: 30.0) ⇒ Array<Float>

1-day Rate-Of-Change (ROC) of a Triple Smooth EMA

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2015

.tsf(real, time_period: 14.0) ⇒ Array<Float>

Time Series Forecast

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2023

.typprice(price_hlc) ⇒ Array<Float>

Typical Price

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2031

.ultosc(price_hlc, time_period1: 7.0, time_period2: 14.0, time_period3: 28.0) ⇒ Array<Float>

Ultimate Oscillator

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period1 (Integer) (defaults to: 7.0)

    Number of bars for 1st period. (default: 7.0)

  • time_period2 (Integer) (defaults to: 14.0)

    Number of bars fro 2nd period (default: 14.0)

  • time_period3 (Integer) (defaults to: 28.0)

    Number of bars for 3rd period (default: 28.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2038

.validate_inputs!(arrays) ⇒ Object

Validates input arrays for TA-Lib functions

Parameters:

  • arrays (Array<Array>)

    Arrays to validate

Raises:



399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/ta_lib_ffi.rb', line 399

def validate_inputs!(arrays) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  raise TALibError, "Input arrays cannot be empty" if arrays.empty?

  arrays.each do |arr|
    raise TALibError, "Input must be arrays" unless arr.is_a?(Array)
  end

  sizes = arrays.map(&:length)
  raise TALibError, "Input arrays cannot be empty" if sizes.any?(&:zero?)

  arrays.each do |arr|
    raise TALibError, "Input arrays must contain only numbers" unless arr.flatten.all? { |x| x.is_a?(Numeric) }
  end
end

.var(real, time_period: 5.0, nb_dev: 1.0) ⇒ Array<Float>

Variance

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 5.0)

    Number of period (default: 5.0)

  • nb_dev (Float) (defaults to: 1.0)

    Nb of deviations (default: 1.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2048

.wclprice(price_hlc) ⇒ Array<Float>

Weighted Close Price

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2057

.willr(price_hlc, time_period: 14.0) ⇒ Array<Float>

Williams’ %R

Parameters:

  • price_hlc (Array<Float>, Array<Float>, Array<Float>)

    Required price arrays: high, low, close

  • time_period (Integer) (defaults to: 14.0)

    Number of period (default: 14.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2064

.wma(real, time_period: 30.0) ⇒ Array<Float>

Weighted Moving Average

Parameters:

  • real (Array<Float>)

    Input values

  • time_period (Integer) (defaults to: 30.0)

    Number of period (default: 30.0)

Returns:

  • (Array<Float>)

Raises:

  • (TALibError)

    If there is an error in function execution



# File 'lib/ta_lib_ffi.rb', line 2072