//@version=6
strategy("5min Entry System Pro", overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
commission_type=strategy.commission.percent,
commission_value=0.04)
// === Inputs ===
higherTF = input.timeframe("D", "Higher TF")
entryTF = input.timeframe("5", "Entry TF")
stopLossPips = input.int(25, "Stop Loss", minval=1)
tp1Pips = input.int(35, "TP1", minval=1)
tp2Pips = input.int(70, "TP2", minval=1)
tp3Pips = input.int(100, "TP3", minval=1)
preAlertBars = input.int(3, "Pre-Alert Bars", minval=1)
// === Global Variables ===
var float entryPrice = na
var bool tradeActive = false
var line entryLine = na
var line slLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
var label[] alertLabels = array.new_label()
// === Multi-Timeframe Data ===
dailyHigh = request.security(syminfo.tickerid, higherTF, high)
dailyLow = request.security(syminfo.tickerid, higherTF, low)
dailyClose = request.security(syminfo.tickerid, higherTF, close)
dailySMA50 = ta.sma(dailyClose, 50)
// === 5min Entry Logic ===
m5High = request.security(syminfo.tickerid, entryTF, high)
m5Low = request.security(syminfo.tickerid, entryTF, low)
m5Close = request.security(syminfo.tickerid, entryTF, close)
isUptrend = dailyClose > dailySMA50 and dailyHigh > dailyHigh[1]
isDowntrend = dailyClose < dailySMA50 and dailyLow < dailyLow[1]
potentialBuy = isUptrend and m5Low <= m5Low[1] and m5Close > m5Close[1]
potentialSell = isDowntrend and m5High >= m5High[1] and m5Close < m5Close[1]
// === Pre-Entry Alerts ===
if potentialBuy and not potentialBuy[1]
lbl = label.new(bar_index, low, "▲ POTENTIAL BUY\nMonitor 5min",
color=color.new(#00FF00, 90), style=label.style_label_up,
textcolor=color.white)
array.push(alertLabels, lbl)
if potentialSell and not potentialSell[1]
lbl = label.new(bar_index, high, "▼ POTENTIAL SELL\nMonitor 5min",
color=color.new(#FF0000, 90), style=label.style_label_down,
textcolor=color.white)
array.push(alertLabels, lbl)
// Cleanup old alerts
if array.size(alertLabels) > 0
for i = 0 to array.size(alertLabels)-1
if bar_index - label.get_x(array.get(alertLabels, i)) > preAlertBars
label.delete(array.get(alertLabels, i))
// === Trade Execution ===
if potentialBuy and not tradeActive
strategy.entry("BUY", strategy.long)
entryPrice := close
tradeActive := true
// Create visuals
entryLine := line.new(bar_index, entryPrice, na, na,
color=color.green, width=2, extend=extend.right)
slLine := line.new(bar_index, entryPrice - stopLossPips*syminfo.mintick, na,
na,
color=color.red, style=line.style_dotted, extend=extend.right)
tp1Line := line.new(bar_index, entryPrice + tp1Pips*syminfo.mintick, na, na,
color=color.orange, style=line.style_dotted, extend=extend.right)
tp2Line := line.new(bar_index, entryPrice + tp2Pips*syminfo.mintick, na, na,
color=color.orange, style=line.style_dotted, extend=extend.right)
tp3Line := line.new(bar_index, entryPrice + tp3Pips*syminfo.mintick, na, na,
color=color.orange, style=line.style_dotted, extend=extend.right)
if potentialSell and not tradeActive
strategy.entry("SELL", strategy.short)
entryPrice := close
tradeActive := true
// Create visuals
entryLine := line.new(bar_index, entryPrice, na, na,
color=color.red, width=2, extend=extend.right)
slLine := line.new(bar_index, entryPrice + stopLossPips*syminfo.mintick, na,
na,
color=color.red, style=line.style_dotted, extend=extend.right)
tp1Line := line.new(bar_index, entryPrice - tp1Pips*syminfo.mintick, na, na,
color=color.orange, style=line.style_dotted, extend=extend.right)
tp2Line := line.new(bar_index, entryPrice - tp2Pips*syminfo.mintick, na, na,
color=color.orange, style=line.style_dotted, extend=extend.right)
tp3Line := line.new(bar_index, entryPrice - tp3Pips*syminfo.mintick, na, na,
color=color.orange, style=line.style_dotted, extend=extend.right)
// === Trade Management ===
if tradeActive
// Update lines
line.set_x2(entryLine, bar_index)
line.set_x2(slLine, bar_index)
line.set_x2(tp1Line, bar_index)
line.set_x2(tp2Line, bar_index)
line.set_x2(tp3Line, bar_index)
// Check exit
if strategy.position_size == 0
line.delete(entryLine)
line.delete(slLine)
line.delete(tp1Line)
line.delete(tp2Line)
line.delete(tp3Line)
entryPrice := na
tradeActive := false
// === Visual Signals ===
plotshape(potentialBuy, "Buy Alert", shape.triangleup, location.belowbar,
color.green, 0, "PRE-BUY", size=size.small)
plotshape(potentialSell, "Sell Alert", shape.triangledown, location.abovebar,
color.red, 0, "PRE-SELL", size=size.small)