vnstock-js

vnstock-js

Tài LiệuVí DụBài ViếtTài Chính
k

© Copyright 2026

Giới Thiệu
Danh Sách Hàm
Cài Đặt
Kiến Trúc
Hướng Dẫn Sử Dụng Nhanh
CLI
Lịch Sử Phiên Bản
Câu Hỏi Thường Gặp
Cơ Bản
Giao Dịch - Trading
Báo Giá - Quote
Niêm Yết - Listing
Tài Chính - Financials
Chỉ Báo - Indicators
AI Contextv1.4Mới
MCP Serverv1.4Mới
Watchlistv1.4Mới
Sàng Lọc - Screening
Tìm Kiếm - Search
Lịch Giao Dịch - Calendar
Realtime - Thời Gian Thực
QuoteHistory
PriceBoardItem
TopStock
CompanyProfile
ScreenResult
RealtimeQuote
ExchangeRate
  1. Tài Liệu
  2. Key Features
  3. Advanced
  4. Indicators

Chỉ Báo Kỹ Thuật - Indicators

SMA, EMA, RSI, MACD, Bollinger Bands, ATR

Các chỉ báo kỹ thuật là pure functions, nhận QuoteHistory[] và trả kết quả. Từ v1.4 có thêm MACD, Bollinger Bands, ATR.

import { sma, ema, rsi, macd, bollinger, atr } from 'vnstock-js';

SMA - Simple Moving Average

const history = await vnstock.stock.quote.history({
  symbols: ['FPT'], start: '2024-01-01', timeFrame: '1D'
});

const sma20 = sma(history, { period: 20 });
// → [{ date: "2024-01-15", sma: null }, ..., { date: "2024-02-15", sma: 25.6 }, ...]

// SMA theo volume
const volumeSma = sma(history, { period: 10, field: 'volume' });

EMA - Exponential Moving Average

const ema12 = ema(history, { period: 12 });
// → [{ date: "...", ema: null }, ..., { date: "...", ema: 25.8 }, ...]

RSI - Relative Strength Index

const rsi14 = rsi(history); // period mặc định = 14
// → [{ date: "...", rsi: null }, ..., { date: "...", rsi: 65.3 }, ...]

const rsi7 = rsi(history, { period: 7 });

MACD — Moving Average Convergence Divergence (v1.4+)

const macdData = macd(history); // default fast=12, slow=26, signal=9
// → [{ date, macd, signal, histogram }]

const fast = macd(history, { fast: 5, slow: 13, signal: 5 });

histogram > 0 đang bullish, histogram < 0 đang bearish. Crossover khi histogram đổi dấu.

Bollinger Bands (v1.4+)

const bb = bollinger(history); // default period=20, stddev=2
// → [{ date, upper, middle, lower, percentB }]

const bb10 = bollinger(history, { period: 10, stddev: 1.5 });
  • percentB = vị trí giá trong band (0..1+). 1.0 = chạm upper, 0.0 = chạm lower.
  • middle = SMA(period). upper/lower = middle ± stddev × σ.

ATR — Average True Range (v1.4+)

const atr14 = atr(history, 14); // Wilder smoothing
// → [{ date, atr }]

Đo biên độ dao động trung bình. Dùng cho stop-loss dynamic, position sizing theo volatility.

Note:

Giá trị null ở đầu mảng là do chưa đủ dữ liệu để tính. Ví dụ SMA(20) cần tối thiểu 20 điểm dữ liệu, MACD cần ≥26 phiên.

PreviousTài Chính - Financials
NextAI Context

Nội Dung

SMA - Simple Moving AverageEMA - Exponential Moving AverageRSI - Relative Strength IndexMACD — Moving Average Convergence Divergence (v1.4+)Bollinger Bands (v1.4+)ATR — Average True Range (v1.4+)