
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng dựa trên chỉ số biến động động (VIDYA), kết hợp với biến động ATR để tăng khả năng nhận diện xu hướng và quản lý rủi ro. Chiến lược này có thể bắt kịp các tín hiệu đảo ngược thị trường bằng cách điều chỉnh động tốc độ phản ứng với biến động thị trường, trong khi vẫn duy trì khả năng theo dõi xu hướng. Hệ thống sử dụng VIDYA làm chỉ số cốt lõi, kết hợp với biến động ATR để thiết lập vị trí dừng lỗ động, thực hiện sự thích ứng thông minh với biến động thị trường.
Cốt lõi của chiến lược là sử dụng tính năng động của chỉ số VIDYA để xác định xu hướng. VIDYA động điều chỉnh trọng lượng của trung bình di chuyển bằng cách tính toán biến động động, do đó có độ nhạy khác nhau trong các môi trường thị trường khác nhau. Cụ thể:
Chiến lược này thực hiện theo dõi động và kiểm soát rủi ro của xu hướng thị trường thông qua sự kết hợp của VIDYA và ATR. Ưu điểm cốt lõi của nó là có thể thích ứng với biến động thị trường, đồng thời nắm bắt cơ hội đảo ngược trong khi duy trì khả năng theo dõi xu hướng. Mặc dù có thể gặp rủi ro trong một số môi trường thị trường, chiến lược này vẫn có giá trị thực tế tốt thông qua các biện pháp quản lý rủi ro và tối ưu hóa tham số hợp lý.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-11 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PakunFX
//@version=5
strategy("VIDYA Auto-Trading(Reversal Logic)", overlay=true)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
int vidya_length = input.int(10, "VIDYA Length")
int vidya_momentum = input.int(20, "VIDYA Momentum")
float band_distance = input.float(2, "Distance factor for upper/lower bands", step = 0.1)
float source = input.source(close, "Source")
color up_trend_color = input(#17dfad, "+")
color down_trend_color = input(#dd326b, "-")
bool shadow = input.bool(true, "Shadow")
// Define VIDYA (Variable Index Dynamic Average) function
vidya_calc(src, vidya_length, vidya_momentum) =>
float momentum = ta.change(src)
float sum_pos_momentum = math.sum((momentum >= 0) ? momentum : 0.0, vidya_momentum)
float sum_neg_momentum = math.sum((momentum >= 0) ? 0.0 : -momentum, vidya_momentum)
float abs_cmo = math.abs(100 * (sum_pos_momentum - sum_neg_momentum) / (sum_pos_momentum + sum_neg_momentum))
float alpha = 2 / (vidya_length + 1)
var float vidya_value = 0.0
vidya_value := alpha * abs_cmo / 100 * src + (1 - alpha * abs_cmo / 100) * nz(vidya_value[1])
ta.sma(vidya_value, 15)
// Calculate VIDYA
float vidya_value = vidya_calc(source, vidya_length, vidya_momentum)
// Calculate upper and lower bands
float atr_value = ta.atr(200)
float upper_band = vidya_value + atr_value * band_distance
float lower_band = vidya_value - atr_value * band_distance
// Detect trend direction
bool is_trend_up = na
if ta.crossover(source, upper_band)
is_trend_up := true
if ta.crossunder(source, lower_band)
is_trend_up := false
// Smooth the trend line
float smoothed_value = na
if is_trend_up
smoothed_value := lower_band
if not is_trend_up
smoothed_value := upper_band
// Detect trend change
bool trend_cross_up = ta.crossover(source, upper_band)
bool trend_cross_down = ta.crossunder(source, lower_band)
// ENTRY & EXIT ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
// Long logic: Enter long when down arrow appears and exit when up arrow appears
if trend_cross_up
strategy.close("Sell") // Close short position if any
strategy.entry("Buy", strategy.long)
if trend_cross_down
strategy.close("Buy") // Close long position if any
strategy.entry("Sell", strategy.short)