technical-indicators
Technical analysis with TA-Lib - Moving averages, RSI, MACD, Bollinger Bands, Stochastic, ATR, candlestick patterns, and strategy signals using OpenAlgo market data
What this skill does
# OpenAlgo Technical Indicators
Perform technical analysis using TA-Lib with OpenAlgo market data. Build trading strategies based on indicators, generate signals, and backtest ideas.
## Environment Setup
```bash
# Install TA-Lib (requires system library)
# macOS
brew install ta-lib
pip install TA-Lib
# Ubuntu/Debian
sudo apt-get install libta-lib-dev
pip install TA-Lib
# Windows
# Download from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib
pip install TA_Lib‑0.4.28‑cp311‑cp311‑win_amd64.whl
```
```python
from openalgo import api
import talib
import pandas as pd
import numpy as np
client = api(
api_key='your_api_key_here',
host='http://127.0.0.1:5000'
)
```
## Quick Start Scripts
### Calculate Indicators
```bash
python scripts/indicators.py --symbol SBIN --exchange NSE --interval 5m --days 5
```
### Generate Signals
```bash
python scripts/signals.py --symbol NIFTY --exchange NSE_INDEX --strategy rsi_oversold
```
### Scan for Patterns
```bash
python scripts/scanner.py --symbols RELIANCE,TCS,INFY,SBIN --exchange NSE --pattern bullish
```
---
## Fetching Data for Analysis
```python
from openalgo import api
import pandas as pd
client = api(api_key='your_key', host='http://127.0.0.1:5000')
# Fetch historical data
df = client.history(
symbol="SBIN",
exchange="NSE",
interval="5m",
start_date="2025-01-01",
end_date="2025-01-15"
)
# TA-Lib requires numpy arrays
open_prices = df['open'].values
high_prices = df['high'].values
low_prices = df['low'].values
close_prices = df['close'].values
volume = df['volume'].values
```
---
## Overlap Studies (Trend Indicators)
### Simple Moving Average (SMA)
```python
import talib
# Calculate SMA
sma_20 = talib.SMA(close_prices, timeperiod=20)
sma_50 = talib.SMA(close_prices, timeperiod=50)
sma_200 = talib.SMA(close_prices, timeperiod=200)
# Add to DataFrame
df['SMA_20'] = sma_20
df['SMA_50'] = sma_50
df['SMA_200'] = sma_200
# Crossover signal
df['SMA_Cross'] = np.where(df['SMA_20'] > df['SMA_50'], 1, -1)
```
### Exponential Moving Average (EMA)
```python
ema_9 = talib.EMA(close_prices, timeperiod=9)
ema_21 = talib.EMA(close_prices, timeperiod=21)
df['EMA_9'] = ema_9
df['EMA_21'] = ema_21
# EMA crossover
df['EMA_Signal'] = np.where(df['EMA_9'] > df['EMA_21'], 'BUY', 'SELL')
```
### Bollinger Bands
```python
upper, middle, lower = talib.BBANDS(
close_prices,
timeperiod=20,
nbdevup=2,
nbdevdn=2,
matype=0 # SMA
)
df['BB_Upper'] = upper
df['BB_Middle'] = middle
df['BB_Lower'] = lower
df['BB_Width'] = (upper - lower) / middle * 100 # Bandwidth %
# Bollinger Band signals
df['BB_Signal'] = np.where(close_prices < lower, 'BUY',
np.where(close_prices > upper, 'SELL', 'HOLD'))
```
### SuperTrend (Custom Implementation)
```python
def supertrend(df, period=10, multiplier=3):
"""Calculate SuperTrend indicator."""
hl2 = (df['high'] + df['low']) / 2
atr = talib.ATR(df['high'].values, df['low'].values, df['close'].values, timeperiod=period)
upperband = hl2 + (multiplier * atr)
lowerband = hl2 - (multiplier * atr)
supertrend = pd.Series(index=df.index, dtype=float)
direction = pd.Series(index=df.index, dtype=int)
for i in range(period, len(df)):
if df['close'].iloc[i] > upperband[i-1]:
supertrend.iloc[i] = lowerband[i]
direction.iloc[i] = 1 # Bullish
elif df['close'].iloc[i] < lowerband[i-1]:
supertrend.iloc[i] = upperband[i]
direction.iloc[i] = -1 # Bearish
else:
supertrend.iloc[i] = supertrend.iloc[i-1]
direction.iloc[i] = direction.iloc[i-1]
return supertrend, direction
df['SuperTrend'], df['ST_Direction'] = supertrend(df)
```
---
## Momentum Indicators
### Relative Strength Index (RSI)
```python
rsi = talib.RSI(close_prices, timeperiod=14)
df['RSI'] = rsi
# RSI signals
df['RSI_Signal'] = np.where(df['RSI'] < 30, 'OVERSOLD',
np.where(df['RSI'] > 70, 'OVERBOUGHT', 'NEUTRAL'))
# RSI divergence detection
def detect_rsi_divergence(df, lookback=14):
"""Detect bullish/bearish RSI divergence."""
price_low = df['close'].rolling(lookback).min()
price_high = df['close'].rolling(lookback).max()
rsi_low = df['RSI'].rolling(lookback).min()
rsi_high = df['RSI'].rolling(lookback).max()
# Bullish divergence: price makes lower low, RSI makes higher low
bullish = (df['close'] == price_low) & (df['RSI'] > rsi_low.shift(lookback))
# Bearish divergence: price makes higher high, RSI makes lower high
bearish = (df['close'] == price_high) & (df['RSI'] < rsi_high.shift(lookback))
return bullish, bearish
df['Bullish_Div'], df['Bearish_Div'] = detect_rsi_divergence(df)
```
### MACD (Moving Average Convergence Divergence)
```python
macd, signal, hist = talib.MACD(
close_prices,
fastperiod=12,
slowperiod=26,
signalperiod=9
)
df['MACD'] = macd
df['MACD_Signal'] = signal
df['MACD_Hist'] = hist
# MACD crossover signals
df['MACD_Cross'] = np.where(
(df['MACD'] > df['MACD_Signal']) & (df['MACD'].shift(1) <= df['MACD_Signal'].shift(1)),
'BUY',
np.where(
(df['MACD'] < df['MACD_Signal']) & (df['MACD'].shift(1) >= df['MACD_Signal'].shift(1)),
'SELL',
'HOLD'
)
)
```
### Stochastic Oscillator
```python
slowk, slowd = talib.STOCH(
high_prices,
low_prices,
close_prices,
fastk_period=14,
slowk_period=3,
slowk_matype=0,
slowd_period=3,
slowd_matype=0
)
df['Stoch_K'] = slowk
df['Stoch_D'] = slowd
# Stochastic signals
df['Stoch_Signal'] = np.where(
(df['Stoch_K'] < 20) & (df['Stoch_K'] > df['Stoch_D']),
'BUY',
np.where(
(df['Stoch_K'] > 80) & (df['Stoch_K'] < df['Stoch_D']),
'SELL',
'HOLD'
)
)
```
### ADX (Average Directional Index)
```python
adx = talib.ADX(high_prices, low_prices, close_prices, timeperiod=14)
plus_di = talib.PLUS_DI(high_prices, low_prices, close_prices, timeperiod=14)
minus_di = talib.MINUS_DI(high_prices, low_prices, close_prices, timeperiod=14)
df['ADX'] = adx
df['Plus_DI'] = plus_di
df['Minus_DI'] = minus_di
# Trend strength
df['Trend_Strength'] = np.where(df['ADX'] > 25, 'STRONG',
np.where(df['ADX'] > 20, 'MODERATE', 'WEAK'))
# DI crossover with trend filter
df['ADX_Signal'] = np.where(
(df['Plus_DI'] > df['Minus_DI']) & (df['ADX'] > 25),
'STRONG_BUY',
np.where(
(df['Minus_DI'] > df['Plus_DI']) & (df['ADX'] > 25),
'STRONG_SELL',
'NEUTRAL'
)
)
```
### Williams %R
```python
willr = talib.WILLR(high_prices, low_prices, close_prices, timeperiod=14)
df['Williams_R'] = willr
df['WillR_Signal'] = np.where(df['Williams_R'] < -80, 'OVERSOLD',
np.where(df['Williams_R'] > -20, 'OVERBOUGHT', 'NEUTRAL'))
```
### CCI (Commodity Channel Index)
```python
cci = talib.CCI(high_prices, low_prices, close_prices, timeperiod=20)
df['CCI'] = cci
df['CCI_Signal'] = np.where(df['CCI'] < -100, 'OVERSOLD',
np.where(df['CCI'] > 100, 'OVERBOUGHT', 'NEUTRAL'))
```
---
## Volatility Indicators
### ATR (Average True Range)
```python
atr = talib.ATR(high_prices, low_prices, close_prices, timeperiod=14)
df['ATR'] = atr
df['ATR_Percent'] = (atr / close_prices) * 100
# Volatility classification
df['Volatility'] = np.where(df['ATR_Percent'] > 2, 'HIGH',
np.where(df['ATR_Percent'] > 1, 'MEDIUM', 'LOW'))
# ATR-based stop loss
df['Stop_Loss'] = df['close'] - (2 * df['ATR']) # 2x ATR trailing stop
```
### Keltner Channel
```python
def keltner_channel(df, ema_period=20, atr_period=10, multiplier=2):
"""Calculate Keltner Channel."""
ema = talib.EMA(df['close'].values, timeperiod=ema_period)
atr = talib.ATR(df['high'].values, df['low'].values, df['close'].values, timeperiod=atr_period)
upper = ema + (multiplier * atr)
lower = ema - (multiplier * atr)
return upper, ema, lower
df['KC_Upper'], Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.