
Chiến lược này sử dụng đường 20 và đường 60 của đường trung bình di chuyển để tạo ra tín hiệu mua và bán. Khi giá tăng vượt qua đường 20 ngày, hãy làm nhiều; Khi giá giảm vượt qua đường 20 ngày, hãy giữ vị trí bằng phẳng.
Các tín hiệu giao dịch và quy tắc tạo ra chiến lược này. Khi giá vượt qua đường trung bình, nó cho thấy xu hướng bắt đầu, bạn có thể theo dõi xu hướng nhiều hơn; Khi giá giảm xuống đường trung bình, nó cho thấy xu hướng kết thúc, và khi đó là lựa chọn chính xác.
Phương pháp giải quyết rủi ro:
Chiến lược tổng thể là một chiến lược chéo đường trung bình di chuyển kép điển hình. Ý tưởng cốt lõi là theo dõi xu hướng, thiết lập vị trí xu hướng khi giá phá vỡ đường trung bình. Chiến lược đơn giản, thực tế và dễ thực hiện.
/*backtest
start: 2022-12-01 00:00:00
end: 2023-12-07 00:00:00
period: 1d
basePeriod: 1h
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/
// © Astorhsu
//@version=5
strategy("Astor SMA20/60 TW", overlay=true, margin_long=100, margin_short=100)
backtest_year = input(2018, title='backtest_year') //回測開始年分
backtest_month = input.int(01, title='backtest_month', minval=1, maxval=12) //回測開始月份
backtest_day = input.int(01, title='backtest_day', minval=1, maxval=31) //回測開始日期
start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00) //回測開始的時間函數
//Indicators
sma20 = ta.sma(close,20)
sma60 = ta.sma(close,60)
plot(sma20, color=color.green, title="sma(20)")
plot(sma60, color=color.red, title="sma(60)")
//進場條件
longCondition = ta.crossover(close, ta.sma(close, 20))
if (longCondition) and time >= start_time
strategy.entry("open long20", strategy.long, qty=1, comment="站上m20做多")
shortCondition = ta.crossunder(close, ta.sma(close, 20))
if (shortCondition) and time >= start_time
strategy.close("open long20",comment="跌破m20平倉", qty=1)
longCondition1 = ta.crossover(close, ta.sma(close, 60))
if (longCondition1) and time >= start_time
strategy.entry("open long60", strategy.long, qty=1, comment="站上m60做多")
shortCondition1 = ta.crossunder(close, ta.sma(close, 60))
if (shortCondition1) and time >= start_time
strategy.close("open long60",comment="跌破m60平倉", qty=1)