
Chiến lược này là một hệ thống giao dịch tự điều chỉnh dựa trên lỗ hổng và biến động giá, để đạt được lợi nhuận ổn định bằng cách thiết lập điểm vào linh hoạt và dừng lỗ động. Chiến lược sử dụng phương thức đặt hàng theo kiểu kim tự tháp, đồng thời kết hợp với hệ thống quản lý đơn đặt hàng OCA để kiểm soát rủi ro. Hệ thống sẽ tự động điều chỉnh hướng giữ vị trí theo xu hướng thị trường và dừng lỗ ngay khi có tín hiệu đảo ngược.
Chiến lược này hoạt động thông qua các cơ chế cốt lõi sau:
Đây là một chiến lược giao dịch được thiết kế hợp lý, logic nghiêm ngặt, đảm bảo sự ổn định và an toàn của giao dịch thông qua nhiều cơ chế. Ưu điểm cốt lõi của chiến lược là khả năng thích ứng và kiểm soát rủi ro của nó, nhưng cũng cần chú ý đến rủi ro do biến động thị trường.
/*backtest
start: 2024-12-04 00:00:00
end: 2024-12-11 00:00:00
period: 10m
basePeriod: 10m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Greedy Strategy - maclaurin", pyramiding = 100, calc_on_order_fills=false, overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
backtestStartDate = input(timestamp("1 Jan 1990"),
title="Start Date", group="Backtest Time Period",
tooltip="This start date is in the time zone of the exchange " +
"where the chart's instrument trades. It doesn't use the time " +
"zone of the chart or of your computer.")
backtestEndDate = input(timestamp("1 Jan 2023"),
title="End Date", group="Backtest Time Period",
tooltip="This end date is in the time zone of the exchange " +
"where the chart's instrument trades. It doesn't use the time " +
"zone of the chart or of your computer.")
inTradeWindow = true
tp = input(10)
sl = input(10)
maxidf = input(title="Max Intraday Filled Orders", defval=5)
// strategy.risk.max_intraday_filled_orders(maxidf)
upGap = open > high[1]
dnGap = open < low[1]
dn = strategy.position_size < 0 and open > close
up = strategy.position_size > 0 and open < close
if inTradeWindow and upGap
strategy.entry("GapUp", strategy.long, stop = high[1])
else
strategy.cancel("GapUp")
if inTradeWindow and dn
strategy.entry("Dn", strategy.short, stop = close)
else
strategy.cancel("Dn")
if inTradeWindow and dnGap
strategy.entry("GapDn", strategy.short, stop = low[1])
else
strategy.cancel("GapDn")
if inTradeWindow and up
strategy.entry("Up", strategy.long, stop = close)
else
strategy.cancel("Up")
XQty = strategy.position_size < 0 ? -strategy.position_size : strategy.position_size
dir = strategy.position_size < 0 ? -1 : 1
lmP = strategy.position_avg_price + dir*tp*syminfo.mintick
slP = strategy.position_avg_price - dir*sl*syminfo.mintick
float nav = na
revCond = strategy.position_size > 0 ? dnGap : (strategy.position_size < 0 ? upGap : false)
if inTradeWindow and not revCond and XQty > 0
strategy.order("TP", strategy.position_size < 0 ? strategy.long : strategy.short, XQty, lmP, nav, "TPSL", "TPSL")
strategy.order("SL", strategy.position_size < 0 ? strategy.long : strategy.short, XQty, nav, slP, "TPSL", "TPSL")
if XQty == 0 or revCond
strategy.cancel("TP")
strategy.cancel("SL")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)