Chiến lược theo dõi xu hướng lợi nhuận nhiều lớp trung bình động biến thiên


Ngày tạo: 2025-09-10 11:14:13 sửa đổi lần cuối: 2025-11-21 11:55:25
sao chép: 0 Số nhấp chuột: 29
2
tập trung vào
319
Người theo dõi

Chiến lược theo dõi xu hướng lợi nhuận nhiều lớp trung bình động biến thiên

Tổng quan

Chiến lược này là một hệ thống theo dõi xu hướng kết hợp các chỉ số động trung bình của chỉ số biến thể (VIDYA) với các dải Bollinger (Bollinger Bands) và tích hợp các cơ chế dừng nhiều tầng. Không giống như các chiến lược xu hướng truyền thống, hệ thống này sử dụng một cách thu lợi nhuận thích ứng hơn để phân biệt các vị trí trống nhiều hơn thông qua chỉ số ATR và mục tiêu phần trăm độc đáo.

Nguyên tắc chiến lược

Cốt lõi của chiến lược là sử dụng hai chỉ số VIDYA nhanh và chậm để phân tích xu hướng giá cả, đồng thời xem xét sự biến động của thị trường. Công thức tính toán của chỉ số VIDYA là: Tỷ lệ phẳng của α = 2/α + 1 VIDYA (t) = α * k * giá (t) + (1 - α * k) * VIDYA (t-1) Trong đó k = chán động cơ dao động (MO) 100

Brinband làm bộ lọc tỷ lệ dao động: Đường lên = MA + (K * chênh lệch chuẩn) Đường sắt dưới = MA - (K * chênh lệch tiêu chuẩn)

Điều kiện tham gia:

  • Nhiều đầu: Giá phá vỡ VIDYA chậm và VIDYA nhanh xu hướng lên, đồng thời giá phá vỡ dây chuyền Brin trên đường ray
  • Blank: Giá giảm xuống thấp hơn VIDYA chậm và VIDYA nhanh xu hướng giảm, đồng thời giá giảm xuống thấp hơn Brin

Các hệ thống ngăn chặn đa tầng bao gồm:

  1. Dừng dựa trên ATR
  2. Cụm dựa trên tỷ lệ phần trăm
  3. Giao dịch không đầu tư sử dụng nhân để tăng tỷ lệ dừng

Lợi thế chiến lược

  1. Tính linh hoạt: Chỉ số Vidia có thể tự động điều chỉnh theo biến động của thị trường, nhạy cảm hơn so với đường trung bình truyền thống
  2. Quản lý rủi ro tốt: Hệ thống ngăn chặn nhiều lớp có thể khóa lợi nhuận ở các mức giá khác nhau
  3. Phân biệt xử lý: sử dụng chiến lược chặn khác nhau đối với các vị trí trống, phù hợp hơn với đặc điểm của thị trường
  4. Bộ lọc tỷ lệ dao động: Brinband được sử dụng để lọc các tín hiệu đột phá giả
  5. Tính linh hoạt: có thể điều chỉnh các tham số theo các điều kiện thị trường khác nhau

Rủi ro chiến lược

  1. Rủi ro thị trường chấn động: Có thể tạo ra tín hiệu sai lệch trên thị trường ngang
  2. Tác động điểm trượt: Nhiều điểm dừng có thể dẫn đến sai lệch giá thực hiện do điểm trượt
  3. Tùy thuộc tham số: Các tham số có thể cần được điều chỉnh thường xuyên trong các môi trường thị trường khác nhau
  4. Sự phức tạp của hệ thống: nhiều lớp ngăn chặn làm tăng sự phức tạp của chiến lược
  5. Căng thẳng quản lý tài chính: Nhiều lệnh ngừng hoạt động có thể làm tăng khó khăn trong việc quản lý vị trí

