
A estratégia é um sistema de negociação de acompanhamento de tendências baseado em três linhas de ruptura na análise técnica do gráfico japonês. A administração de risco dinâmico, através da combinação de um índice de média móvel (EMA) como um filtro de tendência e um indicador de amplitude de onda real (ATR), aumenta a confiabilidade do modelo tradicional de ruptura de três linhas. A estratégia não só é capaz de capturar os pontos de mudança de tendência do mercado, mas também é capaz de controlar o risco de forma eficaz e é adequada para negociação de tendências a médio e longo prazo.
A lógica central da estratégia baseia-se nos seguintes elementos-chave: primeiro, a identificação da forma de ruptura de três linhas, ou seja, uma maior coluna de absorção de reversão após três linhas consecutivas da mesma cor. Segundo, o uso da EMA como filtro de tendência, considerando o sinal de mais somente quando o preço está acima da EMA e o sinal de menos somente quando está abaixo da EMA.
Trata-se de um sistema de estratégia que combina a teoria clássica da análise técnica e a moderna filosofia de negociação quantitativa. Construindo um sistema de negociação mais completo, combinando a forma tradicional de ruptura de três linhas com o rastreamento de tendências e o gerenciamento de riscos.
/*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)