
Chiến lược này kết hợp hai chỉ số kỹ thuật của kênh Đường Dương và đường trung bình di chuyển đơn giản. Khởi động vị trí cao khi giá phá vỡ đường đi xuống của kênh Đường Dương và cao hơn đường trung bình di chuyển đơn giản, mở vị trí trống khi giá phá vỡ đường đi lên của kênh Đường Dương và thấp hơn đường trung bình di chuyển đơn giản.
Chiến lược kết hợp đường Đường Đường Đường Động với Đường Di chuyển Đơn giản là một khung chiến lược giao dịch định lượng đơn giản và dễ sử dụng. Nó xây dựng logic mở vị trí bằng hai góc độ theo dõi xu hướng và phá vỡ biến động, phù hợp với các giống có xu hướng mạnh. Tuy nhiên, chiến lược này không hoạt động tốt trong thị trường thường xuyên biến động, và các tham số thường ổn định.
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("FBK Donchian Channel Strategy", overlay=true)
// Inputs
donchian_period = input.int(20, title="Donchian Channel Period")
donchian_offset = input.int(1, title="Donchian Channel Offset")
sma_period = input.int(200, title="SMA Period")
start_date = input(timestamp("2023-01-01 00:00 +0000"), title="Start Date")
end_date = input(timestamp("2023-12-31 23:59 +0000"), title="End Date")
trade_type = input.string("Both", title="Trade Type", options=["Buy Only", "Sell Only", "Both"])
// Calculate indicators
donchian_upper = ta.highest(high, donchian_period)[donchian_offset]
donchian_lower = ta.lowest(low, donchian_period)[donchian_offset]
sma = ta.sma(close, sma_period)
// Plot indicators
plot(donchian_upper, color=color.red, title="Donchian Upper")
plot(donchian_lower, color=color.green, title="Donchian Lower")
plot(sma, color=color.blue, title="SMA")
// Helper function to check if within testing period
is_in_testing_period() => true
// Entry conditions
long_condition = low <= donchian_lower and close > sma
short_condition = high >= donchian_upper and close < sma
// Exit conditions
exit_long_condition = high >= donchian_upper
exit_short_condition = low <= donchian_lower
// Open long position
if (is_in_testing_period() and (trade_type == "Buy Only" or trade_type == "Both") and long_condition)
strategy.entry("Long", strategy.long)
// Close long position
if (is_in_testing_period() and exit_long_condition)
strategy.close("Long")
// Open short position
if (is_in_testing_period() and (trade_type == "Sell Only" or trade_type == "Both") and short_condition)
strategy.entry("Short", strategy.short)
// Close short position
if (is_in_testing_period() and exit_short_condition)
strategy.close("Short")
// Close all positions at the end of the testing period
if not is_in_testing_period()
strategy.close_all()