Hướng tối ưu hóa chiến lược

  1. Điều chỉnh tham số động: Có thể phát triển hệ thống tham số thích ứng, tự động điều chỉnh theo điều kiện thị trường
  2. Nhận biết môi trường thị trường: thêm mô-đun phán đoán môi trường thị trường, sử dụng các tham số khác nhau trong các điều kiện thị trường khác nhau
  3. Tối ưu hóa dừng lỗ: tăng cơ chế dừng lỗ động và tăng khả năng kiểm soát rủi ro
  4. Bộ lọc tín hiệu: Tăng số lượng giao thông và các chỉ số phụ trợ để tăng độ tin cậy tín hiệu
  5. Quản lý vị trí: Phát triển thuật toán phân bổ vị trí thông minh hơn

Tóm tắt

Chiến lược này tạo ra một hệ thống theo dõi xu hướng toàn diện bằng cách kết hợp tính thích ứng động của chỉ số VIDYA và chức năng lọc tỷ lệ biến động của Brin Belt. Cơ chế chặn nhiều lớp và phương pháp xử lý đa không gian khác biệt, giúp nó có khả năng lợi nhuận và kiểm soát rủi ro tốt. Tuy nhiên, người dùng cần chú ý đến sự thay đổi của môi trường thị trường, điều chỉnh tham số khi thích hợp và xây dựng một hệ thống quản lý tài chính tốt.

