거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
지표

Return-to-Mean Clock: How Many Bars Does Price Take to Come Back to the Moving Average - MetaTrader 5용 지표

조회수:
152
게시됨:
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Return-to-Mean Clock: How Many Bars Does Price Take to Come Back to the Moving Average

The idea behind it

"Price is stretched, it will come back to the average" is one of the most common ideas in trading, and one of the least measured. How stretched is stretched? How often does the return really happen? And how long does it take, five bars or fifty? Without numbers, a stretch is only a feeling, and a trader who waits for the return of a stretch that never returns pays for it. This indicator measures it on your own symbol, your timeframe and your broker's data.

The definitions are short:

  • Mean. An EMA of the close, InpMaPeriod bars.
  • Distance. The close minus the EMA, divided by the Wilder ATR ( InpAtrPeriod ). It is positive above the average and negative below it, and it is measured in ATR, so it can be compared between symbols and over time.
  • Stretch event. A closed bar at which the absolute distance reaches a level ( InpLevel1 , InpLevel2 , InpLevel3 ) for the first time since the bar before was below it. A bar that jumps over several levels starts an event for each of them. The side is above or below the average.
  • Outcome. From the bar after the event on, the stretch is followed bar by bar until one of three things happens, whichever comes first:
    • return: the close is back at the EMA, or on its other side.
    • further: the close is at least InpExtendAtr ATR beyond the level of the event, measured from the average (a stretch of the 2 ATR level counts as further at 3 ATR with the default of 1).
    • none: neither has happened within InpMaxBars bars.
    Return and further cannot happen at the same bar, because they are decided by the same close.
  • Clock. The number of bars from the event to the return. The panel shows the median (half of the returns took this many bars or fewer) and the 80th percentile.

A stretch can be followed by a return, or by a bigger stretch, and the share of each is exactly what a trader needs to know before betting on the return. The "further" column is the price of being early, the "return" column is the reward, and the median shows how long you wait.

There is no look-ahead. An event enters the table only when its outcome is known, so the panel counts only settled events. Events that are still waiting are not counted. The newest bar, which is still forming, is shown in the histogram but never changes the statistics. The calculation is incremental: the EMA and the ATR are running values, the events that wait for an outcome sit in a short list (at most one per level every other bar, for at most InpMaxBars bars), and the history is never rescanned.

How to interpret it

  • Histogram (indicator window). One bar per chart bar, its height is the distance of the close from the EMA in ATR. Gray bars are inside the first level and white bars are beyond it. Dotted lines mark zero and the three levels on both sides.
  • Data Window.
    • "Distance from EMA (ATR)": the distance of the bar.
    • "Bars in stretch": how many closed bars in a row the close has been beyond the first level on the same side, up to this bar. It is 0 inside the first level, and empty for the forming bar.
  • Panel (top left of the chart).
    • Line 1: symbol, timeframe, the number of closed bars analysed, the settings of the mean, the definition of a return, the distance that counts as further, and the wait.
    • Line 2: the column names.
    • Lines 3-5: one row per stretch level. n is the number of events that have an outcome. return , further and none are their shares, and the three add up to 100%. median and p80 are the bars of the return, counted over the events that returned.
    • Line 6: the stretch that is on now, from the closed bars. It shows the distance, the side, how many bars it has lasted, and the row of the highest level that has been reached, with its return share, its median and its further share.
    • Line 7: one line with symbol, timeframe, bars, the EMA period, the wait and for every level the return share and the median, ready to be copied into a comment.
  • Dashes. A row shows "--" instead of percentages while it has fewer than InpMinCases events. The median and the p80 show "--" while fewer than half of InpMinCases events, but never fewer than 5, have returned.


Fig. 1. The last 100 bars of a simulated H1 series that is pulled back towards a slowly moving mean. The dashed line on the price chart is the EMA(50), added to this mockup (the indicator draws only the distance histogram, so add a standard moving average with the same period to see it on the chart). The histogram shows the distance in ATR with dotted lines at zero and at 1, 2 and 3 ATR. The panel counts all 5,052 closed bars, and the "now" line says that the close has been 2.85 ATR below the EMA for 11 bars. The numbers come from simulated data and say nothing about any real market. Black and white screenshot, per the Code Base image guidelines.

External variables (inputs)

Input Default Purpose
InpMaPeriod 50 EMA period of the mean (5-500).
InpAtrPeriod 14 Wilder ATR period, the unit of the distance (5-200). The first bars of the analysis, twice the longer of the two periods, build the EMA and the ATR and are not used.
InpLevel1 1.0 Stretch level 1 in ATR (0.25-10).
InpLevel2 2.0 Stretch level 2 in ATR. It is raised to be at least 0.25 above level 1.
InpLevel3 3.0 Stretch level 3 in ATR. It is raised to be at least 0.25 above level 2.
InpMaxBars 30 Longest wait for an outcome, in bars (5-100).
InpExtendAtr 1.0 A stretch has run further when the close is this many ATR beyond its level (0.25-5).
InpHistoryBars 50000 Newest bars analysed when the indicator loads or is fully recalculated. 0 analyses all bars. New bars are added as they arrive.
InpMinCases 30 Fewest events before a row shows percentages (5-1000).
InpShowPanel true Show the statistics panel.
InpColorNormal clrGray Histogram color inside the first level.
InpColorStretch clrWhite Histogram color beyond the first level.
InpTextColor clrSilver Panel text color.
InpFontSize 8 Panel font size (Consolas). The line height follows the size.
InpPanelX , InpPanelY 8, 14 Panel offset from the upper left corner of the chart, in pixels.

