Chiến lược xây dựng vị trí năng động

Tác giả:ChaoZhang, Ngày: 2024-02-20 14:16:30
Tags:

img

Tổng quan

Ý tưởng chính của chiến lược này là xây dựng một vị trí năng động dựa trên các tín hiệu hệ thống trong một thị trường tăng để kiểm soát rủi ro và có được giá nhập trung bình thấp hơn.

Chiến lược logic

Chiến lược đầu tiên thiết lập vốn khởi đầu và tỷ lệ phần trăm DCA. Khi đóng mỗi thanh, nó tính toán một tỷ lệ phần trăm điều chỉnh dựa trên sự thay đổi giá. Nếu giá tăng, nó giảm tỷ lệ phần trăm. Nếu giá giảm, nó tăng tỷ lệ phần trăm. Điều này cho phép thêm vào vị trí ở mức giá thấp hơn. Sau đó nó tính toán kích thước lệnh dựa trên tỷ lệ phần trăm điều chỉnh và vốn còn lại.

Do đó, nó có thể kiểm soát rủi ro và có được giá nhập trung bình thấp hơn trong khi hành động giá dao động. Trong khi đó, nó theo dõi giá nhập trung bình và giá trung bình để đánh giá tình hình nhập hiện tại.

Phân tích lợi thế

Chiến lược có những lợi thế sau:

  1. Nó có thể tăng quy mô năng động trong vị trí, tăng phân bổ khi giảm và giảm phân bổ khi tăng để kiểm soát rủi ro.

  2. Nó có giá nhập cảnh trung bình thấp hơn so với giá trung bình, cho phép tiềm năng lợi nhuận nhiều hơn.

  3. Nó phù hợp với các thị trường tăng với biến động để có tỷ lệ rủi ro-lợi nhuận tốt hơn.

  4. Nó cho phép đặt trước vốn khởi đầu và tỷ lệ phần trăm DCA để kiểm soát rủi ro kích thước vị trí.

  5. Nó cung cấp thống kê về giá nhập cảnh trung bình và giá trung bình để đánh giá rõ về chất lượng nhập cảnh.

Phân tích rủi ro

Ngoài ra còn có một số rủi ro:

  1. Khi thị trường giảm, nó sẽ tiếp tục tăng vị trí, dẫn đến tổn thất lớn.

  2. Nếu giá tăng nhanh chóng, sự gia tăng sẽ giảm, có thể bỏ lỡ phần lớn sự gia tăng.

  3. Cấu hình tham số không đúng cũng gây ra nguy hiểm. vốn khởi đầu quá mức và tỷ lệ DCA cao sẽ làm tăng lỗ.

Hướng dẫn tối ưu hóa

Một số cách để tối ưu hóa chiến lược:

  1. Thêm logic dừng lỗ để ngừng mở rộng quy mô bán hàng nặng.

  2. Điều chỉnh năng động tỷ lệ DCA dựa trên biến động hoặc các số liệu khác.

  3. Kết hợp các mô hình học máy để dự đoán giá và hướng dẫn các quyết định mở rộng quy mô.

  4. Kết hợp các chỉ số khác để xác định sự thay đổi cấu trúc thị trường để quy mô các điểm thoát.

  5. Thêm các quy tắc quản lý vốn vào các lệnh kích thước động dựa trên giá trị tài khoản.

Kết luận

Đây là một chiến lược mở rộng vị trí rất thực tế. Nó điều chỉnh linh hoạt kích thước vị trí dựa trên biến động giá để đạt được các mục nhập trung bình tốt trong thị trường tăng, trong khi hạn chế rủi ro thông qua các tham số có thể cấu hình. Kết hợp nó với các chỉ số hoặc mô hình khác có thể cải thiện hiệu suất của nó. Nó phù hợp với các nhà đầu tư tìm kiếm lợi nhuận dài hạn.


/*backtest
start: 2024-01-20 00:00:00
end: 2024-02-19 00:00:00
period: 1h
basePeriod: 15m
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/
// © RWCS_LTD

//@version=5
strategy("DCA IN Calculator {RWCS}", overlay=true, pyramiding=999, default_qty_type=strategy.cash, initial_capital=10000, commission_value=0.02)

// User inputs
backtestStartDate = input(timestamp("1 Jan 2024"), 
     title="Start Date", group="Backtest Time Period",
     tooltip="This start date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")
start_date = true
starting_capital = input.float(defval=5000, title="Starting Capital")
dca_allocation_percentage = input.int(defval=10, title="DCA Allocation Percentage")

// Calculate DCA allocation based on price change
price_change_percentage = ((close - close[1]) / close[1]) * 100
adjusted_allocation_percentage = close > close[1] ? dca_allocation_percentage - price_change_percentage : dca_allocation_percentage + price_change_percentage // If price action is negative, increase allocations
adjusted_allocation_percentage1 = dca_allocation_percentage - price_change_percentage // If price action is positive, reduce allocations

// Calculate order size based on adjusted allocation percentage
order_size = (adjusted_allocation_percentage / 100) * starting_capital

// Track remaining capital
var remaining_capital = starting_capital

// Long on the close of every bar
if true
    // Ensure the order size doesn't exceed remaining capital or adjusted allocation
    order_size := math.min(order_size, remaining_capital, adjusted_allocation_percentage / 100 * starting_capital)
    // Ensure order size is not negative
    order_size := math.max(order_size, 0)
    
    strategy.entry("DCA", strategy.long, qty = order_size)
    remaining_capital := remaining_capital - order_size

// Plot average entry price
var float total_entry_price = 0.0
var int total_signals = 0

if start_date
    total_entry_price := total_entry_price + close
    total_signals := total_signals + 1

avg_entry_price = total_entry_price / total_signals

// Calculate and plot median price
var float median_price = na

if start_date
    var float sum_prices = 0.0
    var int num_prices = 0
    
    for i = 0 to bar_index
        if (time[i] >= backtestStartDate)
            sum_prices := sum_prices + close[i]
            num_prices := num_prices + 1
    
    median_price := sum_prices / num_prices

// Reset variables at the start of each day
if (dayofweek != dayofweek[1])
    total_entry_price := 0.0
    total_signals := 0

//table colors
borders_col = color.new(color.black, 90)
top_row_col = color.new(color.gray, 90)
size = input.string(defval='Normal', options=['Tiny', 'Small', 'Normal', 'Large'], title='Table size', inline='design', group='Table Design')
table_size = size == 'Tiny' ? size.tiny : size == 'Small' ? size.small : size == 'Normal' ? size.normal : size == 'Large' ? size.large : na

var tablee = table.new(position=position.top_right, columns=2, rows=3, frame_color=borders_col, frame_width=4, border_color=borders_col, border_width=4)

table.cell(tablee, 0, 0, "Average Entry Price", bgcolor=top_row_col, text_color=color.white, text_size=table_size)
table.cell(tablee, 1, 0, str.tostring(avg_entry_price, '#.##'), text_color=color.white, text_size=table_size)
table.cell(tablee, 0, 1, "Median Price", bgcolor=top_row_col, text_color=color.white, text_size=table_size)
table.cell(tablee, 1, 1, str.tostring(median_price, '#.##'), text_color=color.white, text_size=table_size)
table.cell(tablee, 0, 2, "Remaining Capital", bgcolor=top_row_col, text_color=color.white, text_size=table_size)
table.cell(tablee, 1, 2, str.tostring(remaining_capital, '#.##'), text_color=color.white, text_size=table_size)



Thêm nữa