Logistic RSI, STOCH, ROC, AO & Backtest Framework
What happens when market momentum meets chaos theory.
Most oscillators are linear. They take a price input, apply a formula, and produce a value that moves within a fixed range. They are useful - but they are designed to describe orderly conditions. Markets, however, are not always orderly. They exhibit nonlinear behaviour, feedback loops, and sudden regime shifts that linear tools consistently underestimate.
This script applies a different mathematical lens. It takes a standard oscillator - RSI, Stochastic, Rate of Change, Awesome Oscillator, or a custom price-dominance metric - and passes it through a Logistic Map, a mathematical model borrowed from chaos theory and population dynamics. The result is a momentum indicator that responds differently under stable conditions versus unstable ones, revealing regime transitions that standard oscillators tend to miss until they are already underway.
The Logistic Map
The Logistic Map is a deceptively simple equation with complex behaviour. At low growth rates it converges to a stable value. As the growth rate increases it begins to oscillate between two states, then four, then eight - until it enters a regime of apparent chaos where output becomes highly sensitive to initial conditions. In the context of market momentum, this property is precisely what makes it useful: when momentum is stable and trending, the map produces clean, consistent output. When momentum is unstable or reversing, the iterations diverge - and that divergence is the signal.
Each bar generates 30 iterations of the Logistic Map seeded from the selected oscillator. The final iteration and the aggregated standard deviation of all iterations are both plotted, with the standard deviation line serving as the primary signal - positive standard deviation indicates bullish momentum regime, negative indicates bearish.
Oscillator Selection
Five base oscillators can be selected as the input for the Logistic Map transformation:
Relative Strength Index (RSI) - classic price momentum, normalised to the Logistic Map input range. Configurable length.
Stochastic (STOCH) - position of current price within a recent high-low range, providing a mean-reversion-aware momentum input. Configurable length.
Rate of Change (ROC) - raw percentage price change over a configurable lookback, emphasising momentum without range-normalisation.
Awesome Oscillator (AO) - the difference between a fast and slow simple moving average of the midpoint, providing a broader momentum perspective without a configurable length.
Logistic Dominance - a custom metric built directly from price action, measuring the relative dominance of upward versus downward price movement using the Logistic Map equation itself as the measurement framework. This mode applies the transformation at the oscillator construction stage as well as the iteration stage, producing a fully recursive interpretation of price behaviour.
Visualisation
Three display styles are available. Cross mode plots discrete markers for each of the 30 iterations, showing the spread and clustering behaviour directly. Line mode connects the iterations into a continuous line. StepLine emphasises the discrete nature of the iteration levels. The aggregated standard deviation line is always displayed as the primary signal regardless of style.
A Standard Deviation Line Alone mode hides the individual iterations and displays only the summarised signal - useful for traders who want the signal without the visual complexity of 30 simultaneous plots.
Alerts
Four alert conditions are built in. Early Warning alerts fire when the standard deviation crosses zero but has not yet confirmed on a closed bar - providing advance notice that a signal may be forming. Confirmed alerts fire one bar later when the signal is closed and established. Both long and short versions are available, giving traders the choice between early action and confirmed entry depending on their style.
Backtest Framework
An integrated backtest engine simulates trades directly on the chart using the Logistic Map signals, allowing the oscillator's historical performance to be evaluated without leaving TradingView.
Three trade modes are supported. Long Only simulates only long entries, exiting on short signals or stop loss. Short Only simulates only short entries. Both simulates entries in either direction, with an optional Reverse on Opposite Signal mode that immediately flips the position when the opposite signal fires - keeping the simulation continuously in the market once started.
Entry and exit labels are displayed at each trade with tooltips showing direction, entry price, percentage change, and current capital. An Early Warning label flags the bar before a potential entry, deleted automatically if the signal does not confirm. A floating Trade Statistics label updates in real time, showing win rate, total trades, long and short win/loss breakdown, compounding capital, current unrealised PnL, and active stop loss level.
An optional stop loss exits the trade intrabar when price moves against the position by a configurable percentage - long positions exit when the low reaches the stop level, short positions when the high reaches it.
Candle confirmation filters can require bullish bars for long entries and bearish bars for short entries. A Same-Bar Conflict filter skips entries when both long and short signals fire simultaneously, avoiding false entries during volatile spikes.
Chart background colouring reflects the active trade direction in real time - teal for long, red for short - making the current position state immediately visible at a glance.
A note on the backtest: The framework is designed for exploration and signal evaluation, not for generating tradeable strategies. Past performance of any simulated result does not indicate future results. Use it to understand the signal's historical behaviour - not to make trading decisions.
Logistic Map length, all oscillator lengths, display style, backtest period, initial capital, stop loss percentage, trade mode, and all visual elements are fully configurable.