Chiến lược này được thiết kế dựa trên nguyên tắc hai đường trung bình. Khi đường trung bình ngắn hạn đi qua đường trung bình dài hạn, hãy làm nhiều hơn; Khi đường trung bình ngắn hạn đi qua đường trung bình dài hạn, hãy cân bằng. Chiến lược này đơn giản và dễ hiểu, phù hợp cho người mới học.
Chiến lược này chủ yếu dựa trên hai chỉ số đường trung bình sma ((close, 14) và sma ((close, 28).
Đầu tiên, hãy xác định đường trung bình dài và ngắn:
short_ma = sma(close, 14)
long_ma = sma(close, 28)
Sau đó, họ sẽ được đánh giá theo cách mà họ đã đánh giá trước trận đấu:
longCondition = crossover(short_ma, long_ma)
shortCondition = crossunder(short_ma, long_ma)
Lưu ý rằng bạn có thể làm nhiều hơn khi bạn sử dụng đường trung bình ngắn hạn:
strategy.entry("Buy", strategy.long, when = longCondition)
Khi đường trung bình ngắn hạn vượt qua đường trung bình dài hạn:
strategy.close_all(when = shortCondition)
Nguyên tắc của chiến lược này rất đơn giản và rõ ràng, sử dụng hai đường cong đồng đều để đánh giá và có khả năng theo dõi xu hướng nhất định.
Chiến lược này có thể được tối ưu hóa theo các khía cạnh sau:
Bạn có thể thử các chu kỳ đường trung bình ngắn hạn và dài hạn khác nhau để tìm kiếm sự kết hợp tốt nhất. Ví dụ: kiểm tra so sánh các tham số như (5, 10), (…, 10, 20), (…, 20, 60).
Các điều kiện lọc như khối lượng giao dịch và chênh lệch giá có thể được thêm vào khi giao dịch ngang hàng, tránh quá nhiều giao dịch trong thị trường biến động.
Thiết lập điểm dừng lỗ hoặc sử dụng đường trung bình làm đường dừng lỗ để kiểm soát tổn thất đơn lẻ.
Có thể kết hợp các chỉ số hỗ trợ như MACD, KDJ để giao dịch kết hợp, tăng hiệu quả chiến lược.
Tìm điểm vào tốt hơn ở gần đường trung bình, thay vì thiết lập vị trí chặt chẽ với đường trung bình. Ví dụ, vào điểm nằm ngoài đường trung bình.
Khái niệm của chiến lược hai đường thẳng đơn giản, người mới bắt đầu sử dụng dễ dàng. Tuy nhiên, chiến lược này nhạy cảm với biến động thị trường, có một số rủi ro mất mát. Chúng ta có thể tăng hiệu quả chiến lược bằng cách tối ưu hóa tham số, thêm điều kiện lọc, thiết lập dừng lỗ và thêm các chỉ số khác. Trong xu hướng mạnh, chiến lược này có thể có hiệu quả tốt.
||
This strategy is designed based on the golden cross and death cross of dual moving averages. It goes long when the short period moving average crosses above the long period moving average, and closes position when the short period moving average crosses below the long period moving average. The strategy is simple and easy to understand, suitable for beginners to learn.
The strategy is mainly based on the sma(close, 14) and sma(close, 28) indicators.
First define the short and long moving averages:
short_ma = sma(close, 14)
long_ma = sma(close, 28)
Then determine entry and exit based on golden cross and death cross:
longCondition = crossover(short_ma, long_ma)
shortCondition = crossunder(short_ma, long_ma)
Go long when the short MA crosses above the long MA:
strategy.entry("Buy", strategy.long, when = longCondition)
Close position when the short MA crosses below the long MA:
strategy.close_all(when = shortCondition)
The logic is simple and clear, utilizing the crossovers of dual MAs to determine entries and exits. It has some trend following capacity.
The strategy can be optimized in the following aspects:
Test different short and long MA periods, such as (5, 10), (10, 20), (20, 60) etc to find the optimal combination.
Add filters like trading volume, price gap etc. near MA crossovers to avoid excessive trades in ranging markets.
Set stop loss price or use MA as stop loss line to control single trade loss.
Add auxiliary indicators like MACD, KDJ etc. to improve strategy performance.
Find better entry points near MAs instead of entering right at the crossover. For example, enter on MA divergence points.
The dual MA strategy is simple for beginners to use. But it is sensitive to market fluctuations and has risks of losses. We can improve it by optimizing parameters, adding filters, incorporating stop loss, combining other indicators etc. It can perform well in strong trends but should be used with caution or proper stop loss in ranging markets.
[/trans]
/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=2
// strategy("Tester", pyramiding = 50, default_qty_type = strategy.cash, default_qty_value = 20, initial_capital = 2000, commission_type = strategy.commission.percent, commission_value = 0.25)
minGainPercent = input(0.6)
gainMultiplier = minGainPercent * 0.01 + 1
longCondition = crossover(sma(close, 14), sma(close, 28))
shortCondition = crossunder(sma(close, 14), sma(close, 28))
avg_protection = input(1)
gain_protection = input(1)
strategy.entry("Buy", strategy.long, when = longCondition and (avg_protection >= 1 ? (na(strategy.position_avg_price) ? true : close <= strategy.position_avg_price) : true))
strategy.close_all(when = shortCondition and (gain_protection >=1 ? (close >= gainMultiplier * strategy.position_avg_price) : true))