MFE MAE Regime Distances by [Itto-Ryu]

READ THIS FIRST: WHAT MFE AND MAE ARE
MFE (Maximum Favorable Excursion) is the furthest price moved in the direction of a position while it was open. MAE (Maximum Adverse Excursion) is the furthest price moved against it over the same period. Both are measured from the entry price and both describe the path of a trade, not its result. The idea comes from John Sweeney's work on adverse excursion; the E-ratio shown in the Data Window (average MFE divided by average MAE) follows Curtis Faith.
Collected over many past cases, MFE and MAE become distributions. Their percentiles answer questions of distance: how far did price usually travel within a given number of bars, and how far did it usually come back. They do not say which way price will go next.
This indicator is written for traders who already work with these two concepts. If MFE and MAE are new to you, please study the concept before using the script. Use the levels as a guideline for distance, next to your own analysis. They are not entry, exit or stop signals, and no level here should be the reason for a decision on its own.
WHAT THE SCRIPT DOES
It measures, on the chart's own history, how far price moved from past swing points within the next H bars (default 10), expresses those distances in ATR, and draws the resulting percentile levels from the swing point of the leg that is running now. A dashboard shows the same reading for 30m, 1H, 4H, 1D and 1W.
HOW IT WORKS
• Swings: an ATR zigzag on closed bars. A swing high or low is confirmed when price comes back 2 ATR (input "Reversal size") from the extreme. A swing exists only from the bar that confirms it.
• MFE levels (default mode "Swing point · MFE"): for every past swing of the same kind, the largest move in the leg's direction within the next H bars, divided by ATR(14) of the swing bar. The P25, P50, P75 and P90 of these distances are drawn from the swing point that started the running leg.
• Rebound / pullback guide (the MAE side): for every past closed bar that was the extreme of its leg, the largest move against the leg within the next H bars, divided by ATR of that bar. These levels are drawn from the running leg's low or high and move with it while the leg extends.
• Regime: ADX(14) above 25 with +DI above -DI is Trend up, with -DI above +DI is Trend down, ADX at or below 25 is Sideways. The regime is read on the last closed bar.
• A percentile is calculated only when more than 20 past cases exist. Otherwise the value shows "-".
READING THE CHART
• Swing high / Swing low: the confirmed swing where the running leg started.
• Leg low / Leg high: the furthest point of the running leg, with its length in ATR.
• Reversal: the price at which the running leg would end and a new swing be confirmed.
• Level labels such as "MFE P50 · 50%": P50 is the level, 50% is the share of past cases that travelled at least that far within H bars. P25 · 75%, P75 · 25% and P90 · 10% read the same way. These are shares of past cases, not probabilities of future moves.
• A check mark after a price means the level has been reached: MFE levels by the leg's low or high, rebound / pullback levels by the last closed price.
• When the running leg goes against the regime (an up leg in Trend down, a down leg in Trend up), the levels in the leg's direction are named Rebound (MAE) or Pullback (MAE) and the levels on the other side Resume (MFE). The numbers are the same; only the names and colours change.
DASHBOARD
One row per timeframe (30m, 1H, 4H, 1D, 1W), each calculated inside its own timeframe: Regime with ADX, ATR, the running leg (swing point and extreme), MFE P50 and P75 as prices, MAE P50 and P75 as prices, and Reversal. The two "At" columns show the furthest of the P25 / P50 / P75 / P90 levels already reached. MFE columns hold the levels in the direction of that row's regime, MAE columns the levels against it; in Sideways, MFE follows the running leg. "Dashboard = Full" adds a detail table for the chart's timeframe.
OTHER MODES ("REFERENCE LEVELS FROM")
• Swing point · leg end: where past legs in the same direction ended, counting only legs that had already reached the current length.
• Last close: the classic form. Every closed bar is treated as an entry at the next bar's open; MFE and MAE over H bars are split by regime and drawn from the last closed price. The detail table then also shows opening gaps, a split by entry bar, and the number of entries (n) with the number of non-overlapping entries (n_eff).
INPUTS AND DEFAULTS
• Holding bars (H) = 10: the window in which each excursion is measured.
• ATR length 14, DMI length 14, ADX smoothing 14, ADX threshold 25: common textbook settings, chosen so that the regime reads the same as a standard ADX/DMI.
• Reversal size = 2 ATR: the zigzag threshold. A smaller value gives more and shorter legs.
• Intraday break = Auto: how a lunch break is detected for the gap rows (a time window on TFEX symbols, a time gap elsewhere).
• Text size, table positions and the show / hide switches only change the display.
All distances are in ATR, so the same defaults can be applied to any symbol and timeframe.
HOW TO USE IT
• Decide direction and timing with your own method first. Then read the levels to see how far similar moves went in the past and where the running leg stands against that history.
• A leg marked at or beyond P75 has already gone further than three quarters of past cases in their first H bars. That describes the leg; it does not say the leg is over.
• Compare rows in the dashboard to see whether a move on a small timeframe is still inside the usual rebound or pullback distance of a larger one.
LIMITATIONS
• A baseline of past swings and bars, not the result of any trading rule. No commission or slippage.
• Neighbouring samples overlap, so they are not independent. Percentiles from few cases are rough: the weekly row often has only a few dozen swings per direction.
• Results depend on the history TradingView loads for the chart, so the same row can differ slightly between chart timeframes.
• Continuous futures symbols are not back-adjusted here.
• The rebound / pullback statistic covers only the first H bars after a leg extreme.
DISCLOSURES
• Pine Script v6. Open-source.
• Repainting: swings, regime and statistics use closed bars only, and a swing appears only after the bar that confirms it has closed. Levels measured from the leg's extreme move when the leg makes a new extreme; this is intended. Higher-timeframe rows use lookahead off.
• Chart type: standard charts only. On Heikin Ashi, Renko and other non-standard charts the table shows a warning and the values are not valid.
• No signals and no alerts. Past distances do not predict future prices. Not investment advice.
• Concept credits: MFE / MAE after John Sweeney; E-ratio after Curtis Faith. The code is original.
DISCLAIMER
This script is published for educational and informational purposes only. It describes how far price moved in the past and does not provide trading signals, financial advice or a recommendation to buy or sell any instrument. Past price behaviour does not guarantee future results. Trading involves risk, including the loss of capital. You alone are responsible for your own decisions.
MFE (Maximum Favorable Excursion) is the furthest price moved in the direction of a position while it was open. MAE (Maximum Adverse Excursion) is the furthest price moved against it over the same period. Both are measured from the entry price and both describe the path of a trade, not its result. The idea comes from John Sweeney's work on adverse excursion; the E-ratio shown in the Data Window (average MFE divided by average MAE) follows Curtis Faith.
Collected over many past cases, MFE and MAE become distributions. Their percentiles answer questions of distance: how far did price usually travel within a given number of bars, and how far did it usually come back. They do not say which way price will go next.
This indicator is written for traders who already work with these two concepts. If MFE and MAE are new to you, please study the concept before using the script. Use the levels as a guideline for distance, next to your own analysis. They are not entry, exit or stop signals, and no level here should be the reason for a decision on its own.
WHAT THE SCRIPT DOES
It measures, on the chart's own history, how far price moved from past swing points within the next H bars (default 10), expresses those distances in ATR, and draws the resulting percentile levels from the swing point of the leg that is running now. A dashboard shows the same reading for 30m, 1H, 4H, 1D and 1W.
HOW IT WORKS
• Swings: an ATR zigzag on closed bars. A swing high or low is confirmed when price comes back 2 ATR (input "Reversal size") from the extreme. A swing exists only from the bar that confirms it.
• MFE levels (default mode "Swing point · MFE"): for every past swing of the same kind, the largest move in the leg's direction within the next H bars, divided by ATR(14) of the swing bar. The P25, P50, P75 and P90 of these distances are drawn from the swing point that started the running leg.
• Rebound / pullback guide (the MAE side): for every past closed bar that was the extreme of its leg, the largest move against the leg within the next H bars, divided by ATR of that bar. These levels are drawn from the running leg's low or high and move with it while the leg extends.
• Regime: ADX(14) above 25 with +DI above -DI is Trend up, with -DI above +DI is Trend down, ADX at or below 25 is Sideways. The regime is read on the last closed bar.
• A percentile is calculated only when more than 20 past cases exist. Otherwise the value shows "-".
READING THE CHART
• Swing high / Swing low: the confirmed swing where the running leg started.
• Leg low / Leg high: the furthest point of the running leg, with its length in ATR.
• Reversal: the price at which the running leg would end and a new swing be confirmed.
• Level labels such as "MFE P50 · 50%": P50 is the level, 50% is the share of past cases that travelled at least that far within H bars. P25 · 75%, P75 · 25% and P90 · 10% read the same way. These are shares of past cases, not probabilities of future moves.
• A check mark after a price means the level has been reached: MFE levels by the leg's low or high, rebound / pullback levels by the last closed price.
• When the running leg goes against the regime (an up leg in Trend down, a down leg in Trend up), the levels in the leg's direction are named Rebound (MAE) or Pullback (MAE) and the levels on the other side Resume (MFE). The numbers are the same; only the names and colours change.
DASHBOARD
One row per timeframe (30m, 1H, 4H, 1D, 1W), each calculated inside its own timeframe: Regime with ADX, ATR, the running leg (swing point and extreme), MFE P50 and P75 as prices, MAE P50 and P75 as prices, and Reversal. The two "At" columns show the furthest of the P25 / P50 / P75 / P90 levels already reached. MFE columns hold the levels in the direction of that row's regime, MAE columns the levels against it; in Sideways, MFE follows the running leg. "Dashboard = Full" adds a detail table for the chart's timeframe.
OTHER MODES ("REFERENCE LEVELS FROM")
• Swing point · leg end: where past legs in the same direction ended, counting only legs that had already reached the current length.
• Last close: the classic form. Every closed bar is treated as an entry at the next bar's open; MFE and MAE over H bars are split by regime and drawn from the last closed price. The detail table then also shows opening gaps, a split by entry bar, and the number of entries (n) with the number of non-overlapping entries (n_eff).
INPUTS AND DEFAULTS
• Holding bars (H) = 10: the window in which each excursion is measured.
• ATR length 14, DMI length 14, ADX smoothing 14, ADX threshold 25: common textbook settings, chosen so that the regime reads the same as a standard ADX/DMI.
• Reversal size = 2 ATR: the zigzag threshold. A smaller value gives more and shorter legs.
• Intraday break = Auto: how a lunch break is detected for the gap rows (a time window on TFEX symbols, a time gap elsewhere).
• Text size, table positions and the show / hide switches only change the display.
All distances are in ATR, so the same defaults can be applied to any symbol and timeframe.
HOW TO USE IT
• Decide direction and timing with your own method first. Then read the levels to see how far similar moves went in the past and where the running leg stands against that history.
• A leg marked at or beyond P75 has already gone further than three quarters of past cases in their first H bars. That describes the leg; it does not say the leg is over.
• Compare rows in the dashboard to see whether a move on a small timeframe is still inside the usual rebound or pullback distance of a larger one.
LIMITATIONS
• A baseline of past swings and bars, not the result of any trading rule. No commission or slippage.
• Neighbouring samples overlap, so they are not independent. Percentiles from few cases are rough: the weekly row often has only a few dozen swings per direction.
• Results depend on the history TradingView loads for the chart, so the same row can differ slightly between chart timeframes.
• Continuous futures symbols are not back-adjusted here.
• The rebound / pullback statistic covers only the first H bars after a leg extreme.
DISCLOSURES
• Pine Script v6. Open-source.
• Repainting: swings, regime and statistics use closed bars only, and a swing appears only after the bar that confirms it has closed. Levels measured from the leg's extreme move when the leg makes a new extreme; this is intended. Higher-timeframe rows use lookahead off.
• Chart type: standard charts only. On Heikin Ashi, Renko and other non-standard charts the table shows a warning and the values are not valid.
• No signals and no alerts. Past distances do not predict future prices. Not investment advice.
• Concept credits: MFE / MAE after John Sweeney; E-ratio after Curtis Faith. The code is original.
DISCLAIMER
This script is published for educational and informational purposes only. It describes how far price moved in the past and does not provide trading signals, financial advice or a recommendation to buy or sell any instrument. Past price behaviour does not guarantee future results. Trading involves risk, including the loss of capital. You alone are responsible for your own decisions.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.