
Đây là một chiến lược giao dịch định lượng tăng cường được phát triển dựa trên Metrobonez1ty. Đặc điểm chính của chiến lược là thực hiện mục tiêu lợi nhuận đa cấp và cơ chế dừng lỗ động, trong khi vẫn giữ được sự linh hoạt trong việc tích hợp với tín hiệu chỉ số bên ngoài. Chiến lược hỗ trợ tối đa ba vị trí mục tiêu lợi nhuận và có thể sử dụng kích hoạt dừng lỗ dựa trên chỉ số để lọc giao dịch khi vào thị trường bằng tín hiệu bổ sung.
Về mặt đầu vào, chiến lược kích hoạt tín hiệu giao dịch đa đầu và vô đầu thông qua hai nguồn đầu vào longEntry và shortEntry. Đối với mỗi hướng giao dịch, chiến lược đặt ba mục tiêu lợi nhuận độc lập (TP1, TP2, TP3), mỗi mục tiêu có thể được điều chỉnh động dựa trên tín hiệu chỉ số bên ngoài. Đồng thời, chiến lược giới thiệu một cơ chế dừng lỗ động, có thể điều chỉnh vị trí dừng lỗ linh hoạt theo điều kiện thị trường.
Chiến lược này cung cấp một khung giao dịch toàn diện thông qua mục tiêu lợi nhuận đa cấp và cơ chế dừng lỗ động. Ưu điểm của chiến lược là tính linh hoạt và khả năng tùy chỉnh, nhưng đồng thời cũng cần phải xử lý cẩn thận các vấn đề tối ưu hóa tham số và khả năng thích ứng với thị trường.
/*backtest
start: 2025-02-04 00:00:00
end: 2025-02-18 08:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Enhanced Strategy Tester with multi TP and SL Trigger", overlay=true, margin_long=100, margin_short=100)
// Entry Signals
longEntry = input.source(close, 'Long Entry Trigger', 'long signal source')
shortEntry = input.source(close, 'Short Entry Trigger', 'short signal source')
// Exit Triggers
activateLongExit = input.bool(false, 'Activate Long Exit Signals')
longExit1 = input.source(high, 'Long Exit TP1')
longExit2 = input.source(high, 'Long Exit TP2')
longExit3 = input.source(high, 'Long Exit TP3')
activateShortExit = input.bool(false, 'Activate Short Exit Signals')
shortExit1 = input.source(low, 'Short Exit TP1')
shortExit2 = input.source(low, 'Short Exit TP2')
shortExit3 = input.source(low, 'Short Exit TP3')
// Stop Loss from External Indicator
useSLSignal = input.bool(false, 'Activate SL Signal')
slSignal = input.source(low, 'SL', 'SL Signal Source')
// Long Entry Condition
longCondition = not na(longEntry) and longEntry > 0
if (longCondition and strategy.opentrades == 0)
strategy.entry('long', strategy.long)
strategy.exit('exit_long_tp1', 'long', limit=longExit1, comment='TP1 hit')
strategy.exit('exit_long_tp2', 'long', limit=longExit2, comment='TP2 hit')
strategy.exit('exit_long_tp3', 'long', limit=longExit3, comment='TP3 hit')
strategy.exit('exit_long_sl', 'long', stop=useSLSignal ? slSignal : na, comment='SL hit')
// Long Exit Condition
if (activateLongExit)
if (not na(longExit1) and longExit1 > 0)
strategy.close('long', comment='TP1 at Exit')
if (not na(longExit2) and longExit2 > 0)
strategy.close('long', comment='TP2 at Exit')
if (not na(longExit3) and longExit3 > 0)
strategy.close('long', comment='TP3 at Exit')
// Short Entry Condition
shortCondition = not na(shortEntry) and shortEntry > 0
if (shortCondition and strategy.opentrades == 0)
strategy.entry('short', strategy.short)
strategy.exit('exit_short_tp1', 'short', limit=shortExit1, comment='TP1 hit')
strategy.exit('exit_short_tp2', 'short', limit=shortExit2, comment='TP2 hit')
strategy.exit('exit_short_tp3', 'short', limit=shortExit3, comment='TP3 hit')
strategy.exit('exit_short_sl', 'short', stop=useSLSignal ? slSignal : na, comment='SL hit')
// Short Exit Condition
if (activateShortExit)
if (not na(shortExit1) and shortExit1 > 0)
strategy.close('short', comment='TP1 at Exit')
if (not na(shortExit2) and shortExit2 > 0)
strategy.close('short', comment='TP2 at Exit')
if (not na(shortExit3) and shortExit3 > 0)
strategy.close('short', comment='TP3 at Exit')