Technical Indicators¶
SQA::TAI provides access to 200+ technical analysis indicators from the TA-Lib C library. All indicators are accessible through simple, intuitive Ruby methods.
Indicator Categories¶
Overlap Studies¶
Moving averages and bands that overlay price charts:
- Simple Moving Average (SMA)
- Exponential Moving Average (EMA)
- Weighted Moving Average (WMA)
- Bollinger Bands (BBANDS)
Momentum Indicators¶
Measure the rate of price change:
- Relative Strength Index (RSI)
- Moving Average Convergence/Divergence (MACD)
- Stochastic Oscillator (STOCH)
- Momentum (MOM)
Volatility Indicators¶
Measure market volatility and price range:
Volume Indicators¶
Analyze trading volume:
Pattern Recognition¶
Identify candlestick patterns:
Cycle Indicators¶
Hilbert Transform indicators for cycle analysis:
Price Transform Indicators¶
Transform OHLC data into representative prices:
Statistical Indicators¶
Statistical functions for trend analysis:
Usage Overview¶
All indicators follow a consistent API pattern:
require 'sqa/tai'
# Single input, single output
result = SQA::TAI.sma(prices, period: 10)
# Single input, multiple outputs
upper, middle, lower = SQA::TAI.bbands(prices, period: 20)
# Multiple inputs (OHLC data)
atr = SQA::TAI.atr(high, low, close, period: 14)
Common Parameters¶
Most indicators accept these standard parameters:
| Parameter | Description | Default |
|---|---|---|
period |
Time period for calculation | Varies by indicator |
ma_type |
Moving average type (0=SMA, 1=EMA, etc.) | 0 (SMA) |
nbdev_up |
Standard deviations for upper band | 2.0 |
nbdev_down |
Standard deviations for lower band | 2.0 |
Return Values¶
- Single output indicators return an array
- Multiple output indicators return multiple arrays
- Arrays may contain
nilvalues for the warmup period - Use
.compactto filter outnilvalues - Use
.lastto get the most recent value
Best Practices¶
- Ensure sufficient data - Most indicators need a warmup period
- Handle nil values - Check for nil before using values
- Validate parameters - Use appropriate period lengths for your timeframe
- Combine indicators - Use multiple indicators for confirmation
- Backtest strategies - Always test before live trading
Example: Multi-Indicator Analysis¶
require 'sqa/tai'
# Load historical data
prices = load_stock_data('AAPL')
# Trend: Moving averages
sma_20 = SQA::TAI.sma(prices, period: 20)
sma_50 = SQA::TAI.sma(prices, period: 50)
# Momentum: RSI
rsi = SQA::TAI.rsi(prices, period: 14)
# Volatility: Bollinger Bands
upper, middle, lower = SQA::TAI.bbands(prices, period: 20)
# Analyze current conditions
current_price = prices.last
current_rsi = rsi.last
if current_price > sma_20.last && current_price > sma_50.last
puts "Uptrend confirmed"
end
if current_rsi < 30
puts "Oversold condition"
elsif current_rsi > 70
puts "Overbought condition"
end
if current_price < lower.last
puts "Price below lower Bollinger Band"
end