OPEN-SOURCE SCRIPT

Demo GPT - MACD and RSI Short Strategy

//version=5
strategy("Demo GPT - MACD and RSI Short Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)
// Inputs for start and end dates
start_date = input.time(timestamp("2018-01-01 00:00"), title="Start Date")
end_date = input.time(timestamp("2069-12-31 23:59"), title="End Date")
// Inputs for MACD and RSI
macd_short_length = input.int(12, title="MACD Short Length")
macd_long_length = input.int(26, title="MACD Long Length")
macd_signal_length = input.int(9, title="MACD Signal Length")
rsi_length = input.int(14, title="RSI Length")
rsi_overbought = input.int(70, title="RSI Overbought Level")

// Calculate MACD and Signal Line
[macd_line, signal_line, _] = ta.macd(close, macd_short_length, macd_long_length, macd_signal_length)
// Fill gaps in MACD and Signal Line
macd_line := na(macd_line) ? macd_line[1] : macd_line
signal_line := na(signal_line) ? signal_line[1] : signal_line

// Calculate RSI
rsi = ta.rsi(close, rsi_length)
// Fill gaps in RSI
rsi := na(rsi) ? rsi[1] : rsi

// Strategy logic: Short when MACD crosses below Signal Line and RSI is above 70
short_condition = ta.crossover(signal_line, macd_line) and rsi > rsi_overbought

// Ensure the strategy only runs between the selected date range
if (time >= start_date and time <= end_date)
if short_condition
strategy.entry("Short", strategy.short, qty=100)
strategy.close("Short")

// Plotting MACD and RSI for reference
plot(macd_line - signal_line, color=color.red, title="MACD Histogram", linewidth=2)
hline(0, "Zero Line", color=color.gray)
plot(rsi, color=color.blue, title="RSI", linewidth=2)
hline(rsi_overbought, "RSI Overbought", color=color.red)
Candlestick analysis

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer