
Chiến lược phá vỡ giá Z-Score sử dụng chỉ số điểm chuẩn của giá để xác định liệu giá hiện tại có ở trạng thái bất thường hay không, do đó tạo ra tín hiệu giao dịch. Khi điểm chuẩn của giá cao hơn hoặc thấp hơn một ngưỡng nhất định, nó cho thấy giá đã đi vào trạng thái bất thường, khi đó có thể thực hiện hoạt động nhiều hoặc trống.
Chỉ số cốt lõi của chiến lược này là điểm chuẩn của giá (Z-Score), công thức tính toán như sau:
Z_score = (C - SMA(n)) / StdDev(C,n)
Trong đó C là giá đóng cửa, SMA ((n) là đường trung bình di chuyển đơn giản trong n chu kỳ, StdDev ((C, n) là chênh lệch tiêu chuẩn của giá đóng cửa trong n chu kỳ.
Điểm chuẩn phản ánh mức độ lệch của giá hiện tại so với giá trung bình. Khi điểm chuẩn giá lớn hơn một mức độ chênh lệch tích cực nào đó (ví dụ: +2), nó cho thấy giá hiện tại đã cao hơn mức độ chênh lệch tiêu chuẩn 2 so với giá trung bình và thuộc mức độ tương đối cao. Khi nhỏ hơn một mức độ chênh lệch tiêu cực nào đó (ví dụ: -2), nó cho thấy giá hiện tại đã thấp hơn mức độ chênh lệch tiêu chuẩn 2 so với giá trung bình và thuộc mức độ tương đối thấp.
Chiến lược này đầu tiên tính toán điểm chuẩn của giá, sau đó đặt một ngưỡng âm dương (như 0 và 0), tạo ra một tín hiệu mua khi điểm chuẩn cao hơn ngưỡng dương và một tín hiệu bán khi thấp hơn ngưỡng âm.
Chiến lược phá vỡ giá điểm chuẩn đánh giá xem giá hiện tại có ở trạng thái bất thường hay không, giao dịch dựa trên tích cực của điểm chuẩn giá. Chiến lược này đơn giản, dễ dàng, có thể giao dịch hai chiều, nhưng cũng có một số rủi ro. Bằng các phương tiện như tối ưu hóa tham số và dừng lỗ, bạn có thể tăng cường chiến lược này để tạo thành một hệ thống giao dịch định lượng đầy đủ với các chỉ số khác.
/*backtest
start: 2023-11-29 00:00:00
end: 2023-12-04 19:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 18/01/2017
// The author of this indicator is Veronique Valcu. The z-score (z) for a data
// item x measures the distance (in standard deviations StdDev) and direction
// of the item from its mean (U):
// z = (x-StdDev) / U
// A value of zero indicates that the data item x is equal to the mean U, while
// positive or negative values show that the data item is above (x>U) or below
// (x Values of +2 and -2 show that the data item is two standard deviations
// above or below the chosen mean, respectively, and over 95.5% of all data
// items are contained within these two horizontal references (see Figure 1).
// We substitute x with the closing price C, the mean U with simple moving
// average (SMA) of n periods (n), and StdDev with the standard deviation of
// closing prices for n periods, the above formula becomes:
// Z_score = (C - SMA(n)) / StdDev(C,n)
// The z-score indicator is not new, but its use can be seen as a supplement to
// Bollinger bands. It offers a simple way to assess the position of the price
// vis-a-vis its resistance and support levels expressed by the Bollinger Bands.
// In addition, crossings of z-score averages may signal the start or the end of
// a tradable trend. Traders may take a step further and look for stronger signals
// by identifying common crossing points of z-score, its average, and average of average.
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy(title="Z-Score Strategy", shorttitle="Z-Score Strategy")
Period = input(20, minval=1)
Trigger = input(0)
reverse = input(false, title="Trade reverse")
hline(Trigger, color=purple, linestyle=line)
xStdDev = stdev(close, Period)
xMA = sma(close, Period)
nRes = (close - xMA) / xStdDev
pos = iff(nRes > Trigger, 1,
iff(nRes < Trigger, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(nRes, color=blue, title="Z-Score")