Xu hướng MA nhiều khung thời gian theo chiến lược

Tác giả:ChaoZhang, Ngày: 2024-01-04 17:43:17
Tags:

img

Tổng quan

Chiến lược này dựa trên crossover trung bình động nhiều khung thời gian để theo dõi xu hướng trung hạn dài hạn. Nó áp dụng vị trí kim tự tháp để theo đuổi tăng và đạt được tăng trưởng vốn theo cấp số nhân. Ưu điểm lớn nhất là có thể nắm bắt xu hướng trung hạn dài hạn và mục tiêu kim tự tháp theo lô và giai đoạn để có được lợi nhuận dư thừa.

Chiến lược logic

  1. Xây dựng nhiều khung thời gian dựa trên MA 9 ngày, MA 100 ngày và MA 200 ngày.
  2. Tạo tín hiệu mua khi MA ngắn hơn vượt qua MA dài hơn.
  3. Nhập 7 mục kim tự tháp theo giai đoạn. Kiểm tra các vị trí hiện có trước khi thêm mục mới, ngừng kim tự tháp khi 6 vị trí đã mở.
  4. Đặt cố định 3% TP/SL để kiểm soát rủi ro.

Ở trên là logic giao dịch cơ bản.

Ưu điểm

  1. Hiệu quả bắt được xu hướng trung dài hạn và tận hưởng tăng trưởng theo cấp số nhân.
  2. Crossover MA nhiều khung thời gian tránh tiếng ồn ngắn hạn.
  3. TP/SL cố định kiểm soát rủi ro cho mỗi vị trí.
  4. Nhập kim tự tháp theo lô để có được lợi nhuận dư thừa.

Rủi ro và giải pháp

  1. Rủi ro mất mát lớn nếu không cắt giảm lỗ trong sự đảo ngược xu hướng.
  2. Rủi ro gọi ký quỹ nếu mất mát vượt quá mức chấp nhận.
  3. Rủi ro mất hơn 700% nếu xu hướng giảm mạnh.

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

  1. Kiểm tra các kết hợp MA khác nhau để tìm các thông số tối ưu.
  2. Tối ưu hóa số lượng các giai đoạn kim tự tháp. Kiểm tra để tìm số tốt nhất.
  3. Kiểm tra các thiết lập TP / SL cố định.

Tóm lại

Chiến lược này rất phù hợp để bắt được xu hướng trung dài hạn. Các mục nhập kim tự tháp theo lô có thể đạt được tỷ lệ rủi ro-lợi nhuận rất cao. Ngoài ra còn có một số rủi ro hoạt động, nên được kiểm soát bằng cách điều chỉnh tham số. Nhìn chung đây là một chiến lược hứa hẹn đáng để xác minh giao dịch trực tiếp và tối ưu hóa hơn nữa.


/*backtest
start: 2023-12-27 00:00:00
end: 2024-01-03 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © Coinrule
    
//@version=3
strategy(shorttitle='Pyramiding Entry On Early Trends',title='Pyramiding Entry On Early Trends (by Coinrule)', overlay=false, pyramiding= 7, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.1)
    
    
//Backtest dates
fromMonth = input(defval = 1,  title = "From Month")     
fromDay   = input(defval = 10,    title = "From Day")       
fromYear  = input(defval = 2020, title = "From Year")       
thruMonth = input(defval = 1,    title = "Thru Month")     
thruDay   = input(defval = 1,    title = "Thru Day")     
thruYear  = input(defval = 2112, title = "Thru Year")       
    
showDate  = input(defval = true, title = "Show Date Range")
    
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => true       // create function "within window of time"
    
    
//MA inputs and calculations
inSignal=input(9, title='MAfast')
inlong1=input(100, title='MAslow')
inlong2=input(200, title='MAlong')
    
MAfast= sma(close, inSignal)
MAslow= sma(close, inlong1)
MAlong= sma(close, inlong2)
    
    
Bullish = crossover(close, MAfast) 
    
longsignal = (Bullish and MAfast > MAslow and MAslow < MAlong and window())
    
//set take profit
    
ProfitTarget_Percent = input(3)
Profit_Ticks = (close * (ProfitTarget_Percent / 100)) / syminfo.mintick
    
//set take profit
    
LossTarget_Percent = input(3)
Loss_Ticks = (close * (LossTarget_Percent / 100)) / syminfo.mintick
    
    
//Order Placing
    
strategy.entry("Entry 1", strategy.long, when = (strategy.opentrades == 0) and longsignal)
    
strategy.entry("Entry 2", strategy.long, when = (strategy.opentrades == 1) and longsignal)
        
strategy.entry("Entry 3", strategy.long, when = (strategy.opentrades == 2) and longsignal)
    
strategy.entry("Entry 4", strategy.long, when = (strategy.opentrades == 3) and longsignal)
    
strategy.entry("Entry 5", strategy.long, when = (strategy.opentrades == 4) and longsignal)
        
strategy.entry("Entry 6", strategy.long, when = (strategy.opentrades == 5) and longsignal)
        
strategy.entry("Entry 7", strategy.long, when = (strategy.opentrades == 6) and longsignal)
    
    
    
if (strategy.position_size > 0)
    strategy.exit(id="Exit 1", from_entry = "Entry 1", profit = Profit_Ticks, loss = Loss_Ticks)
    strategy.exit(id="Exit 2", from_entry = "Entry 2", profit = Profit_Ticks, loss = Loss_Ticks)
    strategy.exit(id="Exit 3", from_entry = "Entry 3", profit = Profit_Ticks, loss = Loss_Ticks)
    strategy.exit(id="Exit 4", from_entry = "Entry 4", profit = Profit_Ticks, loss = Loss_Ticks)
    strategy.exit(id="Exit 5", from_entry = "Entry 5", profit = Profit_Ticks, loss = Loss_Ticks)
    strategy.exit(id="Exit 6", from_entry = "Entry 6", profit = Profit_Ticks, loss = Loss_Ticks)
    strategy.exit(id="Exit 7", from_entry = "Entry 7", profit = Profit_Ticks, loss = Loss_Ticks)
     


Thêm nữa