OPEN-SOURCE SCRIPT
System 0530 - Stoch RSI Strategy v13 SL-Priority TP-Reversal

Strategy Overview: System 0530 - Stochastic RSI Multi-Timeframe
This TradingView Pine Script outlines a strategy primarily based on the Stochastic RSI (Stoch RSI) indicator, employing a multi-timeframe approach for signal generation and confirmation. It is designed to operate on a 5-minute chart, referencing 15-minute data for higher-level context.
Core Mechanics:
Primary Indicator: Stochastic RSI, used to identify overbought/oversold conditions and potential momentum shifts.
Timeframes:
5-minute chart: For initial signal triggers and primary execution.
15-minute chart: For signal confirmation and certain take-profit conditions.
Entry Logic:
Bullish Market Bias Adjustment: Reflecting an overall bullish market trend, this strategy is intended to be applied with more tolerance or lower requirements for triggering long positions compared to short positions. This can be achieved by adjusting the input parameters accordingly (e.g., setting a higher stoch_5min_k_long_trigger threshold, allowing longs to trigger when less oversold, or a higher stoch_15min_long_entry_level, requiring less deep confirmation for longs).
5-Minute Initial Trigger:
Long: 5-minute Stoch RSI K-line crosses above its D-line, AND the K-value at the time of the cross is below a specified stoch_5min_k_long_trigger level.
Short: 5-minute Stoch RSI K-line crosses below its D-line, AND the K-value at the time of the cross is above a specified stoch_5min_k_short_trigger level.
15-Minute Confirmation:
After a 5-minute trigger, the strategy waits for a configurable number of 5-minute bars (wait_window_5min_bars) for confirmation from the 15-minute timeframe.
Long Confirmation: 15-minute Stoch RSI K-line must be strictly greater than its D-line, AND the 15-minute K-value must be below stoch_15min_long_entry_level.
Short Confirmation: 15-minute Stoch RSI K-line must be strictly less than its D-line, AND the 15-minute K-value must be above stoch_15min_short_entry_level.
Position Lock: No new entry signals are generated if the strategy already holds an open position.
Duplicate Signal Filter: A cooldown period, defined by min_bars_between_signals, must pass before another signal in the same direction can be considered.
Exit Logic:
Stop-Loss (SL):
The SL is set based on the low (for longs) or high (for shorts) of the 5-minute bar on which the trade was entered.
The position is closed if a subsequent 5-minute bar's closing price moves beyond this SL level.
SL checks are prioritized over Take-Profit checks.
Take-Profit (TP) - Two-Stage Mechanism:
TP1 (Closes 50% of the position):
Priority A (Extreme K Levels): If the 5-minute Stoch K OR 15-minute Stoch K value exceeds extreme_long_tp_level (for longs) or drops below extreme_short_tp_level (for shorts).
Priority B (Conditional 5-min Cross + 15-min K-Reversal): If Extreme K conditions are not met, TP1 is triggered if:
A 5-minute Stoch RSI K/D crossover occurs (K crosses below D for longs; K crosses above D for shorts - using strict ta.crossunder/ta.crossover).
AND this 5-minute crossover is confirmed by a 15-minute Stoch K-value "reversal" (current 15m K < previous 15m K for longs; current 15m K > previous 15m K for shorts).
TP2 (Closes remaining 50% of the position):
This stage is active only after TP1 has been taken.
If the 5-minute Stoch K OR 15-minute Stoch K value reaches the same extreme_long_tp_level or extreme_short_tp_level again, a waiting period begins, defined by tp2_extreme_k_wait_bars (number of 5-minute bars).
If the extreme K condition persists after this waiting period, TP2 is executed.
If the extreme K condition disappears during the waiting period, the TP2 attempt for that instance is cancelled.
If tp2_extreme_k_wait_bars is set to 0, TP2 will trigger immediately upon the extreme K condition being met after TP1.
Note on Fine-Tuning (as per user context):
This strategy has been specifically fine-tuned for SPY. As with any trading system, its performance can vary across different instruments and market conditions. The user notes that to potentially maximize profits, especially in trending scenarios where the current "Extreme K" based TP2 might exit prematurely, it is advisable to explore and integrate other indicators or alternative take-profit methodologies. Dynamic approaches like ATR (Average True Range) trailing stops or trend-following exit signals could be considered for managing the second portion of the position.
This TradingView Pine Script outlines a strategy primarily based on the Stochastic RSI (Stoch RSI) indicator, employing a multi-timeframe approach for signal generation and confirmation. It is designed to operate on a 5-minute chart, referencing 15-minute data for higher-level context.
Core Mechanics:
Primary Indicator: Stochastic RSI, used to identify overbought/oversold conditions and potential momentum shifts.
Timeframes:
5-minute chart: For initial signal triggers and primary execution.
15-minute chart: For signal confirmation and certain take-profit conditions.
Entry Logic:
Bullish Market Bias Adjustment: Reflecting an overall bullish market trend, this strategy is intended to be applied with more tolerance or lower requirements for triggering long positions compared to short positions. This can be achieved by adjusting the input parameters accordingly (e.g., setting a higher stoch_5min_k_long_trigger threshold, allowing longs to trigger when less oversold, or a higher stoch_15min_long_entry_level, requiring less deep confirmation for longs).
5-Minute Initial Trigger:
Long: 5-minute Stoch RSI K-line crosses above its D-line, AND the K-value at the time of the cross is below a specified stoch_5min_k_long_trigger level.
Short: 5-minute Stoch RSI K-line crosses below its D-line, AND the K-value at the time of the cross is above a specified stoch_5min_k_short_trigger level.
15-Minute Confirmation:
After a 5-minute trigger, the strategy waits for a configurable number of 5-minute bars (wait_window_5min_bars) for confirmation from the 15-minute timeframe.
Long Confirmation: 15-minute Stoch RSI K-line must be strictly greater than its D-line, AND the 15-minute K-value must be below stoch_15min_long_entry_level.
Short Confirmation: 15-minute Stoch RSI K-line must be strictly less than its D-line, AND the 15-minute K-value must be above stoch_15min_short_entry_level.
Position Lock: No new entry signals are generated if the strategy already holds an open position.
Duplicate Signal Filter: A cooldown period, defined by min_bars_between_signals, must pass before another signal in the same direction can be considered.
Exit Logic:
Stop-Loss (SL):
The SL is set based on the low (for longs) or high (for shorts) of the 5-minute bar on which the trade was entered.
The position is closed if a subsequent 5-minute bar's closing price moves beyond this SL level.
SL checks are prioritized over Take-Profit checks.
Take-Profit (TP) - Two-Stage Mechanism:
TP1 (Closes 50% of the position):
Priority A (Extreme K Levels): If the 5-minute Stoch K OR 15-minute Stoch K value exceeds extreme_long_tp_level (for longs) or drops below extreme_short_tp_level (for shorts).
Priority B (Conditional 5-min Cross + 15-min K-Reversal): If Extreme K conditions are not met, TP1 is triggered if:
A 5-minute Stoch RSI K/D crossover occurs (K crosses below D for longs; K crosses above D for shorts - using strict ta.crossunder/ta.crossover).
AND this 5-minute crossover is confirmed by a 15-minute Stoch K-value "reversal" (current 15m K < previous 15m K for longs; current 15m K > previous 15m K for shorts).
TP2 (Closes remaining 50% of the position):
This stage is active only after TP1 has been taken.
If the 5-minute Stoch K OR 15-minute Stoch K value reaches the same extreme_long_tp_level or extreme_short_tp_level again, a waiting period begins, defined by tp2_extreme_k_wait_bars (number of 5-minute bars).
If the extreme K condition persists after this waiting period, TP2 is executed.
If the extreme K condition disappears during the waiting period, the TP2 attempt for that instance is cancelled.
If tp2_extreme_k_wait_bars is set to 0, TP2 will trigger immediately upon the extreme K condition being met after TP1.
Note on Fine-Tuning (as per user context):
This strategy has been specifically fine-tuned for SPY. As with any trading system, its performance can vary across different instruments and market conditions. The user notes that to potentially maximize profits, especially in trending scenarios where the current "Extreme K" based TP2 might exit prematurely, it is advisable to explore and integrate other indicators or alternative take-profit methodologies. Dynamic approaches like ATR (Average True Range) trailing stops or trend-following exit signals could be considered for managing the second portion of the position.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.