Persistency with Moving AveragesThis indicator is inspired by the concept of Persistency introduced by Pradeep Bonde . Bonde emphasizes that it's not just about knowing the direction of a trend, but also about understanding how resilient that trend is over time. Stocks that consistently move in the direction of the trend have better odds of continuing that trend. By identifying such stocks, traders can improve their chances of catching both more and bigger winners.
Bonde's original concept can be refined further by tracking how long a price has stayed in a certain trend direction relative to a key moving average. Instead of solely counting the instances where the close is higher than the previous close, this script tracks how many bars (periods) the price has stayed above or below certain moving averages. Moving averages act as dynamic support and resistance levels, providing a more nuanced view of price behavior.
Key Components
Calculating Moving Averages : The indicator calculates up to four moving averages based on user settings. Users can choose the type (EMA or SMA), length, and color of each MA.
Updating Counts : The indicator updates counts for each MA on every bar. Counts increase when the price stays on the same side of the MA. Counts reset and change sign when the price crosses the MA.
Decisive Exit Logic : When enabled, the indicator starts a pending exit if the price meets certain conditions. A decisive exit occurs if the price reaches the stored exit level. Users can select whether to use the close price or high/low prices for pending exits.
Maximum Persistency : This tracks the longest period that the price has remained either above or below a specified moving average. For example, if you're looking at the 21-day EMA and see that the Max value is 100, this means that over the lookback period chosen, the price remained above the 21-day EMA for a maximum of 100 consecutive bars (days). This only applies to daily and higher timeframes.
Entry and Exit Signals : Entry signals are generated when the price crosses above an MA (positive count starts). Exit signals are generated when the price crosses below an MA (negative count starts). Signals are displayed as markers on the chart.
Table and Directional Header : The table displays the MAs, counts, and pending exit status. The header shows an arrow indicating the overall momentum direction based on the counts: ↑ (Up Arrow): Indicates persistent upward momentum. ↓ (Down Arrow): Indicates persistent downward momentum. → (Right Arrow): Indicates a sideways or mixed momentum.
Customization and Settings
Moving Averages Settings:
Show MA #1 to MA #4 : Enable or disable each MA.
MA Type : Select between Exponential Moving Average (EMA) and Simple Moving Average (SMA).
MA Length : Set the period for each MA (e.g., 10, 21, 50, 200).
MA Color : Choose the color for each MA plotted on the chart.
Exit Logic Settings:
Use Decisive Exit for Count : Enable to use pending exits and decisive exit logic.
Show Pending Exit : Display the pending exit status in the table.
Price to Use for Decisive Exit : Choose between using the Close price or High/Low prices to trigger pending exits.
Signal Display Settings:
Show Entry/Exit Signals:
Toggle the display of entry and exit markers on the chart.
Display color-coded labels in the table corresponding to each MA.
Max persistency Settings:
Toggle the display of Max persistency column
Select a lookback period for 'maximum' persistency
Understanding Decisive Exit
A decisive exit is a strategic approach to exiting a trade based on specific, predefined conditions that indicate a significant change in the trend's persistence. It's about being proactive rather than reactive.
Pending Exit Mechanism: In a positive count (price above MA), a pending exit is initiated when the price shows signs of weakening. Users can choose between using the close price or the high/low prices for triggering pending exits. When the trigger condition is met, the script stores the low of that bar as the exit level.
Confirming the Decisive Exit: The decisive exit occurs if the price reaches or breaches the stored exit level. This confirms that the momentum has decisively shifted, prompting an exit from the trade.
Immediate Re-Entry Consideration: After a decisive exit, the script checks for immediate conditions that might warrant entering a new position in the opposite direction. This ensures that traders don't miss potential opportunities that arise quickly after an exit.
Applications of the Indicator
Identifying Persistent Trends : Use the counts to find stocks that have consistently moved in one direction. Persistent positive counts may indicate a strong upward trend.
Timing Entries and Exits : Entry and exit signals help in timing trades based on moving average crossovers. The pending exit feature allows for more conservative exit strategies.
Assessing Momentum Across Time Frames : By configuring MAs of different lengths, you can assess momentum over various periods.
Conclusion
The Persistency with Moving Averages indicator offers a powerful way to assess and capitalize on the persistence of momentum in the markets. By combining the concept of persistent momentum with customizable moving averages and flexible exit logic, traders can enhance their strategies to identify and exploit sustained trends.
Disclaimer:
Trading involves significant risk. This indicator is a tool to assist in analysis and should not be used as the sole basis for any trading decision. Always conduct your own research and consider consulting a financial advisor. Always consider combining this indicator with other analysis tools and risk management practices to make well-informed trading decisions.
Wskaźnik Pine Script®






















