该策略是一个基于日本蜡烛图技术分析中三线突破形态的趋势跟踪交易系统。通过结合指数移动平均线(EMA)作为趋势过滤器和真实波幅指标(ATR)进行动态风险管理,提高了传统三线突破模式的可靠性。该策略不仅能够捕捉市场的趋势转折点,还能够有效控制风险,适合中长期的趋势交易。
策略的核心逻辑基于以下几个关键要素:首先,识别三线突破形态,即连续三根相同颜色的蜡烛线后出现一根较大的反向吞没蜡烛。其次,使用EMA作为趋势过滤器,只有当价格位于EMA之上时才考虑做多信号,位于EMA之下时才考虑做空信号。最后,利用ATR指标动态设置止盈止损位置,具体为止盈设置为2倍ATR,止损设置为1倍ATR。
这是一个融合了技术分析经典理论和现代量化交易理念的策略系统。通过将传统的三线突破形态与趋势跟踪和风险管理相结合,构建了一个较为完整的交易系统。虽然存在一定的局限性,但通过提供的优化方向可以进一步提升策略的稳健性和适应性。策略的成功应用需要交易者深入理解市场特征,并根据具体情况进行参数调整。
/*backtest
start: 2025-01-18 00:00:00
end: 2025-02-17 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// Copyright ...
// Based on the TMA Overlay by Arty, converted to a simple strategy example.
// Pine Script v5
//@version=5
strategy(title='3 Line Strike [TTF] - Strategy with ATR and EMA Filter',
shorttitle='3LS Strategy [TTF]',
overlay=true,
initial_capital=100000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
pyramiding=0)
// -----------------------------------------------------------------------------
// INPUTS
// -----------------------------------------------------------------------------
// ATR and EMA Inputs
atrLength = input.int(title='ATR Length', defval=14, group='ATR & EMA')
emaLength = input.int(title='EMA Length', defval=200, group='ATR & EMA')
// ### 3 Line Strike
showBear3LS = input.bool(title='Show Bearish 3 Line Strike', defval=true, group='3 Line Strike',
tooltip="Bearish 3 Line Strike (3LS-Bear) = 3 zelené sviečky, potom veľká červená sviečka (engulfing).")
showBull3LS = input.bool(title='Show Bullish 3 Line Strike', defval=true, group='3 Line Strike',
tooltip="Bullish 3 Line Strike (3LS-Bull) = 3 červené sviečky, potom veľká zelená sviečka (engulfing).")
// -----------------------------------------------------------------------------
// CALCULATIONS
// -----------------------------------------------------------------------------
// Calculate ATR
atr = ta.atr(atrLength)
// Calculate EMA
ema = ta.ema(close, emaLength)
// Helper Functions
getCandleColorIndex(barIndex) =>
int ret = na
if (close[barIndex] > open[barIndex])
ret := 1
else if (close[barIndex] < open[barIndex])
ret := -1
else
ret := 0
ret
isEngulfing(checkBearish) =>
sizePrevCandle = close[1] - open[1]
sizeCurrentCandle = close - open
isCurrentLargerThanPrevious = math.abs(sizeCurrentCandle) > math.abs(sizePrevCandle)
if checkBearish
isGreenToRed = (getCandleColorIndex(0) < 0) and (getCandleColorIndex(1) > 0)
isCurrentLargerThanPrevious and isGreenToRed
else
isRedToGreen = (getCandleColorIndex(0) > 0) and (getCandleColorIndex(1) < 0)
isCurrentLargerThanPrevious and isRedToGreen
isBearishEngulfing() => isEngulfing(true)
isBullishEngulfing() => isEngulfing(false)
is3LSBear() =>
is3LineSetup = (getCandleColorIndex(1) > 0) and (getCandleColorIndex(2) > 0) and (getCandleColorIndex(3) > 0)
is3LineSetup and isBearishEngulfing()
is3LSBull() =>
is3LineSetup = (getCandleColorIndex(1) < 0) and (getCandleColorIndex(2) < 0) and (getCandleColorIndex(3) < 0)
is3LineSetup and isBullishEngulfing()
// Signals
is3LSBearSig = is3LSBear() and close < ema
is3LSBullSig = is3LSBull() and close > ema
// Take Profit and Stop Loss
longTP = close + 2 * atr
longSL = close - 1 * atr
shortTP = close - 2 * atr
shortSL = close + 1 * atr
// -----------------------------------------------------------------------------
// STRATEGY ENTRY PRÍKAZY
// -----------------------------------------------------------------------------
if (showBull3LS and is3LSBullSig)
strategy.entry("3LS_Bull", strategy.long, comment="3LS Bullish")
strategy.exit("Exit Bull", from_entry="3LS_Bull", limit=longTP, stop=longSL)
if (showBear3LS and is3LSBearSig)
strategy.entry("3LS_Bear", strategy.short, comment="3LS Bearish")
strategy.exit("Exit Bear", from_entry="3LS_Bear", limit=shortTP, stop=shortSL)