PROTECTED SOURCE SCRIPT

XPloRR S&P500 Stock Market Crash Detection Strategy v2

Actualizado
XPloRR S&P500 Stock Market Crash Detection Strategy v2

Long-Term Trailing-Stop strategy detecting S&P500 Stock Market Crashes/Corrections and showing Volatility as warning signal for upcoming crashes

Detecting or avoiding stock market crashes seems to be the 'Holy Grail' of strategies.
Since none of the strategies that I tested can beat the long term Buy&Hold strategy, the purpose was to detect a stock market crash on the S&P500 and step out in time to minimize losses and beat the Buy&Hold strategy. So beat the Buy&Hold strategy with around 10 trades. 100% capitalize sold trade into new trade.

With the default parameters the strategy generates 10262% profit (starting at 01/01/1962 until release date), with 10 closed trades, 100% profitable, while the Buy&Hold strategy only generates 3633% profit, so this strategy beats the Buy&Hold strategy by 2.82 times!
Also the strategy detects all major S&P500 stock market crashes and corrections since 1962 depending on the Trailing Stop Smoothness parameter, and steps out in time to cut losses and steps in again after the bottom has been reached. The 5 major crashes/corrections of 1987, 1990, 2001, 2008 and 2010 were successfully detected with the default parameters.
The script was first released on November 03 2019 and detected the Corona Crash on March 04 2020 with a Volatility crash-alert and a Sell crash-alert.

I have also created an Alerter Study Script based on the engine of this script, which generates Buy, Sell and Volatility signals.
If you are interested in this Alerter version script, please drop me a mail.

The script shows a lot of graphical information:
  • the Close value is shown in light-green. When the Close value is temporarily lower than the Buy value, the Close value is shown in light-red. This way it is possible to evaluate the virtual losses during the current trade.
  • the Trailing Stop value is shown in dark-green. When the Sell value is lower than the Buy value, the last color of the trade will be red (best viewed when zoomed)
  • the EMA and SMA values for both Buy and Sell signals are shown as colored graphs
  • the Buy signals are labeled in blue and the Sell signals are labeled in purple
  • the Volatility is shown below in green and red. The Alert Threshold (red) is default set to 2 (see Volatility Threshold parameter below)


How to use this Strategy?
  • Select the SPX (S&P500) graph and add this script to the graph.
  • Look in the strategy tester overview to optimize the values Percent Profitable and Net Profit (using the strategy settings icon, you can increase/decrease the parameters), then keep using these parameters for future Buy/Sell signals on the S&P500.
  • More trades don't necessarily generate more overall profit. It is important to detect only the major crashes and avoid closing trades on the smaller corrections. Bearing the smaller corrections generates a higher profit.
  • Watch out for the Volatility Alerts generated at the bottom (red). The Threshold can by changed by the Volatility Threshold parameter (default=2% ATR). In almost all crashes/corrections there is an alert ahead of the crash.
    Although the signal doesn't predict the exact timing of the crash/correction, it is a clear warning signal that bearish times are ahead!
  • The correction in December 2018 was not a major crash but there was already a red Volatility warning alert. If the Volatility Alert repeats the next weeks/months, chances are higher that a bigger crash or correction is near. As can be seen in the graphic, the deeper the crash is, the higher and wider the red Volatility signal goes. So keep an eye on the red flag!


Here are the parameters:
  • Fast MA Buy: buy trigger when Fast MA Buy crosses over the Slow MA Buy value (use values between 10-20)
  • Slow MA Buy: buy trigger when Fast MA Buy crosses over the Slow MA Buy value (use values between 21-50)
  • Minimum Buy Strength: minimum upward trend value of the Fast MA Buy value (directional coefficient)(use values between 10-100)
  • Fast MA Sell: sell trigger when Fast MA Sell crosses under the Slow MA Sell value (use values between 10-20)
  • Slow MA Sell: sell trigger when Fast MA Sell crosses under the Slow MA Sell value (use values between 21-50)
  • Minimum Sell Strength: minimum downward trend value of the Fast MA Sell value (directional coefficient)(use values between 10-100)
  • Trailing Stop ATR: trailing stop % distance from the smoothed Close value (use values between 2-20)
  • Trailing Stop Smoothness: MA value for smoothing out the Trailing Stop close value
  • Buy On Start Date: force Buy on start date even without Buy signal (default: true)
  • Sell On End Date: force Sell on end date even without Sell signal (default: true)
  • Volatility EMA Period: MA value of the Volatility value (default 15)
  • Volatility Threshold: Threshold value to change volatility graph to red (default 2)
  • Volatility Graph Scaler: Scaling of the volatility graph (default 5)


