I have found a solution to the problem marked above. the code is as follows.
//@version=6
strategy("VWAP and RSI Strategy", shorttitle="VWAP RSI Strategy", overlay=true)
// --- VWAP Code ---
cumulativePeriod = input.int(30, title="VWAP Period")
typicalPrice = (high + low + close) / 3
typicalPriceVolume = typicalPrice * volume
cumulativeTypicalPriceVolume = ta.cum(typicalPriceVolume) // Cumulative typical price volume
cumulativeVolume = ta.cum(volume) // Cumulative volume
vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume // VWAP calculation
plot(vwapValue, title="VWAP", color=color.blue, linewidth=2)
// --- RSI Code ---
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
rsi = ta.rsi(rsiSourceInput, rsiLengthInput)
// Plot RSI on the main chart as well (if desired)
rsiPlot = plot(rsi, "RSI", color=color.purple)
rsiUpperBand = hline(70, "RSI Upper Band", color=color.red)
rsiLowerBand = hline(30, "RSI Lower Band", color=color.green)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
// --- Strategy Conditions ---
longCondition = ta.crossover(close, vwapValue) and rsi <= 25
if longCondition
strategy.entry("Long", strategy.long)
shortCondition = ta.crossunder(close, vwapValue) and rsi >= 65
if shortCondition
strategy.entry("Short", strategy.short)
// --- Exit Conditions ---
// Close the long trade if RSI reaches 30
if (rsi >= 30)
strategy.close("Long")
// Close the short trade if RSI reaches 70
if (rsi >= 70)
strategy.close("Short")
// --- Risk Management (Optional) ---
longStopLossPercent = input.float(2.0, title="Long Stop Loss %", minval=0.1, step=0.1) / 100
longTakeProfitPercent = input.float(5.0, title="Long Take Profit %", minval=0.1, step=0.1) / 100
shortStopLossPercent = input.float(2.0, title="Short Stop Loss %", minval=0.1, step=0.1) / 100
shortTakeProfitPercent = input.float(5.0, title="Short Take Profit %", minval=0.1, step=0.1) / 100
longStopLossPrice = strategy.position_avg_price * (1 - longStopLossPercent)
longTakeProfitPrice = strategy.position_avg_price * (1 + longTakeProfitPercent)
shortStopLossPrice = strategy.position_avg_price * (1 + shortStopLossPercent)
shortTakeProfitPrice = strategy.position_avg_price * (1 - shortTakeProfitPercent)
strategy.exit("Long TP/SL", from_entry="Long", stop=longStopLossPrice, limit=longTakeProfitPrice)
strategy.exit("Short TP/SL", from_entry="Short", stop=shortStopLossPrice, limit=shortTakeProfitPrice)
// --- Additional Plots and Strategy Settings ---
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Once testing, this has lead to the rise of more questions. The VWAP plotting for this does not align to the one inputted into ChatGPT as the base sample of VWAP with periods. There seems to be a problem regarding changes of v3 to v6 and the outdated ta.sum() now not being available so having to use ta.cum(). I think this comes from the fcat the 2 codes i am mergging are codes in v3 and v6. If anyone can help with this it would be greatly appreciated. The VWAP code I used was called VWAP with periods by neolao.