
Đây là một chiến lược luân chuyển thông minh dựa trên chu kỳ thời gian, thu lợi nhuận bằng cách giao dịch luân chuyển nhiều luân chuyển trong một chu kỳ thời gian được chỉ định. Chiến lược sử dụng cơ chế quản lý vị trí linh hoạt, có thể tự động điều chỉnh hướng giao dịch theo môi trường thị trường, đồng thời có chức năng kiểm soát rủi ro. Chiến lược này hỗ trợ giao dịch hai chiều nhiều luân chuyển và có thể khởi động tùy chọn mô hình giao dịch luân chuyển, có khả năng thích ứng mạnh mẽ.
Chiến lược kiểm soát giao dịch chủ yếu thông qua chu kỳ thời gian và trạng thái giữ vị trí. Đầu tiên, bằng hàm inActivePeriod () xác định xem có nằm trong phạm vi giao dịch có hiệu lực gần nhất của 500 đường K hay không. Trong phạm vi có hiệu lực, chiến lược quyết định hành vi giao dịch dựa trên các biến số như trạng thái giữ vị trí (positionHeld), thời gian giữ vị trí (barsHeld) và thời gian tạm dừng (barsPaused).
Chiến lược này thu được lợi nhuận thị trường thông qua kiểm soát chu kỳ thời gian và chuyển động nhiều không gian, có tính linh hoạt và thích ứng mạnh mẽ. Mặc dù có một số rủi ro, nhưng bằng các biện pháp tối ưu hóa và kiểm soát rủi ro hợp lý, có thể cải thiện đáng kể tính ổn định và lợi nhuận của chiến lược. Ưu điểm cốt lõi của chiến lược nằm trong logic giao dịch đơn giản và hiệu quả, thích nghi để tối ưu hóa và mở rộng hơn nữa cho chiến lược cơ bản.
/*backtest
start: 2024-10-12 00:00:00
end: 2024-11-11 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Tickerly Test Strategy", overlay=true)
// Inputs
longEnabled = input.bool(true, "Enable Long Trades")
shortEnabled = input.bool(true, "Enable Short Trades")
swingEnabled = input.bool(false, "Enable Swing Trading")
// Variables
var positionHeld = 0
var barsHeld = 0
var barsPaused = 0
var lastAction = "none"
// Function to determine if we're in the last 500 bars
inActivePeriod() =>
barIndex = bar_index
lastBarIndex = last_bar_index
barIndex >= (lastBarIndex - 499)
// Main strategy logic
if inActivePeriod()
if swingEnabled
if positionHeld == 0 and barstate.isconfirmed
if lastAction != "long"
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
lastAction := "long"
else
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
lastAction := "short"
if positionHeld != 0
barsHeld += 1
if barsHeld >= 2
if positionHeld == 1
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
lastAction := "short"
else
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
lastAction := "long"
else
if positionHeld == 0 and barsPaused >= 1 and barstate.isconfirmed
if longEnabled and shortEnabled
if lastAction != "long"
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
barsPaused := 0
lastAction := "long"
else
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
barsPaused := 0
lastAction := "short"
else if longEnabled
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
barsPaused := 0
lastAction := "long"
else if shortEnabled
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
barsPaused := 0
lastAction := "short"
if positionHeld != 0
barsHeld += 1
if barsHeld >= 3
strategy.close_all()
positionHeld := 0
barsHeld := 0
barsPaused := 0 // Reset pause counter when exiting a position
else
barsPaused += 1
// Plotting active period for visual confirmation
plot(inActivePeriod() ? 1 : 0, "Active Period", color=color.new(color.blue, 80), style=plot.style_areabr)