Important: optimizing and using these parameters is no guarantee for future winning trades!
Notas de prensa
Stochastic RSI Min-Max Strategy [XPloRR]

S&P500 (SPX) strategy using Stochastic RSI Min-Max, normalized Volatility and Trailing Stop signals

Detecting when to enter or leave the SPX tracker at the right moment seems to be the 'Holy Grail' of strategies.
Since none of the strategies that I tested can beat the long term Buy&Hold strategy, the purpose was to create a strategy that beats the Buy&Hold strategy backtested from the early beginning of the S&P500 data at around 1870 until today. Backtesting was done starting with 1.000 USD and buying/selling always with 100% of the capital/stocks.

With the default parameters this strategy generates 925899 % profit (starting at feb 1871), while the Buy&Hold strategy "only" generates 163582 % profit, so this strategy beats the Buy&Hold strategy by 5.66 times!
So if you invested 1.000 USD in 1871, you would now (feb 2024) own 9.258.997 USD!

The strategy detects "corrections" depending on the Trailing Stop parameters, and steps out in time to cut losses and steps in again after the bottom has been reached using tuned Stochastic RSI signals combined with normalized Volatility thresholds.
This strategy can also be used in case you never step out, but only want to buy at regular intervals using the buy signals only.

Update: Alerter Version
I have also created an Alerter script based on the same engine as this script, which auto-generates buy and sell alert signals (via e-mail, in-app push-notifications, pop-ups etc.).
The script is currently fine-tuned for the S&P500 SPX tracker, but parameters can be fine-tuned upon request for other trackers or stocks.
If you are interested in this alerter-version script or fine-tuning other trackers, please drop me a message or mail xplorr at live dot com.

How to use this Strategy?
  • Select the SPX (S&P500) graph and set the value to "Day" values (top) and set "Auto Fit Data To Screen" (bottom-right).
  • Select in the Indicators the "Stochastic RSI Min-Max Strategy [XPloRR]" script and set "Auto Fit Data To Screen" (bottom-right)
  • Look in the strategy tester overview to optimize the values "Percent Profitable" and "Net Profit" (using the strategy settings icon, you can increase/decrease the parameters).


How to interpret the graphical information?
  • In the SPX graph, you will see the Buy(Blue) and Sell(Purple) signals.
  • The green/red graph below shows the accumulated profit/loss in % of to the initial buy value of the trade (it revolves around 100%, 110 means 10% profit, 95 means 5% loss)
  • The small purple blocks indicate out-of-trade periods
  • The green graph below the zero line is the stochastic RSI buy signal. You can set a threshold (green horizontal line). The vertical green lines show minima below that threshold and indicate possible buy signals.
  • The blue graph above the zero line is the normalized volatility signal. You can set a threshold (blue horizontal line).
  • The red graph above the zero line is the slower stochastic RSI sell signal. You can set a threshold (red horizontal line). The vertical red lines show maxima above that threshold and indicate possible exit signals.
    However real exits are triggered if close values are crossing below the trailing stop value. The red lines and areas above the exit threshold are rather indicative to show that the SPX is expensive and not ideal to enter. Please note that in bullish periods the red line can stay at a permanent high value, so it is not ideal to use as a strict sell signal. However, when it drops below zero and the green vertical lines appear, these are strong buy signals together with a high volatility.


These Parameters can be changed
  • Buy Stochastic Lookback
  • Buy Stochastic Smoother
  • Buy Threshold
  • Buy Only After Fall
  • Minimum % Fall
  • Sell Stochastic Lookback
  • Sell Stochastic Smoother
  • Sell Threshold
  • Sell Only With Profit
  • Minimum % Profit
  • Volatility Smoother
  • Volatility Threshold
  • Use ATR (iso of a fixed percentage for the trailing stop)
  • ATR Lookback
  • Trailing Stop Factor(or fixed percentage if "use ATR" is false)
  • Stock Value Smoother (for checking the trailing stop)


Important: optimizing and using these parameters is no guarantee for future winning trades!
Notas de prensa
Stochastic RSI Min-Max Strategy [XPloRR]

S&P500 (SPX) strategy using Stochastic RSI Min-Max, normalized Volatility and Trailing Stop signals

