Join our fan page
- Views:
- 67
- Published:
- Updated:
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
ClockDiagnostic.mq5 reads TimeCurrent() and TimeLocal() every few seconds for a fixed observation window and reports the two failure modes of the server clock: it freezes when no tick arrives, and it can step backwards after a symbol switch, a reconnection or a tick from another instrument.
Inputs: InpSeconds = 60 (observation length), InpStep = 2 (interval between readings, seconds).
The script prints both clocks and their initial difference in seconds and hours, a >>> STEP BACK line each time TimeCurrent() goes back, and a summary: readings taken, seconds advanced by each clock, the longest freeze observed and the number of step-backs, followed by a verdict for the window.
Rule it documents: TimeLocal() for timestamps, dates, day changes and expiry; TimeCurrent() for session hours and comparison with market data.
Limit: it measures only the window it runs in. With the market open and ticks arriving, a 60-second run may show no anomaly; run it with the market closed to see the freeze.
Gold Hour Profile - when gold moves, and when the spread eats it
Measures, hour by hour, how far a symbol travels and how much of that the spread takes away. Built for gold, works on any symbol, compares several side by side.
CGoldSymbol - find the broker's gold and size the position correctly on it
Detects the gold symbol whatever the broker calls it, reads the contract specification from the terminal instead of assuming it, and turns a risk in account currency into a lot size that is correct for that broker.
Safe Logger: why your log lines vanish while FileOpen keeps returning success
Four EAs writing to the same file, all with FILE_SHARE_READ|FILE_SHARE_WRITE, FileSeek(SEEK_END), FileWrite, FileClose. Looks correct. Every FileOpen returns success. No error in the log. And the lines vanish. Reason: FILE_SHARE_WRITE lets all four open at the same time. All four call FileSeek(SEEK_END) and get THE SAME offset, because none has written yet. All four write at the same position. Whoever closes last wins. Three lines vanish silently. In my case: 12 events expected, 8 in the file. The fix is to open EXCLUSIVELY (no FILE_SHARE_WRITE) and retry while another EA holds the file. And to shout in the log when the retries run out: a log that fails silently is worse than no log at all, because you trust it. The demo script reproduces both modes. To see the loss, drag it onto four charts at the same time with safe mode off and count the lines in the CSV. On a single chart the defect does not show up - which is why it passes in testing and breaks in production.
Contract Sizer: ladder, floor and a breaker that survives a deposit
Three position-sizing protections that do different things; confusing them is why so many accounts get wiped out: - ladder: one contract per X of balance, always applied as a CAP, even with manual lot sizing; - floor: below the minimum capital it does not trade; a new deposit is needed; - breaker: stops at X% below the peak, at any account size, and does not rearm by itself. What this library solves and almost none does: a deposit is not profit, and a withdrawal is not a loss. The breaker measures the drop against the balance peak. Untreated, a deposit made DURING a drawdown lifts balance and peak together, and the protection stops seeing the drop exactly when it would help. Here deposits and withdrawals shift the peak by the same amount. The peak is persisted to a file: a breaker that forgets the peak on a terminal restart is not a breaker. The demo simulates a deposit at the bottom of a drawdown. Run it with the deposit on and off and compare the "drop" column.