SpringPad’s TradingView Strategy PineScript Code
//@version=5
strategy("VWAP and MA Mean Reversion Strategy with ATR Stop Loss", overlay=true)
// Inputs
length = input(14, "MA Length")
atrLength = input(14, "ATR Length")
atrMultiplier = input(1.5, title="ATR Multiplier for Stop Loss")
// Calculate VWAP, Moving Average, and ATR
vwap = [Link](hlc3)
ma = [Link](close, length)
atr = [Link](atrLength)
// Buy condition: Price is below VWAP but above MA
longCondition = close < vwap and close > ma
if (longCondition)
[Link]("Buy", [Link])
stopPrice = close - atrMultiplier * atr
[Link]("Stop Loss", "Buy", stop=stopPrice)
// Sell condition: Price is above VWAP but below MA
shortCondition = close > vwap and close < ma
if (shortCondition)
[Link]("Sell", [Link])
stopPrice = close + atrMultiplier * atr
[Link]("Stop Loss", "Sell", stop=stopPrice)
// Plotting
plot(vwap, title="VWAP", color=[Link])
plot(ma, title="MA", color=[Link])
STEPS
1) Go to - [Link]
2) Select – PRODUCTS -> SUPERCHARTS
3) Bottom of Screen – PINE EDITOR
4) COPY ABOVE CODE and PASTE IT
5) RENAME SCRIPT and SAVE
6) To use it, click INDICATORS -> Personal -> Select your saved script.