
Chiến lược đa hội tụ swing hunter là một chiến lược định lượng cao cấp được thiết kế đặc biệt cho giao dịch khung thời gian thấp, sử dụng hệ thống điểm dựa trên điểm tổng thể, kết hợp các chỉ số kỹ thuật tối ưu, phân tích hành vi giá và nhận dạng mô hình đảo ngược để tạo ra tín hiệu giao dịch chính xác. Sự đổi mới cốt lõi của chiến lược này là việc giới thiệu một cơ chế điểm đánh giá kép độc đáo, một mặt nhận diện đáy dao động thông qua hệ thống điểm đánh giá vào, và mặt khác thông qua hệ thống điểm đánh giá ra để xác định thời gian rút lui tốt nhất.
Chiến lược này sử dụng các tham số chỉ số được tối ưu hóa được đánh giá rộng rãi, bao gồm MACD ((3, 10, 3) và RSI ((21) được cấu hình đặc biệt, có thể thích ứng với sự thay đổi nhanh chóng của thị trường hơn so với cấu hình tiêu chuẩn. Chiến lược yêu cầu phải có ngưỡng điểm cao ít nhất 13 điểm để vào và ra, đảm bảo chỉ có tín hiệu có độ tin cậy cao sẽ kích hoạt giao dịch.
Trung tâm của chiến lược đa hội tụ là hệ thống xếp hạng tổng hợp của nó, nó xác định thời điểm giao dịch bằng cách đánh giá định lượng nhiều điều kiện kỹ thuật. Hệ thống xếp hạng nhập cảnh bao gồm bốn thành phần chính sau:
Tín hiệu RSI(Tối đa 5 điểm):
MACD tín hiệu(Tối đa 8 điểm):
Hành vi giá cả(Tối đa 4 điểm):
Nhận dạng mô hình(Tối đa 8 điểm):
Hệ thống điểm xuất phát sử dụng một hệ thống trọng lượng tương tự, nhưng sử dụng tiêu chuẩn ngược lại để nhận biết đỉnh xoay. Chiến lược này yêu cầu điểm xuất phát và xuất phát phải đạt được ít nhất 13 điểm, điều này đảm bảo rằng chỉ có tín hiệu có độ tin cậy cao sẽ được thực hiện, giảm khả năng của tín hiệu giả.
Một thành phần quan trọng khác của chiến lược là các tham số chỉ số được tối ưu hóa:
Các tham số này đã được tối ưu hóa đặc biệt để nắm bắt biến động giá nhanh và biến động tần số cao.
Quá trình quyết định định lượng khách quanBằng cách sử dụng hệ thống đánh giá dựa trên điểm số, chiến lược này loại bỏ sự phán đoán chủ quan và cung cấp tiêu chuẩn giao dịch rõ ràng. Phương pháp này làm cho quyết định giao dịch dựa trên dữ liệu thay vì cảm xúc, cải thiện đáng kể kỷ luật giao dịch.
Cơ chế xác nhận đa dạngChiến lược yêu cầu nhiều chỉ số kỹ thuật và mô hình giá được xác nhận cùng một lúc, làm tăng đáng kể độ tin cậy của tín hiệu. Chỉ khi tiêu chuẩn ít nhất 13 điểm được đáp ứng, giao dịch sẽ được thực hiện, điều này làm giảm nguy cơ tín hiệu giả.
Tối ưu hóa tính nhạy cảm thời gianBằng cách sử dụng các tham số MACD ((3, 10, 3) và RSI ((21) được tối ưu hóa, chiến lược có thể bắt kịp những thay đổi trong động lực giá sớm hơn, đồng thời lọc ra tiếng ồn thị trường, cung cấp sự nhạy cảm về thời gian tốt hơn.
Quản lý rủi ro linh hoạt: Chiến lược có tính toán mục tiêu dừng và lợi nhuận dựa trên rủi ro, tỷ lệ lợi nhuận rủi ro 5: 1 được sử dụng mặc định, cung cấp một khung quản lý rủi ro rõ ràng cho giao dịch. Động thái dừng dựa trên điểm thấp dao động gần đây, có vùng đệm có thể cấu hình, tăng tính linh hoạt trong kiểm soát rủi ro.
Hệ thống giao dịch có khả năng hiển thị caoChiến lược cung cấp hệ thống hiển thị điểm bao gồm thẻ xanh ((điểm vào ≥10) và thẻ đỏ ((điểm ra ≥10), và dấu nhập / thoát giao dịch rõ ràng, cho phép thương nhân nhìn rõ cách hoạt động của hệ thống.
Khả năng thích nghi cao: Mặc dù các tham số chiến lược được tối ưu hóa, chúng có thể được điều chỉnh theo các môi trường thị trường khác nhau và các loại giao dịch, làm cho chiến lược có thể áp dụng rộng rãi.
Vị trí cao phân bổ rủi roChiến lược này mặc định sử dụng cách phân bổ vốn 100%, loại đầu tư tập trung này làm tăng lỗ hổng rủi ro cho mỗi giao dịch. Điều này có thể dẫn đến biến động tài khoản đáng kể trong trường hợp thị trường biến động mạnh hoặc xảy ra sự kiện bất ngờ.
Tùy thuộc vào điều kiện thị trườngChiến lược này hoạt động tốt nhất trong các thị trường có xu hướng rõ ràng và biến động, nhưng có thể giảm hiệu quả trong các thị trường có biến động cao và ngang. Cần thận trọng trong các môi trường thị trường khác nhau và xem xét điều chỉnh các tham số hoặc tạm dừng giao dịch.
Tối ưu hóa rủi ro quá phù hợp: Các tham số chiến lược được tối ưu hóa, có thể có nguy cơ quá phù hợp với dữ liệu lịch sử. Những thay đổi trong điều kiện thị trường trong tương lai có thể khiến chiến lược hoạt động kém hơn kết quả kiểm tra lại. Các tham số nên được xác minh lại và điều chỉnh thường xuyên để duy trì hiệu quả của chiến lược.
Không bảo vệ đa dạngLà một chiến lược vị trí duy nhất, thiếu bảo vệ đa dạng, tăng rủi ro thị trường cụ thể. Trong ứng dụng thực tế, có thể xem xét chiến lược này như một phần của danh mục đầu tư rộng hơn hoặc giới thiệu giao dịch đa dạng để tăng đa dạng.
Rủi ro bị lỗi kỹ thuậtHệ thống xếp hạng phức tạp và nhiều điều kiện có thể không hiệu quả trong một số môi trường thị trường, đặc biệt là trong điều kiện thị trường cực đoan. Các biện pháp quản lý rủi ro bổ sung được đề xuất, chẳng hạn như đặt giới hạn lỗ tối đa hoặc sử dụng bộ lọc biến động.
Tiếp tục nhập các tham số thích ứngVí dụ, điều chỉnh các tham số MACD tự động trong môi trường biến động cao, hoặc điều chỉnh mức bán/mua quá mức RSI theo tình trạng thị trường hiện tại để cải thiện khả năng thích ứng của chiến lược trong các môi trường thị trường khác nhau.
Phân tích giá trị tổng hợpChiến lược hiện tại dựa trên hành động giá và các chỉ số động lực, có thể tăng cường chất lượng tín hiệu bằng cách tích hợp phân tích khối lượng giao dịch. Xác nhận khối lượng giao dịch có thể cung cấp độ tin cậy bổ sung, đặc biệt là trong xác nhận mô hình đảo ngược.
Thêm bộ lọc môi trường thị trường: Thực hiện cơ chế nhận diện môi trường thị trường, tự động giảm tần số giao dịch hoặc điều chỉnh tham số trong điều kiện thị trường không phù hợp với chiến lược. Ví dụ: nâng ngưỡng điểm trong thị trường ngang cao hoặc giảm phạm vi dừng lỗ trong môi trường biến động thấp.
Tối ưu hóa hệ thống quản lý tài chínhChiến lược hiện tại sử dụng phân bổ 100% vị trí, có thể thực hiện hệ thống quản lý tiền phức tạp hơn, điều chỉnh kích thước vị trí dựa trên cường độ tín hiệu, biến động thị trường hoặc hoạt động lịch sử. Ví dụ: phân bổ nhiều tiền hơn khi điểm số cao hơn hoặc giảm kích thước vị trí sau khi thua lỗ liên tục.
Tích hợp phân tích nhiều khung thời gianTăng cường chất lượng tín hiệu nhập cảnh bằng cách thêm xác nhận xu hướng của khung thời gian cao hơn. Ví dụ, giao dịch chỉ được thực hiện khi xu hướng khung thời gian cao hơn phù hợp, hoặc phân bổ nhiều điểm cho các giao dịch tuân theo xu hướng chủ đạo.
Tối ưu hóa học máyCân nhắc việc sử dụng các phương pháp học máy để tối ưu hóa trọng số và điểm mờ. Bằng cách phân tích dữ liệu lịch sử, bạn có thể xác định được các kết hợp tín hiệu nào hiệu quả nhất trong một môi trường thị trường cụ thể và điều chỉnh hệ thống xếp hạng cho phù hợp.
Chiến lược đa hội tụ-thay đổi-thợ săn đại diện cho một phương pháp giao dịch khung thời gian thấp toàn diện và có hệ thống, nó tạo ra một hệ thống quyết định giao dịch dựa trên dữ liệu bằng cách tích hợp nhiều chỉ số phân tích kỹ thuật và các đặc điểm hành vi giá. Điểm mạnh cốt lõi của chiến lược này là phương pháp đánh giá đa tiêu chuẩn khách quan, loại bỏ hiệu quả quyết định cảm xúc, trong khi vẫn đủ linh hoạt để thích ứng với các loại giao dịch và môi trường thị trường khác nhau.
Chiến lược này có khả năng nắm bắt hiệu quả sự biến động của thị trường, đặc biệt là trong các thị trường có biến động cao, thông qua các tham số MACD ((3, 10, 3) và RSI ((21) được tối ưu hóa, kết hợp với các điều kiện nhập và thoát nghiêm ngặt. Các tính năng quản lý rủi ro và công cụ trực quan được tích hợp trong chiến lược làm tăng thêm tính thiết thực và thân thiện với người dùng.
Tuy nhiên, chiến lược cũng có một số hạn chế và rủi ro, bao gồm phân bổ vị trí cao, sự phụ thuộc vào điều kiện thị trường và khả năng tối ưu hóa quá phù hợp. Bằng cách thực hiện các hướng tối ưu hóa được đề xuất, chẳng hạn như giới thiệu các tham số thích ứng, tích hợp phân tích quan hệ giá trị, thêm bộ lọc môi trường thị trường, các chiến lược có thể được nâng cao hơn nữa.
Đối với các nhà giao dịch có kinh nghiệm, chiến lược săn săn săn nhiều lần tập trung cung cấp một khuôn khổ mạnh mẽ để nắm bắt xu hướng và giao dịch xoay quanh khung thời gian thấp. Bằng cách hiểu các nguyên tắc cốt lõi của nó và điều chỉnh theo nhu cầu cụ thể, các nhà giao dịch có thể sử dụng chiến lược này để tìm kiếm các cơ hội giao dịch có xác suất cao trong thị trường thay đổi nhanh chóng.
/*backtest
start: 2024-06-30 00:00:00
end: 2025-06-28 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":50000000}]
*/
// ____ _ _______ _ _ _____
// / __ \ | | |__ __| | (_) | __ \
// | | | |_ _ __ _ _ __ | |_ | |_ __ __ _ __| |_ _ __ __ _ | |__) |
// | | | | | | |/ _` | '_ \| __| | | '__/ _` |/ _` | | '_ \ / _` | | ___/ '__/ _ \
// | |__| | |_| | (_| | | | | |_ | | | | (_| | (_| | | | | | (_| | | | | | | (_) |
// \___\_\\__,_|\__,_|_| |_|\__| |_|_| \__,_|\__,_|_|_| |_|\__, | |_| |_| \___/
// __/ |
// |___/
// Quant Trading Pro
//@version=6
strategy("Multi-Confluence Swing Hunter V1", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.1,
slippage=3, initial_capital=1000, margin_long=0, margin_short=0)
// === DESCRIPTION ===
// High-conviction swing bottom entry strategy using optimized MACD(3,10,3) and RSI(21)
// Entry: Point-based scoring system for swing bottoms (divergences, momentum, price action)
// Exit: Inverse scoring system for swing tops (no stop-loss, exit only on swing top signals)
// Position: Single position with 100% allocation, scores displayed only when ≥10 points
// Based on analysis showing 23.7% improvement over standard parameters
// === INPUT PARAMETERS ===
// Optimized Indicator Settings
macdFast = input.int(3, "MACD Fast Length", minval=1, maxval=50, group="Optimized Indicators")
macdSlow = input.int(10, "MACD Slow Length", minval=1, maxval=100, group="Optimized Indicators")
macdSignal = input.int(3, "MACD Signal Length", minval=1, maxval=50, group="Optimized Indicators")
rsiLength = input.int(21, "RSI Length", minval=2, maxval=100, group="Optimized Indicators")
// Entry Settings - Swing Bottom Scoring
minEntryScore = input.int(13, "Minimum Entry Score", minval=5, maxval=20, group="Entry Settings")
showEntryScores = input.bool(true, "Show Entry Scores (Above 10)", group="Entry Settings")
// Exit Settings - Swing Top Scoring (Inverse of Entry Criteria)
minExitScore = input.int(13, "Minimum Exit Score", minval=5, maxval=20, group="Exit Settings")
showExitScores = input.bool(true, "Show Exit Scores (Above 10)", group="Exit Settings")
// Price Action Settings
minLowerWickPercent = input.float(50.0, "Min Lower Wick %", minval=10.0, maxval=90.0, step=5.0, group="Price Action")
quickRecoveryPercent = input.float(0.3, "Quick Recovery %", minval=0.1, maxval=2.0, step=0.1, group="Price Action")
quickRecoveryBars = input.int(3, "Quick Recovery Bars", minval=1, maxval=10, group="Price Action")
// RSI Levels
rsiOversold = input.float(30.0, "RSI Oversold Level", minval=10.0, maxval=50.0, step=1.0, group="RSI Settings")
rsiExtremeOversold = input.float(25.0, "RSI Extreme Oversold", minval=10.0, maxval=40.0, step=1.0, group="RSI Settings")
rsiOverbought = input.float(70.0, "RSI Overbought Level", minval=50.0, maxval=90.0, step=1.0, group="RSI Settings")
rsiExtremeOverbought = input.float(75.0, "RSI Extreme Overbought", minval=60.0, maxval=90.0, step=1.0, group="RSI Settings")
// Reversal Signals Settings
reversalLookback = input.int(12, "Reversal Candle Lookback", minval=5, maxval=50, group="Reversal Signals")
reversalConfirm = input.int(3, "Reversal Confirm Within", minval=1, maxval=10, group="Reversal Signals")
useVolumeConfirmation = input.bool(false, "Use Volume Confirmation", group="Reversal Signals")
// Trade Management
allowShortTrades = input.bool(false, "Allow Short Trades?", group="Short Trades")
// Risk/Reward TP/SL Settings
useRiskReward = input.bool(true, "Use Risk/Reward TP/SL", group="Risk Management")
riskRewardRatio = input.float(5, "Risk/Reward Ratio", minval=1.0, maxval=5.0, step=0.1, group="Risk Management")
stopLossLookback = input.int(10, "Stop Loss Lookback Bars", minval=3, maxval=50, group="Risk Management")
stopLossBuffer = input.float(0.15, "Stop Loss Buffer %", minval=0.05, maxval=1.0, step=0.05, group="Risk Management")
// Advanced Settings
maxLookbackBars = input.int(8, "Divergence Lookback Bars", minval=3, maxval=20, group="Advanced")
// === 1️⃣ CALCULATIONS ===
// Optimized MACD Calculation
[macdLine, signalLine, macdHist] = ta.macd(close, macdFast, macdSlow, macdSignal)
// Optimized RSI Calculation
rsi = ta.rsi(close, rsiLength)
// Price Action Calculations
bodySize = math.abs(close - open)
lowerWick = math.min(open, close) - low
upperWick = high - math.max(open, close)
totalRange = high - low
lowerWickPercent = totalRange > 0 ? (lowerWick / totalRange) * 100 : 0
upperWickPercent = totalRange > 0 ? (upperWick / totalRange) * 100 : 0
bodyPercent = totalRange > 0 ? (bodySize / totalRange) * 100 : 0
// Reversal Signals Calculation
var int bullCandleScore = 0
var int bearCandleScore = 0
var bool bullReversalCandidate = false
var bool bearReversalCandidate = false
var float bullReversalLow = 0.0
var float bullReversalHigh = 0.0
var float bearReversalLow = 0.0
var float bearReversalHigh = 0.0
var bool bullSignalConfirmed = false
var bool bearSignalConfirmed = false
var int bullCandleCounter = 0
var int bearCandleCounter = 0
volumeIsHigh = volume > ta.sma(volume, 20)
// Reset scores
bullCandleScore := 0
bearCandleScore := 0
// Calculate reversal scores
if bar_index >= reversalLookback
for i = 0 to (reversalLookback - 1)
if close < low[i]
bullCandleScore += 1
if close > high[i]
bearCandleScore += 1
// Bear signal setup
if bearCandleScore == (reversalLookback - 1)
bearReversalCandidate := true
bearReversalLow := low
bearReversalHigh := high
bearSignalConfirmed := false
bearCandleCounter := 0
if bearReversalCandidate
bearCandleCounter += 1
if close > bearReversalHigh
bearReversalCandidate := false
bearCondition = bearReversalCandidate and close < bearReversalLow and not bearSignalConfirmed and bearCandleCounter <= (reversalConfirm + 1)
bearSignal = false
if bearCondition
bearSignalConfirmed := true
if not useVolumeConfirmation or volumeIsHigh
bearSignal := true
// Bull signal setup
if bullCandleScore == (reversalLookback - 1)
bullReversalCandidate := true
bullReversalLow := low
bullReversalHigh := high
bullSignalConfirmed := false
bullCandleCounter := 0
if bullReversalCandidate
bullCandleCounter += 1
if close < bullReversalLow
bullReversalCandidate := false
bullCondition = bullReversalCandidate and close > bullReversalHigh and not bullSignalConfirmed and bullCandleCounter <= (reversalConfirm + 1)
bullSignal = false
if bullCondition
bullSignalConfirmed := true
if not useVolumeConfirmation or volumeIsHigh
bullSignal := true
// === 2️⃣ ENTRY & EXIT LOGIC ===
// Helper Functions for Divergence Detection
findLowerLow(lookback) =>
var float lowestPrice = na
var int lowestIndex = na
if bar_index >= lookback
lowestPrice := low
lowestIndex := bar_index
for i = 1 to lookback
if low[i] < lowestPrice
lowestPrice := low[i]
lowestIndex := bar_index - i
[lowestPrice, lowestIndex]
findHigherHigh(lookback) =>
var float highestPrice = na
var int highestIndex = na
if bar_index >= lookback
highestPrice := high
highestIndex := bar_index
for i = 1 to lookback
if high[i] > highestPrice
highestPrice := high[i]
highestIndex := bar_index - i
[highestPrice, highestIndex]
// SWING BOTTOM SCORING SYSTEM
// 1. RSI Signals
rsiOversoldSignal = rsi < rsiOversold
rsiExtremeOversoldSignal = rsi < rsiExtremeOversold
rsiTurningUp = rsi > rsi[1]
// RSI Bullish Divergence
[prevLowPrice, prevLowIndex] = findLowerLow(maxLookbackBars)
rsiBullishDivergence = false
if not na(prevLowPrice) and not na(prevLowIndex) and bar_index > prevLowIndex
prevRSI = rsi[bar_index - prevLowIndex]
if low < prevLowPrice and rsi > prevRSI and not na(prevRSI)
rsiBullishDivergence := true
// 2. MACD Signals
macdNegative = macdLine < 0
macdTurningUp = macdLine > macdLine[1]
macdHistImproving = macdHist > macdHist[1]
// MACD Bullish Divergence
macdBullishDivergence = false
if not na(prevLowPrice) and not na(prevLowIndex) and bar_index > prevLowIndex
prevMACD = macdLine[bar_index - prevLowIndex]
if low < prevLowPrice and macdLine > prevMACD and not na(prevMACD)
macdBullishDivergence := true
// 3. Price Action Signals
longLowerWick = lowerWickPercent > minLowerWickPercent
smallBody = bodyPercent < 30.0
bullishClose = close > open
// 4. Quick Recovery Check
quickRecovery = false
if bar_index >= quickRecoveryBars
recoveryTarget = close * (1 + quickRecoveryPercent / 100)
for i = 1 to quickRecoveryBars
if high[i] > recoveryTarget
quickRecovery := true
break
// ENTRY SCORE CALCULATION
entryScore = 0
entryScore := entryScore + (rsiOversoldSignal ? 2 : 0)
entryScore := entryScore + (rsiExtremeOversoldSignal ? 2 : 0)
entryScore := entryScore + (rsiBullishDivergence ? 4 : 0)
entryScore := entryScore + (rsiTurningUp ? 1 : 0)
entryScore := entryScore + (macdNegative ? 1 : 0)
entryScore := entryScore + (macdTurningUp ? 2 : 0)
entryScore := entryScore + (macdHistImproving ? 2 : 0)
entryScore := entryScore + (macdBullishDivergence ? 3 : 0)
entryScore := entryScore + (longLowerWick ? 2 : 0)
entryScore := entryScore + (smallBody ? 1 : 0)
entryScore := entryScore + (bullishClose ? 1 : 0)
entryScore := entryScore + (quickRecovery ? 2 : 0)
entryScore := entryScore + (bullSignal ? 4 : 0) // Green reversal signal +4
// SWING TOP SCORING SYSTEM (for exits)
// 1. RSI Exit Signals
rsiOverboughtSignal = rsi > rsiOverbought
rsiExtremeOverboughtSignal = rsi > rsiExtremeOverbought
rsiTurningDown = rsi < rsi[1]
// RSI Bearish Divergence
[prevHighPrice, prevHighIndex] = findHigherHigh(maxLookbackBars)
rsiBearishDivergence = false
if not na(prevHighPrice) and not na(prevHighIndex) and bar_index > prevHighIndex
prevRSIHigh = rsi[bar_index - prevHighIndex]
if high > prevHighPrice and rsi < prevRSIHigh and not na(prevRSIHigh)
rsiBearishDivergence := true
// 2. MACD Exit Signals
macdPositive = macdLine > 0
macdTurningDown = macdLine < macdLine[1]
macdHistDeclining = macdHist < macdHist[1]
// MACD Bearish Divergence
macdBearishDivergence = false
if not na(prevHighPrice) and not na(prevHighIndex) and bar_index > prevHighIndex
prevMACDHigh = macdLine[bar_index - prevHighIndex]
if high > prevHighPrice and macdLine < prevMACDHigh and not na(prevMACDHigh)
macdBearishDivergence := true
// 3. Price Action Exit Signals
longUpperWick = upperWickPercent > minLowerWickPercent
bearishClose = close < open
// EXIT SCORE CALCULATION
exitScore = 0
exitScore := exitScore + (rsiOverboughtSignal ? 2 : 0)
exitScore := exitScore + (rsiExtremeOverboughtSignal ? 2 : 0)
exitScore := exitScore + (rsiBearishDivergence ? 4 : 0)
exitScore := exitScore + (rsiTurningDown ? 1 : 0)
exitScore := exitScore + (macdPositive ? 1 : 0)
exitScore := exitScore + (macdTurningDown ? 2 : 0)
exitScore := exitScore + (macdHistDeclining ? 2 : 0)
exitScore := exitScore + (macdBearishDivergence ? 3 : 0)
exitScore := exitScore + (longUpperWick ? 2 : 0)
exitScore := exitScore + (bearishClose ? 1 : 0)
exitScore := exitScore + (bearSignal ? 1 : 0) // Red reversal signal +1
// SIGNAL CONDITIONS
longCondition = entryScore >= minEntryScore and barstate.isconfirmed
exitCondition = exitScore >= minExitScore and barstate.isconfirmed
// === TP/SL LEVELS (Clean Logic) ===
var float stopLossLevel = na
var float takeProfitLevel = na
var bool tpslSet = false
// Clear levels when no position
if strategy.position_size == 0
stopLossLevel := na
takeProfitLevel := na
tpslSet := false
// Calculate TP/SL levels ONCE when position is opened
if strategy.position_size > 0 and strategy.position_size[1] == 0 and useRiskReward and not tpslSet
// Find recent low for stop loss
recentLow = low
for i = 1 to stopLossLookback
if low[i] < recentLow
recentLow := low[i]
// Set levels using actual entry price
entryPrice = strategy.opentrades.entry_price(0)
stopLossLevel := recentLow * (1 - stopLossBuffer / 100) // Configurable buffer below recent low
riskAmount = entryPrice - stopLossLevel
takeProfitLevel := entryPrice + (riskAmount * riskRewardRatio)
tpslSet := true
// === 3️⃣ TRADE EXECUTIONS ===
// Long Entry - Single Position Only
if longCondition and strategy.position_size == 0
strategy.entry("Long", strategy.long, comment="Entry Score: " + str.tostring(entryScore))
// Set TP/SL ONLY ONCE per trade (when levels are calculated and not yet set)
if strategy.position_size > 0 and useRiskReward and tpslSet and not na(stopLossLevel) and not na(takeProfitLevel)
strategy.exit("TP/SL", "Long", stop=stopLossLevel, limit=takeProfitLevel)
// Long Exit - Close Position on Swing Top Signal (Only when NOT using TP/SL)
if exitCondition and strategy.position_size > 0 and not useRiskReward
strategy.close("Long", comment="Exit Score: " + str.tostring(exitScore))
// === 4️⃣ VISUALIZATIONS ===
// Entry Score Display (Only When Score ≥ 10) - Shows on ALL qualifying bars
if showEntryScores and entryScore >= 10 and barstate.isconfirmed
label.new(bar_index, low,
text=str.tostring(entryScore),
yloc=yloc.belowbar,
color=na,
style=label.style_label_up,
textcolor=color.green,
size=size.small)
// Exit Score Display (Only When Score ≥ 10) - Shows on ALL qualifying bars
if showExitScores and exitScore >= 10 and barstate.isconfirmed
label.new(bar_index, high,
text=str.tostring(exitScore),
yloc=yloc.abovebar,
color=na,
style=label.style_label_down,
textcolor=color.red,
size=size.small)
// Large Trade Entry Triangle (Only when actually entering a position) - Using plotshape to avoid label limits
plotshape(longCondition and strategy.position_size == 0, title="Trade Entry", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.normal, text="BUY")
// Large Trade Exit Triangle (Only when actually exiting a position) - Using plotshape to avoid label limits
plotshape(exitCondition and strategy.position_size > 0, title="Trade Exit", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.normal, text="SELL")
// Reversal Signal Triangles
plotshape(bullSignal, title="Bull Reversal", location=location.belowbar,
color=color.lime, style=shape.triangleup, size=size.tiny)
plotshape(bearSignal, title="Bear Reversal", location=location.abovebar,
color=color.red, style=shape.triangledown, size=size.tiny)
// === TP/SL LEVEL PLOTS ===
plot(strategy.position_size > 0 and useRiskReward ? stopLossLevel : na, title="Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr)
plot(strategy.position_size > 0 and useRiskReward ? takeProfitLevel : na, title="Take Profit", color=color.green, linewidth=2, style=plot.style_linebr)
// MACD and RSI Plots (in separate panes)
macdPlot = plot(macdLine, title="MACD Line", color=color.blue, display=display.none)
signalPlot = plot(signalLine, title="Signal Line", color=color.red, display=display.none)
histPlot = plot(macdHist, title="MACD Histogram", color=color.gray, style=plot.style_histogram, display=display.none)
rsiPlot = plot(rsi, title="RSI", color=color.purple, display=display.none)
rsiOverboughtLine = hline(rsiOverbought, title="RSI Overbought", color=color.red, linestyle=hline.style_dashed, display=display.none)
rsiOversoldLine = hline(rsiOversold, title="RSI Oversold", color=color.green, linestyle=hline.style_dashed, display=display.none)