
Đây là một chiến lược giao dịch định lượng dựa trên chỉ số xu hướng trung bình (ADX) và giá phá vỡ. Chiến lược này chủ yếu đánh giá cường độ của xu hướng thị trường bằng cách theo dõi số chỉ số ADX và kết hợp với tín hiệu phá vỡ giá để nắm bắt động lực thị trường. Chiến lược được thiết lập để hoạt động trong một khoảng thời gian giao dịch cụ thể và quản lý rủi ro bằng cách dừng lỗ và giới hạn số lần giao dịch mỗi ngày.
Logic cốt lõi của chiến lược bao gồm các yếu tố chính sau:
Đây là một chiến lược theo dõi xu hướng có cấu trúc, logic rõ ràng. Bằng cách kết hợp các chỉ số ADX với các đợt phá vỡ giá, nắm bắt các cơ hội xu hướng thị trường trong khuôn khổ quản lý rủi ro hiệu quả. Mặc dù có một số không gian để tối ưu hóa, nhưng khung cơ bản của chiến lược là vững chắc, phù hợp với các thành phần cơ bản của hệ thống giao dịch định lượng.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HuntGatherTrade
// ========================
// NQ 30 minute, ES 30 minute
//@version=5
strategy("ADX Breakout", overlay=false, initial_capital=25000, default_qty_value=1)
// ===============================
// Input parameters
// ===============================
stopLoss = input(1000.0, title="Stop Loss ($)", group="Exits")
session = input("0730-1430:1234567", group="Trade Session")
highestLB = input(34, title="Highest lookback window", group="Indicator values")
// ===============================
// Trade Session Handling
// ===============================
t = time(timeframe.period, session)
// Reset numTrades at the start of each session
var int numTrades = 0
is_new_session = ta.change(time("D")) != 0
if is_new_session
numTrades := 0
// ===============================
// Entry Conditions
// ===============================
[plusDI, minusDI, adxValue] = ta.dmi(50, 14)
entryCondition = (close >= ta.highest(close, highestLB)[1]) and (adxValue < 17.5) and (strategy.position_size == 0) and (numTrades < 3) and not na(t)
// ===============================
// 7. Execute Entry
// ===============================
var float stopPricePlot = na
if entryCondition
entryPrice = close + syminfo.mintick
strategy.entry("Long Entry", strategy.long, stop=entryPrice)
//stopPrice = strategy.position_avg_price - (stopLoss / syminfo.pointvalue)
//strategy.exit("Stop Loss", "Long Entry", stop=stopPrice)
numTrades += 1
if (strategy.position_size > 0) and (strategy.position_size[1] == 0)
stopPoints = stopLoss / syminfo.pointvalue
stopPrice = strategy.position_avg_price - stopPoints
stopPrice := math.round(stopPrice / syminfo.mintick) * syminfo.mintick
strategy.exit("Stop Loss", from_entry="Long Entry", stop=stopPrice)
if ta.change(strategy.opentrades) == 1
float entryPrice = strategy.opentrades.entry_price(0)
stopPricePlot := entryPrice - (stopLoss / syminfo.pointvalue)
if ta.change(strategy.closedtrades) == 1
stopPricePlot := na
plot(stopPricePlot, "Stop-loss level", color.red, 1, plot.style_linebr)
// ===============================
// Exit at End of Session
// ===============================
if na(t) and strategy.position_size != 0
strategy.close_all(comment="End of Day Exit")