Mã nguồn chiến lược
/*backtest
start: 2025-01-01 00:00:00
end: 2025-09-08 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":500000}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PresentTrading

// This strategy, "VIDYA ProTrend Multi-Tier Profit," is a trend-following system that utilizes fast and slow VIDYA indicators 
// to identify entry and exit points based on the direction and strength of the trend. 
// It incorporates Bollinger Bands as a volatility filter and features a multi-step take profit mechanism, 
// with adjustable ATR-based and percentage-based profit targets for both long and short positions. 
// The strategy allows for more aggressive take profit settings for short trades, making it adaptable to varying market conditions.

//@version=5
strategy("VIDYA ProTrend Multi-Tier Profit", overlay=true)


// User-defined inputs
tradeDirection = input.string(title="Trading Direction", defval="Both", options=["Long", "Short", "Both"])
fastVidyaLength = input.int(10, title="Fast VIDYA Length", minval=1)
slowVidyaLength = input.int(30, title="Slow VIDYA Length", minval=1)
minSlopeThreshold = input.float(0.05, title="Minimum VIDYA Slope Threshold", step=0.01)

// Bollinger Bands Inputs
bbLength = input.int(20, title="Bollinger Bands Length", minval=1)
bbMultiplier = input.float(1.0, title="Bollinger Bands Multiplier", step=0.1)

// Multi-Step Take Profit Settings
group_tp = "Multi-Step Take Profit"
useMultiStepTP = input.bool(true, title="Enable Multi-Step Take Profit", group=group_tp)
tp_direction = input.string(title="Take Profit Direction", defval="Both", options=["Long", "Short", "Both"], group=group_tp)
atrLengthTP =  input.int(14, title="ATR Length", group=group_tp)


// ATR-based Take Profit Steps
atrMultiplierTP1 = input.float(2.618, title="ATR Multiplier for TP 1", group=group_tp)
atrMultiplierTP2 = input.float(5.0, title="ATR Multiplier for TP 2", group=group_tp)
atrMultiplierTP3 = input.float(10.0, title="ATR Multiplier for TP 3", group=group_tp)

// Short Position Multiplier for Take Profit Percentages
shortTPPercentMultiplier = input.float(1.5, title="Short TP Percent Multiplier", group=group_tp)

// Percentage-based Take Profit Steps (Long)
tp_level_percent1 = input.float(title="Take Profit Level 1 (%)", defval=3.0, group=group_tp)
tp_level_percent2 = input.float(title="Take Profit Level 2 (%)", defval=8.0, group=group_tp)
tp_level_percent3 = input.float(title="Take Profit Level 3 (%)", defval=17.0, group=group_tp)

// Percentage-based Take Profit Allocation (Long)
tp_percent1 = input.float(title="Take Profit Percent 1 (%)", defval=12.0, group=group_tp)
tp_percent2 = input.float(title="Take Profit Percent 2 (%)", defval=8.0, group=group_tp)
tp_percent3 = input.float(title="Take Profit Percent 3 (%)", defval=10.0, group=group_tp)

// ATR-based Take Profit Percent Allocation (Long)
tp_percentATR1 = input.float(title="ATR TP Percent 1 (%)", defval=10.0, group=group_tp)
tp_percentATR2 = input.float(title="ATR TP Percent 2 (%)", defval=10.0, group=group_tp)
tp_percentATR3 = input.float(title="ATR TP Percent 3 (%)", defval=10.0, group=group_tp)

// Short position percentage allocations using the multiplier
tp_percent1_short = tp_percent1 * shortTPPercentMultiplier
tp_percent2_short = tp_percent2 * shortTPPercentMultiplier
tp_percent3_short = tp_percent3 * shortTPPercentMultiplier

tp_percentATR1_short = tp_percentATR1 * shortTPPercentMultiplier
tp_percentATR2_short = tp_percentATR2 * shortTPPercentMultiplier
tp_percentATR3_short = tp_percentATR3 * shortTPPercentMultiplier

// VIDYA Calculation Function
calcVIDYA(src, length) =>
    alpha = 2 / (length + 1)
    momm = ta.change(src)
    m1 = momm >= 0.0 ? momm : 0.0
    m2 = momm < 0.0 ? -momm : 0.0
    sm1 = math.sum(m1, length)
    sm2 = math.sum(m2, length)
    chandeMO = nz(100 * (sm1 - sm2) / (sm1 + sm2))
    k = math.abs(chandeMO) / 100
    var float vidya = na
    vidya := na(vidya[1]) ? src : (alpha * k * src + (1 - alpha * k) * vidya[1])
    vidya

// Calculate VIDYAs
fastVIDYA = calcVIDYA(close, fastVidyaLength)
slowVIDYA = calcVIDYA(close, slowVidyaLength)

// Bollinger Bands Calculation
[bbUpper, bbBasis, bbLower] = ta.bb(close, bbLength, bbMultiplier)

// Manual Slope Calculation (price difference over time)
calcSlope(current, previous, length) =>
    (current - previous) / length

// Slope of fast and slow VIDYA (comparing current value with value 'length' bars ago)
fastSlope = calcSlope(fastVIDYA, fastVIDYA[fastVidyaLength], fastVidyaLength)
slowSlope = calcSlope(slowVIDYA, slowVIDYA[slowVidyaLength], slowVidyaLength)

// Conditions for long entry with Bollinger Bands filter
longCondition = close > slowVIDYA and fastSlope > slowSlope and fastSlope > minSlopeThreshold and slowSlope > 1/2*minSlopeThreshold and close > bbUpper

// Conditions for short entry with Bollinger Bands filter
shortCondition = close < slowVIDYA and fastSlope < slowSlope and fastSlope < -minSlopeThreshold and slowSlope < -1/2*minSlopeThreshold and close < bbLower

// Exit conditions (opposite crossovers or flat slopes)
exitLongCondition = fastSlope < -minSlopeThreshold and slowSlope < -1/2*minSlopeThreshold or shortCondition
exitShortCondition = fastSlope > minSlopeThreshold and slowSlope > 1/2*minSlopeThreshold or longCondition

// Entry and Exit logic with trading direction
if (longCondition) and (strategy.position_size == 0) and (tradeDirection == "Long" or tradeDirection == "Both")
    strategy.order("Long", strategy.long)

if (exitLongCondition) and strategy.position_size > 0 and (tradeDirection == "Long" or tradeDirection == "Both")
    strategy.close("Long")

if (shortCondition) and (strategy.position_size == 0) and (tradeDirection == "Short" or tradeDirection == "Both")
    strategy.order("Short", strategy.short)

if (exitShortCondition) and strategy.position_size < 0 and (tradeDirection == "Short" or tradeDirection == "Both")
    strategy.close("Short")


if useMultiStepTP
    if strategy.position_size > 0 and (tp_direction == "Long" or tp_direction == "Both")
        // ATR-based Take Profit (Long)
        tp_priceATR1_long = strategy.position_avg_price + atrMultiplierTP1 * ta.atr(atrLengthTP)
        tp_priceATR2_long = strategy.position_avg_price + atrMultiplierTP2 * ta.atr(atrLengthTP)
        tp_priceATR3_long = strategy.position_avg_price + atrMultiplierTP3 * ta.atr(atrLengthTP)
        
        // Percentage-based Take Profit (Long)
        tp_pricePercent1_long = strategy.position_avg_price * (1 + tp_level_percent1 / 100)
        tp_pricePercent2_long = strategy.position_avg_price * (1 + tp_level_percent2 / 100)
        tp_pricePercent3_long = strategy.position_avg_price * (1 + tp_level_percent3 / 100)

        // Execute ATR-based exits for Long
        strategy.exit("TP ATR 1 Long", from_entry="Long", qty_percent=tp_percentATR1, limit=tp_priceATR1_long)
        strategy.exit("TP ATR 2 Long", from_entry="Long", qty_percent=tp_percentATR2, limit=tp_priceATR2_long)
        strategy.exit("TP ATR 3 Long", from_entry="Long", qty_percent=tp_percentATR3, limit=tp_priceATR3_long)
        
        // Execute Percentage-based exits for Long
        strategy.exit("TP Percent 1 Long", from_entry="Long", qty_percent=tp_percent1, limit=tp_pricePercent1_long)
        strategy.exit("TP Percent 2 Long", from_entry="Long", qty_percent=tp_percent2, limit=tp_pricePercent2_long)
        strategy.exit("TP Percent 3 Long", from_entry="Long", qty_percent=tp_percent3, limit=tp_pricePercent3_long)

    if strategy.position_size < 0 and (tp_direction == "Short" or tp_direction == "Both")
        // ATR-based Take Profit (Short) - using the same ATR levels as long
        tp_priceATR1_short = strategy.position_avg_price - atrMultiplierTP1 * ta.atr(atrLengthTP)
        tp_priceATR2_short = strategy.position_avg_price - atrMultiplierTP2 * ta.atr(atrLengthTP)
        tp_priceATR3_short = strategy.position_avg_price - atrMultiplierTP3 * ta.atr(atrLengthTP)
        
        // Percentage-based Take Profit (Short) - using the same levels, but more aggressive percentages
        tp_pricePercent1_short = strategy.position_avg_price * (1 - tp_level_percent1 / 100)
        tp_pricePercent2_short = strategy.position_avg_price * (1 - tp_level_percent2 / 100)
        tp_pricePercent3_short = strategy.position_avg_price * (1 - tp_level_percent3 / 100)

        // Execute ATR-based exits for Short (using the percentage multiplier for short)
        strategy.exit("TP ATR 1 Short", from_entry="Short", qty_percent=tp_percentATR1_short, limit=tp_priceATR1_short)
        strategy.exit("TP ATR 2 Short", from_entry="Short", qty_percent=tp_percentATR2_short, limit=tp_priceATR2_short)
        strategy.exit("TP ATR 3 Short", from_entry="Short", qty_percent=tp_percentATR3_short, limit=tp_priceATR3_short)
        
        // Execute Percentage-based exits for Short
        strategy.exit("TP Percent 1 Short", from_entry="Short", qty_percent=tp_percent1_short, limit=tp_pricePercent1_short)
        strategy.exit("TP Percent 2 Short", from_entry="Short", qty_percent=tp_percent2_short, limit=tp_pricePercent2_short)
        strategy.exit("TP Percent 3 Short", from_entry="Short", qty_percent=tp_percent3_short, limit=tp_pricePercent3_short)
// Plot VIDYAs
plot(fastVIDYA, color=color.green, title="Fast VIDYA")
plot(slowVIDYA, color=color.red, title="Slow VIDYA")