
Chiến lược này là một hệ thống giao dịch cao cấp dựa trên hình thức phá vỡ ba dòng cổ điển, cung cấp một giải pháp giao dịch hoàn chỉnh bằng cách tích hợp các chỉ số xác nhận xu hướng ADX và cơ chế dừng dừng động ATR. Cốt lõi của chiến lược là xác định hình thức phá vỡ sau ba dòng K đồng chiều liên tiếp và kết hợp với xác nhận cường độ xu hướng để tạo ra tín hiệu giao dịch chính xác.
Chiến lược hoạt động dựa trên ba cơ chế cốt lõi: đầu tiên là nhận diện hình dạng phá vỡ ba dòng cổ điển, bao gồm hình dạng bullish (((three consecutive bullish break) và hình dạng bearish (((three consecutive bullish break); tiếp theo sử dụng ADX (((trend indicator) để lọc cường độ xu hướng, chỉ xác nhận tín hiệu khi giá trị ADX vượt ngưỡng thiết lập; và cuối cùng sử dụng ATR (((trong thực amplitude) để tính toán vị trí dừng lỗ, tự điều chỉnh khả năng quản lý rủi ro. Chiến lược đảm bảo chất lượng tín hiệu về mặt kỹ thuật bằng cách xác định màu sắc K chính xác và kiểm tra cường độ phá vỡ.
Chiến lược này tạo ra một hệ thống giao dịch có cả cơ sở lý thuyết và thực tiễn bằng cách kết hợp hình thức đột phá ba dòng cổ điển với các chỉ số kỹ thuật hiện đại. Điểm mạnh cốt lõi của nó là cơ chế xác nhận tín hiệu đa dạng và quản lý rủi ro thông minh, nhưng khi sử dụng, cần chú ý đến sự phù hợp với môi trường thị trường và các vấn đề tối ưu hóa tham số.
/*backtest
start: 2024-08-05 00:00:00
end: 2024-12-24 00:00:00
period: 5h
basePeriod: 5h
exchanges: [{"eid":"Binance","currency":"ETH_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 ADX 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 ADX Inputs
atrLength = input.int(title='ATR Length', defval=14, group='ATR & ADX')
adxLength = input.int(title='ADX Length', defval=14, group='ATR & ADX')
adxThreshold = input.float(title='ADX Threshold', defval=25, group='ATR & ADX')
// ### 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 ADX components manually
tr = ta.tr(true)
plusDM = ta.change(high) > ta.change(low) and ta.change(high) > 0 ? ta.change(high) : 0
minusDM = ta.change(low) > ta.change(high) and ta.change(low) > 0 ? ta.change(low) : 0
smoothedPlusDM = ta.rma(plusDM, adxLength)
smoothedMinusDM = ta.rma(minusDM, adxLength)
smoothedTR = ta.rma(tr, adxLength)
plusDI = (smoothedPlusDM / smoothedTR) * 100
minusDI = (smoothedMinusDM / smoothedTR) * 100
dx = math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100
adx = ta.rma(dx, adxLength)
// 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 adx > adxThreshold
is3LSBullSig = is3LSBull() and adx > adxThreshold
// 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)