OPEN-SOURCE SCRIPT

Bank Nifty Strategy [Signals + Alerts]

79
//version=5
strategy("Bank Nifty 5min Strategy [SMA/EMA + Volume + SL/TP]", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === INPUTS ===
maLength = input.int(10, title="MA Length")
emaLength = input.int(10, title="EMA Length")
vpSignalLen = input.int(3, title="Volume Pressure Signal Length")
vpLongLen = input.int(27, title="Volume Pressure Lookback")

takeProfitPercent = input.float(1.0, title="Target (%)", minval=0.1) // 1%
stopLossPercent = input.float(0.5, title="Stop Loss (%)", minval=0.1) // 0.5%

// === MA/EMA Crossover ===
xMA = ta.sma(close, maLength)
xEMA = ta.ema(xMA, emaLength)
trendUp = xMA > xEMA
trendDn = xEMA > xMA

plot(xMA, title="SMA", color=color.red)
plot(xEMA, title="EMA", color=color.blue)

// === Volume Pressure ===
vol = math.max(volume, 1)
BP = close < open ? (close[1] < open ? math.max(high - close[1], close - low) : math.max(high - open, close - low)) :
close > open ? (close[1] > open ? high - low : math.max(open - close[1], high - low)) :
high - low
SP = close < open ? (close[1] > open ? math.max(close[1] - open, high - low) : high - low) :
close > open ? (close[1] > open ? math.max(close[1] - low, high - close) : math.max(open - low, high - close)) :
high - low
TP = BP + SP
BPV = (BP / TP) * vol
SPV = (SP / TP) * vol
TPV = BPV + SPV
BPVavg = ta.ema(ta.ema(BPV, vpSignalLen), vpSignalLen)
SPVavg = ta.ema(ta.ema(SPV, vpSignalLen), vpSignalLen)
TPVavg = ta.ema(ta.wma(TPV, vpSignalLen), vpSignalLen)
vpo1 = ((BPVavg - SPVavg) / TPVavg) * 100
vpo1_rising = vpo1 > vpo1[1]
vpo1_falling = vpo1 < vpo1[1]

// === Signal Conditions ===
buySignal = trendUp and vpo1 > 0 and vpo1_rising
sellSignal = trendDn and vpo1 < 0 and vpo1_falling

// === Strategy Orders ===
longSL = close * (1 - stopLossPercent / 100)
longTP = close * (1 + takeProfitPercent / 100)

shortSL = close * (1 + stopLossPercent / 100)
shortTP = close * (1 - takeProfitPercent / 100)

if buySignal and strategy.position_size == 0
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry="Long", stop=longSL, limit=longTP)

if sellSignal and strategy.position_size == 0
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry="Short", stop=shortSL, limit=shortTP)

// === Plot Buy/Sell Arrows ===
plotshape(buySignal, title="Buy", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="Sell", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。