Econometrics Non Linear Strategy (RSI condition) by TheWannaBeQuant

By TheWannaBeQuant

Performance Metrics

Description

This strategy trades StochRSI extremes (OS/OB) but only enters when a Stata-trained logistic model assigns a high probability to the expected direction, then exits via time, probability decay, and/or mean-reversion back to the midline.I know that many of you simply do not like math, so I will explain this scrip in two ways, the easy way and the mathematical way. The easy way:Think of the market like a **rubber band**:* Sometimes price gets stretched too far down → it often snaps back up.* Sometimes price gets stretched *too far up → it often snaps back down.This script is built to:1. Spot when the rubber band is stretched2. Decide if it’s a good stretch to trade3. Enter the trade4. Exit when the snap-back is likely done1) It looks for “extreme” moments (Stoch RSI)The script uses a tool called the Stochastic RSI to tell if price is:* Oversold = price got pushed down too hard (stretched down)* Overbought = price got pushed up too hard (stretched up)So, the script basically waits for:* Oversold → “maybe buy”* Overbought → “maybe sell”2) It doesn’t trade every extreme (because many extremes fail)This is the important part:Even if something looks oversold/overbought, it doesn’t always bounce immediately.So the script adds a smart filter:* It gives each situation a score from 0% to 100%* That score means: “How likely is it that this trade is worth taking?”If the score isn’t high enough → the script does nothing.3) It only enters trades when the score is high enoughYou choose a number like 0.78 (78%).* If the script thinks the chance is 78% or more, it enters.* If it’s lower, it ignores it.So it’s like:> “I will only trade when my filter is confident.”As you see in the image above, the market entered a volatile, sideways state. The model was able to accurately define the extreme lows, enter trades, and then exit with profitability.4) Optional extra filter: RSI (on/off)You can turn on an extra rule:* RSI above 50 might support buying* RSI below 50 might support selling (or reversed if you flip it)This is just a “more strict” option. How it exits (how it decides when to leave)The script can exit in 3 simple ways:A) Time exit> “If nothing happens after X bars, I’m leaving.”B) Probability exit> “If my score drops and the setup no longer looks good, I’m leaving.”C) Midline exit (mean reversion exit)> “Once Stoch RSI returns to normal (around the middle), I assume the bounce is done, so I take profit or exit.”What the controls mean:* Use Stoch zone gate: only trade when oversold/overbought* Use probability gate: only trade when the setup score is high enough* Use RSI gate: add an extra filter (optional)* Reverse logic: flip the meaning (useful for testing)* Trade mode + enable longs/shorts: choose long-only, short-only, or both (and it will enforce it) NOTE!! This script is not FINANCIAL ADVICE. There is no script in the world that is guaranteed to make you money. This strategy is there to help you further confirm any entry based on your own strategy and belief Here are some downsides to this strategy:The market is sideways trading and has low volume. With slippage/commission, this strategy fails. The blue circle is a missed chance at capturing the entire big move. You can then see the red circle contain two losing trades where it completely miss read the market. When to use this strategy:When looking at the XAUUSD for example, in an uncertain world, XAUUSD tends to be bullish. It works well when there is a clear trend in any forex pair or commodity.I recommend you experiment with the settings and maybe build yourself your own winning strategy!

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView