OPEN-SOURCE SCRIPT

HARRISH DADE

73
//version=5
strategy("Nifty 15m ORB + 20 EMA + Volume - Signals Fixed", overlay=true,
initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=25,
process_orders_on_close=true)

// 15-minute timeframe check
if timeframe.period != "15"
runtime.error("Use this strategy on 15 minute timeframe only")

// ORB 9:15–9:30 High/Low
var float orbHigh = na
var float orbLow = na

newDay = ta.change(time("D")) != 0
if newDay
orbHigh := na
orbLow := na

sessStart = 0915
sessEnd = 0930
hhmm = hour * 100 + minute
inORB = hhmm >= sessStart and hhmm < sessEnd

if inORB
orbHigh := na(orbHigh) ? high : math.max(orbHigh, high)
orbLow := na(orbLow) ? low : math.min(orbLow, low)

// Plot ORB levels
plot(orbHigh, "ORB High", color=color.new(color.green, 0), linewidth=2)
plot(orbLow, "ORB Low", color=color.new(color.red, 0), linewidth=2)

// Trend filter - 20 EMA
emaLen = input.int(20, "EMA Length", minval=1)
ema20 = ta.ema(close, emaLen)
upTrend = close > ema20
dnTrend = close < ema20
plot(ema20, "EMA 20", color=color.orange, linewidth=2)

// Volume filter - Adaptive
volLen = input.int(20, "Volume MA Length", minval=1)
avgVol = ta.sma(volume, volLen)
volMult = input.float(1.5, "Volume Multiplier", step=0.1)
enoughVol = volume >= (avgVol * volMult)

// ORB complete check
orbLocked = not na(orbHigh) and not na(orbLow) and not inORB

// Entry conditions (for strategy)
longCond = orbLocked and ta.crossover(close, orbHigh) and upTrend and enoughVol
shortCond = orbLocked and ta.crossunder(close, orbLow) and dnTrend and enoughVol

// Risk Management
targetPts = input.float(40.0, "Target Points", step=1.0)
slPts = input.float(25.0, "Stoploss Points", step=1.0)

// STRATEGY ENTRIES
if longCond and strategy.position_size == 0
strategy.entry("LONG", strategy.long)

if shortCond and strategy.position_size == 0
strategy.entry("SHORT", strategy.short)

// STRATEGY EXITS
if strategy.position_size > 0
strategy.exit("LONG EXIT", from_entry="LONG",
limit=strategy.position_avg_price + targetPts,
stop=strategy.position_avg_price - slPts)

if strategy.position_size < 0
strategy.exit("SHORT EXIT", from_entry="SHORT",
limit=strategy.position_avg_price - targetPts,
stop=strategy.position_avg_price + slPts)

// **FIXED BUY/SELL SIGNALS** - No barstate.isconfirmed, direct conditions
plotshape(longCond, title="BUY", style=shape.triangleup, location=location.belowbar,
color=color.new(color.lime, 0), size=size.large, text="BUY", textcolor=color.white)

plotshape(shortCond, title="SELL", style=shape.triangledown, location=location.abovebar,
color=color.new(color.red, 0), size=size.large, text="SELL", textcolor=color.white)

// Debug table - shows if conditions met
if barstate.islast
var table debugTable = table.new(position.top_right, 2, 6, bgcolor=color.white, border_width=1)
table.cell(debugTable, 0, 0, "Condition", text_color=color.black, bgcolor=color.gray)
table.cell(debugTable, 1, 0, "Status", text_color=color.black, bgcolor=color.gray)
table.cell(debugTable, 0, 1, "ORB Locked", text_color=color.black)
table.cell(debugTable, 1, 1, str.tostring(orbLocked), text_color=orbLocked ? color.green : color.red)
table.cell(debugTable, 0, 2, "UpTrend", text_color=color.black)
table.cell(debugTable, 1, 2, str.tostring(upTrend), text_color=upTrend ? color.green : color.red)
table.cell(debugTable, 0, 3, "Enough Vol", text_color=color.black)
table.cell(debugTable, 1, 3, str.tostring(enoughVol), text_color=enoughVol ? color.green : color.red)

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.