I am not a coder or programmer, et. just old man trying to figure out a script that is a strategy. When I place it in TradingView I get all kinds of error messages. I will try to attach it here if someone could please help me? Thank you very much.
<code>/@version=4
strategy("VWAP, RSI, and ADX Mean Reversion Strategy", overlay=true)
// Inputs vwap_length = input(20, "VWAP Length", minval=1)
rsi_length = input(4, "RSI Length", minval=1)
rsi_overbought = input(70, "RSI Overbought Level", minval=1)
rsi_oversold = input(30, "RSI Oversold Level", minval=1)
adx_length = input(14, "ADX Length", minval=1)
adx_level = input(25, "ADX Level", minval=1) //
Calculate VWAP and RSI
vwap = vwap(hlc3)
rsi = rsi(close, rsi_length) //
Calculate ADX
up = change(high)
down = -change(low)
trur = rma(tr, adx_length)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, adx_length) / trur)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, adx_length) / trur)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adx_length)
// Plot VWAP and RSI
plot(vwap, "VWAP", color=color.blue)
plot(rsi, "RSI", color=color.purple)
// Entry and exit conditions
longCondition = close < vwap and rsi > rsi_overbought and adx < adx_level
if longCondition
strategy.entry("Long", strategy.long)
shortCondition = close > vwap and rsi < rsi_oversold and adx < adx_level
if shortCondition
strategy.entry("Short", strategy.short)
// Stop loss and take profit
stopLoss = input(2.0, "Stop Loss %", step=0.1) / 100
takeProfit = input(5.0, "Take Profit %", step=0.1) / 100
strategy.exit("Exit Long", "Long", stop=strategy.position_avg_price * (1 - stopLoss), limit=strategy.position_avg_price * (1 + takeProfit))
strategy.exit("Exit Short", "Short", stop=strategy.position_avg_price * (1 + stopLoss), limit=strategy.position_avg_price * (1 - takeProfit))
</code>
<code>/@version=4
strategy("VWAP, RSI, and ADX Mean Reversion Strategy", overlay=true)
// Inputs vwap_length = input(20, "VWAP Length", minval=1)
rsi_length = input(4, "RSI Length", minval=1)
rsi_overbought = input(70, "RSI Overbought Level", minval=1)
rsi_oversold = input(30, "RSI Oversold Level", minval=1)
adx_length = input(14, "ADX Length", minval=1)
adx_level = input(25, "ADX Level", minval=1) //
Calculate VWAP and RSI
vwap = vwap(hlc3)
rsi = rsi(close, rsi_length) //
Calculate ADX
up = change(high)
down = -change(low)
trur = rma(tr, adx_length)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, adx_length) / trur)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, adx_length) / trur)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adx_length)
// Plot VWAP and RSI
plot(vwap, "VWAP", color=color.blue)
plot(rsi, "RSI", color=color.purple)
// Entry and exit conditions
longCondition = close < vwap and rsi > rsi_overbought and adx < adx_level
if longCondition
strategy.entry("Long", strategy.long)
shortCondition = close > vwap and rsi < rsi_oversold and adx < adx_level
if shortCondition
strategy.entry("Short", strategy.short)
// Stop loss and take profit
stopLoss = input(2.0, "Stop Loss %", step=0.1) / 100
takeProfit = input(5.0, "Take Profit %", step=0.1) / 100
strategy.exit("Exit Long", "Long", stop=strategy.position_avg_price * (1 - stopLoss), limit=strategy.position_avg_price * (1 + takeProfit))
strategy.exit("Exit Short", "Short", stop=strategy.position_avg_price * (1 + stopLoss), limit=strategy.position_avg_price * (1 - takeProfit))
</code>
/@version=4
strategy("VWAP, RSI, and ADX Mean Reversion Strategy", overlay=true)
// Inputs vwap_length = input(20, "VWAP Length", minval=1)
rsi_length = input(4, "RSI Length", minval=1)
rsi_overbought = input(70, "RSI Overbought Level", minval=1)
rsi_oversold = input(30, "RSI Oversold Level", minval=1)
adx_length = input(14, "ADX Length", minval=1)
adx_level = input(25, "ADX Level", minval=1) //
Calculate VWAP and RSI
vwap = vwap(hlc3)
rsi = rsi(close, rsi_length) //
Calculate ADX
up = change(high)
down = -change(low)
trur = rma(tr, adx_length)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, adx_length) / trur)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, adx_length) / trur)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adx_length)
// Plot VWAP and RSI
plot(vwap, "VWAP", color=color.blue)
plot(rsi, "RSI", color=color.purple)
// Entry and exit conditions
longCondition = close < vwap and rsi > rsi_overbought and adx < adx_level
if longCondition
strategy.entry("Long", strategy.long)
shortCondition = close > vwap and rsi < rsi_oversold and adx < adx_level
if shortCondition
strategy.entry("Short", strategy.short)
// Stop loss and take profit
stopLoss = input(2.0, "Stop Loss %", step=0.1) / 100
takeProfit = input(5.0, "Take Profit %", step=0.1) / 100
strategy.exit("Exit Long", "Long", stop=strategy.position_avg_price * (1 - stopLoss), limit=strategy.position_avg_price * (1 + takeProfit))
strategy.exit("Exit Short", "Short", stop=strategy.position_avg_price * (1 + stopLoss), limit=strategy.position_avg_price * (1 - takeProfit))
I don’t know how to fix code
New contributor
Buck is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.