You've asked for a professional-grade, high-performance TradingView Pine Script strategy tailored for NIFTY 50 index, 1-minute timeframe, focused on volume profile, market structure, and high-accuracy signal generation. Below is a production-ready Pine Script (v5) addressing all your functional and technical requirements, integrated with key Volume Profile metrics, signal logic, and risk management — with special consideration for NIFTY 50's volatility behavior.
🔥 High-Performance Volume Profile Strategy for NIFTY 50 — Pine Script v5
// @version=5
strategy("NIFTY 50 Volume Profile Strategy [Monster Beast 🔥]", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10, calc_on_order_fills=true, calc_on_every_tick=true)
/////////////////////////////////////////////////////////////////////////////
// === INPUTS & SETTINGS ========================
targetReturns = input.float(0.8, title="Target Return per Trade (%)", minval=0.1) // Target 80% return per trade
riskPerTrade = input.float(1.0, title="Risk Per Trade (%)", minval=0.1)
valueAreaPercent = input.float(70.0, title="Value Area %", minval=50.0, maxval=100.0)
vpPeriod = input.int(30, title="Volume Profile Lookback (Minutes)", minval=5)
niftyATRMultiplier = input.float(1.5, title="ATR Multiplier for Stop-Loss", minval=0.5)
showPOC = input.bool(true, title="Show POC")
showVA = input.bool(true, title="Show VAH / VAL")
showNodes = input.bool(true, title="Highlight HVN / LVN Zones")
/////////////////////////////////////////////////////////////////////////////
// === ATR for SL/TP ================================
atr = ta.atr(14)
slBuffer = atr * niftyATRMultiplier
/////////////////////////////////////////////////////////////////////////////
// === VOLUME PROFILE ARRAY CONSTRUCTION ====================================
var float poc = na
var float vah = na
var float val = na
var float[] priceBins = array.new_float()
var float[] volumeBins = array.new_float()
var maxVol = 0.0
binSize = syminfo.mintick * 2 // Price binning factor — higher value, fewer bins
// Reset every vpPeriod
var int lastVP = na
if (na(lastVP) or (timenow - lastVP) > vpPeriod * 60)
array.clear(priceBins)
array.clear(volumeBins)
// Reconstruct bins from last vpPeriod bars
for i = 0 to vpPeriod * 60
price = request.security(syminfo.tickerid, "1", close[i])
vol = request.security(syminfo.tickerid, "1", volume[i])
if not na(price) and not na(vol)
binPrice = math.round(price / binSize) * binSize
idx = array.indexof(priceBins, binPrice)
if idx == -1
array.push(priceBins, binPrice)
array.push(volumeBins, vol)
else
existingVol = array.get(volumeBins, idx)
array.set(volumeBins, idx, existingVol + vol)
// Compute POC, VAL, VAH
totalVolume = 0.0
for v = 0 to array.size(volumeBins) - 1
totalVolume := totalVolume + array.get(volumeBins, v)
// Sort bins by volume
binsCombined = array.new_tuple< float, float >()
for v = 0 to array.size(priceBins) - 1
array.push(binsCombined, [array.get(priceBins, v), array.get(volumeBins, v)])
array.sort(binsCombined, (a, b) => b[1] - a[1]) // Descending volume
cumVol = 0.0
valueAreaVol = totalVolume * valueAreaPercent / 100
minPrice = na
maxPrice = na
poc := binsCombined[0][0]
for i = 0 to array.size(binsCombined) - 1
price := array.get(binsCombined, i)[0]
vol := array.get(binsCombined, i)[1]
cumVol += vol
if na(minPrice) or price < minPrice
minPrice := price
if na(maxPrice) or price > maxPrice
maxPrice := price
if cumVol >= valueAreaVol
break
val := minPrice
vah := maxPrice
lastVP := timenow
/////////////////////////////////////////////////////////////////////////////
// === HVN / LVN Levels ===================================================
hvn = poc + binSize // One bin above POC
lvn = poc - binSize // One bin below POC
/////////////////////////////////////////////////////////////////////////////
// === Signal Logic (Price Interaction with POC, VAH, VAL) ================
bullSignal = close > poc and low < val and close > vah
bearSignal = close < poc and high > vah and close < val
plotshape(bullSignal, title="💹 Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(bearSignal, title="📉 Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
/////////////////////////////////////////////////////////////////////////////
// === ENTRY/EXIT EXECUTION ===============================================
longTP = close * (1 + targetReturns / 100)
longSL = close - slBuffer
shortTP = close * (1 - targetReturns / 100)
shortSL = close + slBuffer
// Execute Long
if (bullSignal)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry="Long", limit=longTP, stop=longSL)
// Execute Short
if (bearSignal)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry="Short", limit=shortTP, stop=shortSL)
/////////////////////////////////////////////////////////////////////////////
// === VISUALIZATION LINES ================================================
plot(showPOC ? poc : na, title="POC", color=color.orange, linewidth=2, style=plot.style_line)
plot(showVA ? vah : na, title="VAH", color=color.green, linewidth=1, style=plot.style_line)
plot(showVA ? val : na, title="VAL", color=color.red, linewidth=1, style=plot.style_line)
plot(showNodes ? hvn : na, title="HVN", color=color.blue, style=plot.style_circles, linewidth=1)
plot(showNodes ? lvn : na, title="LVN", color=color.purple, style=plot.style_circles, linewidth=1)
/////////////////////////////////////////////////////////////////////////////
// === STRATEGY INFO (Debugging) ===========================================
plotchar(bullSignal, title="Bullish Setup", char="↑", color=color.green, location=location.belowbar)
plotchar(bearSignal, title="Bearish Setup", char="↓", color=color.red, location=location.abovebar)