Chiến lược phá vỡ đường Dongxian là một chiến lược theo dõi xu hướng dựa trên đường Dongxian. Chiến lược này sử dụng giá cao nhất và giá thấp nhất trong các chu kỳ khác nhau để xác định điểm vào và điểm dừng của các đầu nhiều đầu và đầu trống.
Quy tắc nhập cảnh của chiến lược là: khi giá phá vỡ giá cao nhất trong chu kỳ nhất định (ví dụ: 20 ngày), hãy làm nhiều; khi giá phá vỡ giá thấp nhất trong chu kỳ nhất định (ví dụ: 10 ngày), hãy làm trống.
Quy tắc EXIT là: nhiều vị trí đầu vào dừng lại ở đường giữa hoặc đường dưới; vị trí đầu trống dừng lại ở đường giữa hoặc đường trên. đường giữa là giá trung bình của giá cao nhất và giá thấp nhất trong một chu kỳ nhất định (ví dụ: 10 ngày).
Giả sử giao dịch là BTCUSDT, các tham số được đặt như sau:
Vì vậy, các quy tắc nhập cảnh và dừng lỗ là:
Bằng cách điều chỉnh động các tham số của chu kỳ đầu vào và dừng lỗ, bạn có thể tối ưu hóa trong các chu kỳ thị trường khác nhau để có được lợi nhuận tốt hơn trong các tình huống xu hướng.
Chiến lược phá vỡ đường hầm TCM được sử dụng để đánh giá hướng xu hướng bằng cách phá vỡ, điểm dừng là điểm trung bình của đường hầm hoặc lên xuống đường, có thể kiểm soát rủi ro hiệu quả. Bằng cách thiết lập tham số tối ưu hóa, bạn có thể nâng cao tỷ lệ nắm bắt chiến lược trong tình huống xu hướng.
/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Donchian Channel Strategy", overlay=true, default_qty_type= strategy.percent_of_equity, initial_capital = 1000, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.036)
//Long optopns
buyPeriodEnter = input(10, "Channel Period for Long enter position")
buyPeriodExit = input(10, "Channel Period for Long exit position")
isMiddleBuy = input(true, "Is exit on Base Line? If 'no' - exit on bottom line")
takeProfitBuy = input(2.5, "Take Profit (%) for Long position")
isBuy = input(true, "Allow Long?")
//Short Options
sellPeriodEnter = input(20, "Channel Period for Short enter position")
sellPeriodExit = input(20, "Channel Period for Short exit position")
isMiddleSell = input(true, "Is exit on Base Line? If 'no' - exit on upper line")
takeProfitSell = input(2.5, "Take Profit (%) for Short position")
isSell = input(true, "Allow Short?")
// Test Start
startYear = input(2005, "Test Start Year")
startMonth = input(1, "Test Start Month")
startDay = input(1, "Test Start Day")
startTest = timestamp(startYear,startMonth,startDay,0,0)
//Test End
endYear = input(2050, "Test End Year")
endMonth = input(12, "Test End Month")
endDay = input(30, "Test End Day")
endTest = timestamp(endYear,endMonth,endDay,23,59)
timeRange = time > startTest and time < endTest ? true : false
// Long&Short Levels
BuyEnter = highest(buyPeriodEnter)
BuyExit = isMiddleBuy ? ((highest(buyPeriodExit) + lowest(buyPeriodExit)) / 2): lowest(buyPeriodExit)
SellEnter = lowest(sellPeriodEnter)
SellExit = isMiddleSell ? ((highest(sellPeriodExit) + lowest(sellPeriodExit)) / 2): highest(sellPeriodExit)
// Plot Data
plot(BuyEnter, style=plot.style_line, linewidth=2, color=color.blue, title="Buy Enter")
plot(BuyExit, style=plot.style_line, linewidth=1, color=color.blue, title="Buy Exit", transp=50)
plot(SellEnter, style=plot.style_line, linewidth=2, color=color.red, title="Sell Enter")
plot(SellExit, style=plot.style_line, linewidth=1, color=color.red, title="Sell Exit", transp=50)
// Calc Take Profits
TakeProfitBuy = 0.0
TakeProfitSell = 0.0
if strategy.position_size > 0
TakeProfitBuy := strategy.position_avg_price*(1 + takeProfitBuy/100)
if strategy.position_size < 0
TakeProfitSell := strategy.position_avg_price*(1 - takeProfitSell/100)
// Long Position
if isBuy and timeRange
strategy.entry("Long", strategy.long, stop = BuyEnter, when = strategy.position_size == 0)
strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TakeProfitBuy, when = strategy.position_size > 0)
// Short Position
if isSell and timeRange
strategy.entry("Short", strategy.short, stop = SellEnter, when = strategy.position_size == 0)
strategy.exit("Short Exit", "Short", stop=SellExit, limit = TakeProfitSell, when = strategy.position_size < 0)
// Close & Cancel when over End of the Test
if time > endTest
strategy.close_all()
strategy.cancel_all()