Dựa trên chiến lược thêm vị trí động


Ngày tạo: 2024-02-20 14:16:30 sửa đổi lần cuối: 2024-02-20 14:16:30
sao chép: 0 Số nhấp chuột: 624
1
tập trung vào
1617
Người theo dõi

Dựa trên chiến lược thêm vị trí động

Tổng quan

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

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

Chiến lược này trước tiên thiết lập tỷ lệ phần trăm đầu tư và phân bổ DCA. Khi mỗi dòng K kết thúc, nó sẽ tính toán tỷ lệ phần trăm phân bổ được điều chỉnh theo biến động giá. Nếu giá tăng, nó sẽ giảm tỷ lệ phần trăm; Nếu giá giảm, nó sẽ tăng tỷ lệ phần trăm.

Bằng cách này, nó có thể kiểm soát rủi ro và có được giá nhập cảnh trung bình thấp hơn khi thị trường biến động. Đồng thời, nó cũng sẽ thống kê giá nhập cảnh trung bình và giá trung bình, để xác định tình hình nhập cảnh hiện tại.

Phân tích lợi thế

Chiến lược này có những ưu điểm sau:

  1. Bạn có thể tăng vị thế động, tăng vị trí khi thị trường giảm, giảm vị trí khi thị trường tăng, do đó kiểm soát rủi ro.

  2. Có giá nhập cảnh trung bình thấp hơn so với giá trung bình, có lợi cho việc thu được lợi nhuận cao hơn.

  3. Trong thị trường bò, bạn có thể nhận được một tỷ lệ lợi nhuận tốt hơn.

  4. Bạn có thể đặt trước số tiền khởi động và tỷ lệ phần trăm DCA, kiểm soát số tiền mỗi lần đặt cược, tránh rủi ro quá lớn.

  5. Cung cấp số liệu thống kê về giá nhập học trung bình và giá trung bình, có thể đánh giá trực quan về giá nhập học.

Phân tích rủi ro

Chiến lược này cũng có một số rủi ro:

  1. Chiến lược này sẽ tiếp tục tăng giá khi thị trường giảm mạnh, có thể dẫn đến tổn thất tài chính lớn. Bạn có thể thiết lập dừng lỗ để kiểm soát rủi ro.

  2. Nếu thị trường tăng nhanh, mức gia tăng của chiến lược này sẽ giảm, có thể bỏ lỡ hầu hết các cơ hội tăng. Khi đó, cần sử dụng các tín hiệu khác để thực hiện LSI nhanh chóng.

  3. Các tham số không được thiết lập đúng cũng có một số rủi ro. Quá nhiều tiền khởi động và tỷ lệ DCA quá cao sẽ làm tăng tổn thất.

Hướng tối ưu hóa

Chiến lược này cũng có thể được tối ưu hóa theo các khía cạnh sau:

  1. Có thể thêm logic dừng lỗ, dừng đặt cược khi giảm mạnh.

  2. Tỷ lệ phần trăm DCA có thể được điều chỉnh theo biến động của tỷ lệ biến động hoặc các chỉ số khác.

  3. Các mô hình học máy có thể được thêm vào để dự đoán biến động giá và hướng dẫn các quyết định đặt hàng.

  4. Có thể kết hợp với các chỉ số kỹ thuật khác để đánh giá cấu trúc thị trường, dừng đặt cược tại các điểm biến đổi cấu trúc.

  5. Bạn có thể thêm mô-đun quản lý tiền để điều chỉnh động số tiền mỗi lần đặt hàng theo tình hình tài khoản của bạn.

Tóm tắt

Chiến lược này là một chiến lược gia tăng vị thế động rất thực tế. Nó có thể điều chỉnh vị trí một cách linh hoạt theo biến động của thị trường, để có được giá nhập cảnh trung bình thấp hơn trong thị trường bò. Đồng thời, nó có cài đặt tham số tích hợp để kiểm soát rủi ro.

Mã nguồn chiến lược
/*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)