Trade recovery rather than oversold readings
RSI below 30 does not establish a bottom. This long-only research strategy waits for RSI to cross back above 30 while price remains above its 100-bar simple moving average. The filter deliberately excludes many falling markets, but can also exclude profitable reversals.
Worked example
Suppose RSI moves from 25 to 34 and the closing price is 102 while the average is 100. The recovery signal qualifies. If the next open is 103, the simulated entry is 103, not 102. A later cross below 60 or close below the moving average generates an exit signal for the following open.

Hypothetical RSI path: the green marker is the recovery signal; the following bar is the simulated execution point, conditional on the trend filter passing at the signal.
ThinkScript strategy implementation
Create a strategy rather than a study and paste the following example. AddOrder generates hypothetical strategy orders, not unattended live broker execution. The negative index is used only for the next-bar simulated execution price, not for deciding the signal.
input rsiLength = 14;
input trendLength = 100;
input quantity = 1;
def r = RSI(length = rsiLength);
def trend = Average(close, trendLength);
def buySignal = r crosses above 30 and close > trend;
def sellSignal = r crosses below 60 or close < trend;
AddOrder(OrderType.BUY_TO_OPEN, buySignal, open[-1], quantity, Color.GREEN, Color.GREEN, "Recovery");
AddOrder(OrderType.SELL_TO_CLOSE, sellSignal, open[-1], quantity, Color.RED, Color.RED, "Exit");
Configure strategy settings to limit same-direction entries to one if testing a single-position model. The example has no intrabar protective stop; an overnight gap can produce a much larger loss than anticipated. For a more complete model, define explicit position state, stop rules and execution assumptions. Do not treat a simulated next-open fill as a guaranteed executable quote.
Testing and limitations
Compare the unfiltered RSI recovery with the filtered version on identical symbols, periods and costs. Measure trade count, exposure, maximum drawdown and average net trade. Test 50, 100 and 200-bar filters on training data, then reserve untouched periods for validation. Inspect the strategy report for repeated entries and unmatched exits. Account for spreads, commissions and gaps separately where the simulator does not model them. This example has not been compiled or backtested here. Trading involves risk of loss.
For additional state management and customized research rules, see Custom Thinkorswim strategy Development Services.