
This is an enhanced quantitative trading strategy developed based on metrobonez1ty’s strategy tester. The strategy’s main features include multiple take-profit targets and dynamic stop-loss mechanisms while maintaining flexibility for integration with external indicator signals. It supports up to three profit targets and optionally uses indicator-based stop-loss triggers, filtering trade entries through additional signal confirmation.
The strategy’s core logic revolves around a multi-layered exit mechanism. For entry, the strategy uses longEntry and shortEntry input sources to trigger long and short trading signals. For each trading direction, the strategy sets up three independent take-profit targets (TP1, TP2, TP3), each of which can be dynamically adjusted based on external indicator signals. Additionally, the strategy incorporates a dynamic stop-loss mechanism that can flexibly adjust stop-loss positions according to market conditions. The strategy also implements confluence-based filtering, requiring multiple indicator confirmations to trigger trades.
The strategy provides a comprehensive trading framework through multiple profit targets and dynamic stop-loss mechanisms. Its strengths lie in its flexibility and customizability, but careful attention must be paid to parameter optimization and market adaptability issues. Through the suggested optimization directions, the strategy can further enhance its stability and adaptability to become a more refined trading system.
/*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')