Recommended use

  • Symbols and timeframes. Any symbol and any timeframe. The numbers describe one symbol on one timeframe with one setting of the mean, so the table of H1 is not the table of M15 and the table of EMA 50 is not the table of EMA 200. Run it on the symbols you trade and compare.
  • Read the three columns together. A return share of 60% sounds good, but if 40% of the stretches ran further first, a trader who fades the stretch is wrong four times in ten and has to survive the further move. Compare the return share with the further share and with the wait, and read the p80 as the "slow" case that you have to be able to sit through.
  • Trends make the numbers worse. A symbol that trends keeps its stretches and returns less often. The table is an average over the whole history, with its trends and its ranges mixed. A "now" line that shows a stretch in the middle of a strong trend is not the same event as a stretch in a range, and the table does not know the difference.
  • The mean moves. The EMA follows the price, so a stretch can end because the average came to the price and not because the price went back. The indicator counts both as a return, because both end the stretch. A slower EMA gives a more stable mean and fewer returns.
  • Events overlap. The distance can dip below a level and cross it again within the wait, which starts a second event while the first is still open. The events are not independent, so the real uncertainty is larger than the number of cases suggests. Look at the column n first, load more history through InpHistoryBars , and be careful with rows of under 100 events. The higher levels are rare.
  • Check both halves of the history. Change InpHistoryBars to see an older and a newer part. A return share that is high in one half and low in the other is not a property of the symbol.
  • Choose the wait with the timeframe. The default of 30 bars is a long wait on H4 and a short one on M1. A longer wait turns "none" events into returns or into further moves, and it also makes the median larger, so compare symbols only with the same inputs.
  • An edge is not a profit. The indicator does not include spread, swap, slippage or the risk of the stretch that runs further. It does not tell you where to enter or where to stop.
  • It describes the past. The table shows what was usual in the loaded history. It does not predict the next stretch.
  • The data is the broker's data. Closes, highs and lows depend on the feed and on its time zone, and holes in the history change the ATR. A different broker can give a slightly different table. A gap over a weekend can put the close far from the average in a single bar and starts events for several levels at once.
  • Performance and memory. Each bar is processed once. Up to 256 events can wait at the same time, the tables have a few hundred numbers, and later ticks only update the forming bar and the panel.
  • Chart objects. The only objects are the panel lines in the main chart window, named with the prefix RM_P . They are removed in OnDeinit() .
  • Account types. The indicator does not trade and does not depend on netting or hedging accounts.
  • Your turn: post your numbers. Attach the indicator to a chart you trade, copy the last line of the panel and post it in the comments with the name of your broker. This is only the format, and its numbers are made up: EURUSD H1 | 50000 bars | EMA 50 | back at the EMA within 30 bars: 1.0 ATR 62% (median 4) | 2.0 ATR 66% (median 7) | 3.0 ATR 71% (median 11) . Which symbols come back to the average quickly, and which ones never seem to? Does the return get more likely or less likely at 3 ATR on your symbol? Post the most surprising line you find.
Prop Firm Risk Manager - daily loss and trailing drawdown guard Prop Firm Risk Manager - daily loss and trailing drawdown guard

Account guard for prop-firm challenges. It does not open trades: it watches the whole account (manual trades and any EA) and closes everything before the firm's limits are broken. - Daily loss limit: closes all and blocks trading until the next day. - Max drawdown: static or trailing (can lock at the start balance); closes all and locks the account. - Optional profit-target lock, max lots / max positions, Friday close. - On-chart panel (equity, today's P/L, daily and drawdown room left) and push alerts. - Equity peak and lock are saved per account, so a restart does not reset the protection. Main inputs: StartBalance, DailyLossUSD, DDMode, MaxDDUSD, LockAtStart, safety buffers, TargetUSD, MaxOpenLots, MaxOpenPositions, FridayCloseOn, ResetLock. Attach to any one chart, any symbol and timeframe, with Algo Trading enabled.

Robustness Lab: Optimisation robustness map with plateau score for the Strategy Tester Robustness Lab: Optimisation robustness map with plateau score for the Strategy Tester

Draws a live heatmap of two optimised inputs while the Strategy Tester optimises your EA, and scores every cell by its neighbourhood: the plateau score is the mean minus k times the standard deviation of the surrounding cells. It shows whether your best parameters sit on a stable plateau or on a single lucky cell, and writes an HTML report, a CSV and a picture of the map. Includes a Monte Carlo drawdown criterion and a small demo EA. Part of the free Robustness Lab set.

Daily loss and max loss guard - prop firm rules in one include Daily loss and max loss guard - prop firm rules in one include

Watches the equity like a prop firm does: daily loss limit and max loss limit, static or trailing, floating profit included. Stops new trades at a warning level, closes everything on a breach and remembers it after a restart.

MACD Signals MACD Signals

Indicator edition for new platform.