TASC 2026.07 Risk-On, Risk-Off, Or Caution — Strategy by PineCodersTASC

By PineCodersTASC

Performance Metrics

Description

█ OVERVIEWThis strategy implements the portfolio allocation strategy presented by Gaetano Di Prima & Fabio Baruffa in the July 2026 edition of the TASC Traders' Tips "Market Regime Identification Using Trend, Volatility, And Credit Conditions". The article describes a regime-based allocation strategy, which uses a combination of trend, volatility, and credit spread measures to indicate three regime states and adjust exposure accordingly.█ COMPONENTSThe regime classification combines three components:Trend Filter: The system uses a 200-day Simple Moving Average (SMA) of SPX. A popular long-term trend filter, this is not intended to detect tops and bottoms, and simply serves as a baseline condition for taking on risk. When SPX is above its 200 SMA, conditions are seen as favorable.Volatility Filter: The system measures market stress by comparing the short-term CBOE Volatility Index (VIX) to its longer term three-month counterpart (VIX3M). During market stress, short-term volatility typically rises sharply, which is associated with uncertainty and higher short-term risk. For this reason, the system checks for VIX to be less-than VIX3M under favorable conditions.Risk Appetite: Credit markets can provide insight into the willingness of investors to take on risk. By computing a ratio between High Yield Corporate Bonds (HYG) and 7–10 Year Treasury bonds (IEF), the specific appetite of investors can be determined. When the 100MA of the rolling Z-score for the HYG/IEF spread is positive, conditions are considered favorable.█ THE RULESThe rules are simple. At the end of every week, the script assesses the conditions and adjusts the position accordingly. The strategy places an order to be executed at Monday's open with the changes to the position, if any. If all conditions are favorable, modify the position to have full exposure. If 2/3 conditions are favorable, modify the position to only have 50% exposure. If 1/3 or 0/3 conditions are favorable, modify the position to have no exposure.▌PropertiesPosition Sizing: This strategy manages and allocates up to 100% of equity, the same as in the article.Commissions: Commission value is set to $0. Most major US brokers charge $0 commission on stocks and ETF trades.Slippage: Slippage is set to three ticks to simulate less-than-ideal execution conditions.█ DISPLAYThe display shows blue bars in a separate pane, indicating the specific conditions and their Boolean values at the time. Together, these values determine the specific "regime" state that the system is in.The script colors the background of the chart pane to indicate the current regime. Red indicates "Risk OFF", yellow indicates "Caution", and green indicates "Risk ON". A table in the separate pane provides a key for the colors as well.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView