Indicators
QuantConnect tích hợp sẵn 100+ indicators. Indicators được quản lý bởi Indicator Registry và tự động cập nhật khi có dữ liệu mới.
Indicators Có Sẵn
| Nhóm | Ví dụ |
|---|---|
| Trend | SMA, EMA, MACD, ADX, Parabolic SAR |
| Momentum | RSI, Stochastic, Williams %R, ROC |
| Volatility | Bollinger Bands, ATR, Standard Deviation |
| Volume | OBV, MFI, Volume Profile |
| Statistical | Correlation, Beta, Linear Regression |
Sử Dụng Indicator
python
def Initialize(self):
# 1. Đăng ký indicator — tự động cập nhật
self.sma = self.SMA("SPY", 50, Resolution.Daily)
self.rsi = self.RSI("SPY", 14, Resolution.Daily)
self.bb = self.BB("SPY", 20, 2, Resolution.Daily)
# 2. Warm-up đủ bar cho indicator dài nhất
self.SetWarmUp(200)
def OnData(self, data):
if self.IsWarmingUp:
return # Chưa đủ dữ liệu
# 3. Kiểm tra IsReady trước khi dùng
if self.sma.IsReady and self.rsi.IsReady:
if data["SPY"].Close > self.sma.Current.Value:
self.SetHoldings("SPY", 0.5)Manual Update Indicator
python
class MyManualIndicator(QCAlgorithm):
def Initialize(self):
self.sma = SimpleMovingAverage(50)
self.RegisterIndicator("SPY", self.sma, Resolution.Daily)
def OnData(self, data):
# SMA tự động cập nhật qua RegisterIndicator
if self.sma.IsReady:
value = self.sma.Current.ValueCustom Indicator
python
class MyCustomIndicator(PythonIndicator):
def __init__(self):
self.Name = "MyCustomIndicator"
self.Value = 0
def Update(self, input: BaseData) -> bool:
self.Value = input.Close * 2 - input.Open
return True