Skip to content

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ómVí dụ
TrendSMA, EMA, MACD, ADX, Parabolic SAR
MomentumRSI, Stochastic, Williams %R, ROC
VolatilityBollinger Bands, ATR, Standard Deviation
VolumeOBV, MFI, Volume Profile
StatisticalCorrelation, 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.Value

Custom 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

Powered by dautu.tech