Detecting when to enter or leave the SPX tracker at the right moment seems to be the 'Holy Grail' of strategies.
Since none of the strategies that I tested can beat the long term Buy&Hold strategy, the purpose was to create a strategy that beats the Buy&Hold strategy backtested from the early beginning of the S&P500 data at around 1870 until today. Backtesting was done starting with 1.000 USD and buying/selling always with 100% of the capital/stocks.

With the default parameters this strategy generates 2.663.001 % profit (starting at feb 1871), while the Buy&Hold strategy "only" generates 162.599 % profit, so this strategy beats the Buy&Hold strategy by 16.38 times!
So if you invested 1.000 USD in 1871, you would now (feb 2024) own 26.630.014 USD!

The strategy detects "corrections" depending on the Trailing Stop and Moving Average parameters, and steps out in time to cut losses and steps in again after the bottom has been reached using tuned Stochastic RSI signals combined with normalized Volatility thresholds.
This strategy can also be used in case you never step out (Buy&Hold strategy), but only want to start new buy trades at regular intervals using the buy signals only.
What this strategy also learned is that putting a trailing stop of 9% on your trades has proven to be the most effective strategy to cut losses.

Update: Alerter Version
I have also created an Alerter script based on the same engine as this script, which auto-generates buy and sell alert signals (via e-mail, in-app push-notifications, pop-ups etc.).
The script is currently fine-tuned for the S&P500 SPX tracker, but parameters can be fine-tuned upon request for other trackers or stocks.
If you are interested in this alerter-version script or fine-tuning other trackers, please drop me a message or mail xplorr at live dot com.

How to use this Strategy?
  • Select the SPX (S&P500) graph and set the value to "Day" values (top) and set "Auto Fit Data To Screen" (bottom-right).
  • Select in the Indicators the "Stochastic RSI Min-Max Strategy [XPloRR]" (aka under its old name XPloRR S&P500 Stock Market Crash Detection Strategy v2) script and set "Auto Fit Data To Screen" (bottom-right)
  • Look in the strategy tester overview to optimize the values "Percent Profitable" and "Net Profit" (using the strategy settings icon, you can increase/decrease the parameters).


How to interpret the graphical information?
  • In the SPX graph, you will see the Buy(Blue) and Sell(Purple) labels created by the strategy.
  • The green/red graph below shows the accumulated profit/loss in % of to the initial buy value of the trade (it revolves around 100%, 110 means 10% profit, 95 means 5% loss)
  • The small purple blocks indicate out-of-trade periods
  • The green graph below the zero line is the stochastic RSI buy signal. You can set a threshold (green horizontal line). The vertical green lines show minima below that threshold and indicate possible buy signals.
  • The blue graph above the zero line is the normalized volatility signal. You can set a threshold (blue horizontal line) affecting buy signals.
  • The red graph above the zero line is the slower stochastic RSI sell signal. You can set a threshold (red horizontal line). The red areas indicate values above that threshold.
    However real exits are triggered if close values are crossing below the trailing stop value or optionally when the fast moving average crosses under the slow one. The red areas above the threshold are rather indicative to show that the SPX is expensive and not ideal to enter. Please note that in bullish periods the red line and areas can stay at a permanent high value, so it is not ideal to use as a strict sell signal. However, when it drops below zero and the green vertical lines appear, these are strong buy signals together with a high volatility.


These Parameters can be changed
  • Buy Stochastic Lookback
  • Buy Stochastic Smoother
  • Buy Threshold
  • Buy Only After Fall
  • Minimum % Fall
  • Sell Stochastic Lookback
  • Sell Stochastic Smoother
  • Sell Threshold
  • Sell Only With Profit
  • Minimum % Profit
  • Use Sell MA
  • Fast MA Sell
  • Slow MA Sell
  • MA Sell Threshold
  • Use Buy Volatility
  • Volatility Smoother
  • Volatility Threshold
  • Use Trailing Stop
  • Use ATR (iso of a fixed percentage for the trailing stop)
  • ATR Lookback
  • Trailing Stop Factor(or fixed percentage if "use ATR" is false)
  • Trailing Stop Smoother


Important: optimizing and using these parameters is no guarantee for future winning trades!
Average True Range (ATR)Exponential Moving Average (EMA)relative-strength-indexrsistochasticSPX (S&P 500 Index)S&P 500 (SPX500)Stochastic RSI (STOCH RSI)trackertrailing-stoptrailingstoptrailingstoplossvolatilty

Script protegido

Este script se publica con código cerrado, pero puede utilizarlo libremente. Márquelo como favorito y podrá usarlo en un gráfico. El código fuente no se puede ver ni modificar.

¿Quiere utilizar este script en un gráfico?

Exención de responsabilidad