Chiến lược xu hướng dựa trên sự giao nhau của EMA


Ngày tạo: 2023-09-15 11:51:34 sửa đổi lần cuối: 2023-09-15 11:51:34
sao chép: 0 Số nhấp chuột: 767
1
tập trung vào
1617
Người theo dõi

Trong bài viết này, chúng tôi sẽ giới thiệu chi tiết về một chiến lược theo dõi xu hướng sử dụng EMA trung bình để tạo ra tín hiệu giao dịch. Chiến lược này sẽ cải thiện sự ổn định của chiến lược bằng cách tối ưu hóa các tham số trung bình.

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

Chiến lược này theo những quy tắc cốt lõi sau:

  1. Cài đặt đường thẳng EMA và đường chậm EMA, đường thẳng phản ứng với sự thay đổi giá, đường chậm đánh giá xu hướng;

  2. Theo các chuyên gia, việc sử dụng dây chuyền nhanh sẽ làm nhiều việc hơn, còn dây chuyền chậm sẽ không có việc gì.

  3. Thiết lập tỷ lệ tham số EMA, chu kỳ đường chậm ≥ đường nhanh gấp 3 lần, để giảm tín hiệu giả;

  4. Có thể chọn chỉ làm nhiều mô hình để tránh giao dịch ngược.

  5. Có thể tùy chỉnh chu kỳ đánh giá để thử nghiệm tối ưu hóa tham số.

Bằng cách điều chỉnh các tham số đường trung bình của EMA, bạn có thể tăng sự ổn định và khóa cơ hội giao dịch theo xu hướng trong khi vẫn giữ được sự nhạy cảm.

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

Lợi thế lớn nhất của chiến lược này là các quy tắc đơn giản, dễ thực hiện và phù hợp với các nhà giao dịch có giới hạn thời gian.

Một lợi thế khác là có thể giảm các giao dịch vô hiệu thường xuyên bằng cách tối ưu hóa tham số.

Cuối cùng, bạn có thể chọn chỉ làm nhiều mô hình, không cần giao dịch ngược, phù hợp với các loại như thị trường chứng khoán.

Ba, rủi ro tiềm ẩn

Tuy nhiên, chiến lược này cũng có những vấn đề:

Đầu tiên, đường trung bình EMA có vấn đề về sự chậm trễ và có thể bỏ lỡ điểm tốt nhất.

Thứ hai, thiết lập tham số không chính xác có thể dẫn đến việc lọc quá mức.

Cuối cùng, các cơ chế ngăn chặn và ngăn chặn thiệt hại cần được cải thiện và tối ưu hóa.

Bốn nội dung, tóm tắt

Bài viết này mô tả chi tiết một chiến lược giao dịch xu hướng dựa trên đường trung bình EMA. Nó tăng sự ổn định của chiến lược bằng cách điều chỉnh các tham số đường trung bình. Chiến lược này dễ sử dụng và các quy tắc đơn giản và rõ ràng, nhưng cũng cần lưu ý các vấn đề như kiểm soát đường trung bình.

Mã nguồn chiến lược
/*backtest
start: 2023-08-15 00:00:00
end: 2023-09-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gregoirejohnb
//
// Moving average crossover systems measure drift in the market. They are great strategies for time-limited people.
// So, why don't more people use them?
// 
// I think it's due to poor choice in choosing EMA lengths: Market Wizard Ed Seykota has a guideline for moving average crossovers: the slow line should be at least 3x the fast line.
// This removes a lot of the whipsaws inherent in moving average systems, which means greater profitability.
// His other piece of advice: long-only strategies are best in stock markets where there's a lot more upside potential.
//
// Using these simple rules, we can reduce a lot of the whipsaws and low profitability trades! This strategy was made so you can see for yourself before trading.
//
// === HOW TO USE THIS INDICATOR ===
// 1) Choose your market and timeframe.
// 2) Choose the length.
// 3) Choose the multiplier.
// 4) Choose if the strategy is long-only or bidirectional. 
//
// Don't overthink the above! We don't know the best answers, that's why this strategy exists! We're going to test and find out.
//  After you find a good combination, set up an alert system with the default Exponential Moving Average indicators provided by TradingView.
//
// === TIPS ===
// Increase the multiplier to reduce whipsaws (back and forth trades).
// Increase the length to take fewer trades, decrease the length to take more trades.
// Try a Long-Only strategy to see if that performs better.
//
strategy(title="EMA Crossover Strategy", shorttitle="EMA COS", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10, currency=currency.USD,commission_type=strategy.commission.percent,commission_value=0.1)

// === GENERAL INPUTS ===
//strategy start date
start_year = input(defval=2020, title="Backtest Start Year")

// === LOGIC ===
length = input(type=input.integer,defval=20,minval=1,title="Length")
ratio = input(type=input.integer,defval=3,title="Multiplier (3x length, 4x length, etc)",options=[3,4,5,6,7,8,9,10])
longOnly = input(type=input.bool,defval=false,title="Long Only")
fast = ema(hl2,length)
slow = ema(hl2,length * ratio)
plot(fast,linewidth=2,color=color.orange,title="Fast")
plot(slow,linewidth=2,color=color.blue,title="Slow")

longEntry = crossover(fast,slow)
shortEntry = crossunder(fast,slow)

plotshape(longEntry ? close : na,style=shape.triangleup,color=color.green,location=location.belowbar,size=size.small,title="Long Triangle")
plotshape(shortEntry and not longOnly ? close : na,style=shape.triangledown,color=color.red,location=location.abovebar,size=size.small,title="Short Triangle")
plotshape(shortEntry and longOnly ? close : na,style=shape.xcross,color=color.black,location=location.abovebar,size=size.small,title="Exit Sign")

// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() =>
    crossover(fast,slow) and 
       time > timestamp(start_year, 1, 1, 01, 01)
exitLong() =>
    longOnly and crossunder(fast,slow)
strategy.entry(id="Long", long=strategy.long, when=enterLong())
strategy.close(id="Long", when=exitLong())
// === STRATEGY - SHORT POSITION EXECUTION ===
enterShort() =>
    not longOnly and crossunder(fast,slow) and 
       time > timestamp(start_year, 1, 1, 01, 01)
exitShort() =>
    false
strategy.entry(id="Short", long=strategy.short, when=enterShort())
strategy.close(id="Short", when=exitShort())