0% found this document useful (0 votes)
226 views

ChatGPT Strategy

The document defines a Relative Strength Index (RSI) trading strategy. It calculates RSI values using a 14 period RSI and generates buy and sell signals when RSI crosses above 30 (oversold) and below 70 (overbought) respectively while those levels are sustained for a minimum of 4 bars. It also identifies "strong" signals when the RSI divergence occurs on the crossover. The signals are then plotted on a chart for visualization.

Uploaded by

Manjunath Akar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views

ChatGPT Strategy

The document defines a Relative Strength Index (RSI) trading strategy. It calculates RSI values using a 14 period RSI and generates buy and sell signals when RSI crosses above 30 (oversold) and below 70 (overbought) respectively while those levels are sustained for a minimum of 4 bars. It also identifies "strong" signals when the RSI divergence occurs on the crossover. The signals are then plotted on a chart for visualization.

Uploaded by

Manjunath Akar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

//@version=4

study("RSI Strategy", shorttitle="RSI Strategy", overlay=true)

// Parameters
overbought = 70
oversold = 30
rsi_period = 14
min_duration = 4
max_duration = 100

// Calculate RSI
rsi = rsi(close, rsi_period)

// Check if RSI is overbought or oversold for the specified


duration
longOverbought = sum(rsi > overbought ? 1 : 0, max_duration) >=
min_duration
longOversold = sum(rsi < oversold ? 1 : 0, max_duration) >=
min_duration

// Generate signals
buySignal = crossover(rsi, oversold) and longOversold
sellSignal = crossunder(rsi, overbought) and longOverbought

// Calculate RSI divergence


priceDelta = close - close[1]
rsiDelta = rsi - rsi[1]
divergence = priceDelta * rsiDelta < 0

strongBuySignal = buySignal and divergence


strongSellSignal = sellSignal and divergence

// Plotting
plotshape(series=buySignal and not strongBuySignal, title="Buy
Signal", location=location.belowbar, color=color.green,
style=shape.labelup, text="Buy")
plotshape(series=sellSignal and not strongSellSignal, title="Sell
Signal", location=location.abovebar, color=color.red,
style=shape.labeldown, text="Sell")

plotshape(series=strongBuySignal, title="Strong Buy Signal",


location=location.belowbar, color=color.green,
style=shape.triangleup, text="Strong Buy")
plotshape(series=strongSellSignal, title="Strong Sell Signal",
location=location.abovebar, color=color.red,
style=shape.triangledown, text="Strong Sell")

// Plot RSI for reference


//hline(overbought, "Overbought", color=color.red)
//hline(oversold, "Oversold", color=color.green)
//plot(rsi, "RSI", color=color.blue)

You might also like