Loading…

Repaint And Lookahead Detector

MQL4 price and indicator arrays index 0 as the most recent bar - the CURRENT, still-forming one, not the last completed one. Reading shift 0 inside logic meant to react to a finished bar is a genuinely easy mistake, especially coming from a platform or a habit where index 0 means "the last settled value". The symptom is invisible on a static chart: the number looks perfectly reasonable right now. What it is not, is the number a trader actually saw and could have acted on a moment earlier, because shift 0 keeps changing as the bar continues to form. That silent difference between "what showed on screen in real time" and "what the value settled on after the fact" is what repainting means in practice, and an indicator or EA that reads shift 0 where it should read shift 1 has exactly this bug even though its code compiles and looks correct on a quick read. This tool makes the bug visible with numbers instead of code review. It evaluates one simple, configurable test signal two ways on every tick: once at shift 1, the last closed bar, which by definition never changes again once computed, and once at shift 0, the live bar, which can change many times before it closes. It tracks how often the live reading disagrees with the disciplined shift-1 reading on any given tick, and - the sharper test - it remembers the very last live value seen just before each bar closes and compares that to what the bar's value actually settles on once it becomes shift 1. A mismatch there is direct, logged proof that the value a trader would have watched and traded intrabar was not the value the bar ultimately confirmed. Notes and limitations - This tool demonstrates the shift-0-versus-shift-1 trap using its own simple, built-in signal. It does not inspect a third-party indicator's source code; use the same shift-1-versus-shift-0 comparison technique manually if you want to audit someone else's custom indicator. - A non-zero repaint mismatch rate on a plain SMA cross is expected and not itself alarming - a fast/slow MA cross computed on a still-forming bar legitimately can flip before the bar closes. The number to actually watch is how large the rate is and whether it is a strategy you intend to react to intrabar; the tool reports the fact, the trader supplies the judgement of what it means for a given system. - Never trades. It only reads price and indicator data and reports.

Expert advisor · MT4 · v1.0 · Free

About Repaint And Lookahead Detector

Repaint And Lookahead Detector is a script for MetaTrader 4 based on Moving Average. It can alert you with a pop-up, sound, email or push message. It has 8 settings, such as Test signal, Fast period and Slow period. MQL source code included.

Files in the download: RepaintAndLookaheadDetector.ex4, RepaintAndLookaheadDetector.mq4, RepaintAndLookaheadDetector.txt.

Settings

SettingDefaultWhat it does
Test signalSIGNAL_MA_CROSSWhich built-in test signal to evaluate both ways
Fast period5Fast MA period (SIGNAL_MA_CROSS) or the single MA period (SIGNAL_PRICE_VS_MA)
Slow period20Slow MA period, used only by SIGNAL_MA_CROSS
Ma methodMODE_SMAMoving average method
Applied pricePRICE_CLOSEApplied price
Alert on mismatchfalsePopup alert the moment a closed bar's live vs settled value disagreed
Csv file nameRepaintAndLookaheadDetector.csvRepaint event log, in MQL4\Files
Status log seconds60Seconds between Journal status lines

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Buy/Sell Arrows · Alerts · Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria