Wait for recovery rather than buying an oversold reading
An RSI below 30 can persist during a decline. A recovery strategy instead waits for RSI to cross back above 30, while requiring price to remain above its 100-bar simple moving average. This is a long-only Thinkorswim strategy simulation, not an unattended live trading system.
Signal and simulated execution
Use 14-bar RSI. If RSI moves from 28 to 34 and price is above its 100-bar average, the entry qualifies. If the signal bar closes at 102 and the next bar opens at 103, the modeled entry is 103, not 102. Exit when RSI crosses above 50 or price is no longer above the average. Both entry and exit use the next bar open. The illustrative state variable prevents repeated entries while a modeled position is held.

Hypothetical RSI path: 40, 32, 25, 28, 34, 39. The recovery signal occurs at 34; the simulated fill belongs to the next bar, subject to the trend filter.
thinkScript strategy example
input length = 14;
input lower = 30;
input exitLevel = 50;
input qty = 1;
def r = RSI(length = length);
def trend = close > Average(close, 100);
def entry = r crosses above lower and trend;
def exit = r crosses above exitLevel or !trend;
rec holding = CompoundValue(1,
if holding[1] then
if exit[1] then 0 else 1
else if entry[1] then 1 else 0, 0);
AddOrder(OrderType.BUY_TO_OPEN,
!holding and entry, open[-1], qty,
Color.GREEN, Color.GREEN, "RSI recovery");
AddOrder(OrderType.SELL_TO_CLOSE,
holding and exit, open[-1], qty,
Color.RED, Color.RED, "RSI exit");
Add the script under Strategies, not Studies. The recursive holding variable represents the modeled position after the preceding bar's signal. It is not a brokerage position query. The negative index in open[-1] specifies the next bar's modeled order price, not an input to the signal. See the official AddOrder reference. AddOrder produces hypothetical strategy orders and does not submit unattended live orders.
Test the assumptions
Load sufficient history for the 100-bar average and RSI warm-up. Compare recovery thresholds of 25, 30 and 35 while keeping the trend filter and costs constant. Examine trade count, average return, drawdown and performance in unseen trending and sideways periods. A gap can materially change the next-open price; include realistic spread, slippage and commissions when evaluating results. The example has no protective stop and is not a complete risk-managed strategy. It has not been compiled or backtested here. Trading can cause substantial losses.
For customized strategy simulations and signal logic, see Custom Thinkorswim strategy Development Services.