MetaEditor Hilfe → MCP and AI → Examples → Optimizing Algorithms for Performance and Speed

Optimizing Algorithms for Performance and Speed Using AI

Measure first, preserve outputs, and optimize the dominant cost. Faster code is not an improvement if it changes signal timing, numeric behavior, or risk.

Adapt file names, symbols, periods, risk limits, and requirements to your project or preferences. Preserve an unchanged baseline and test the algorithm in a demo environment before live use.
 
You are solely responsible for AI-generated content, AI-assisted actions, trading decisions, trading results, and any resulting losses.

Native matrix and vector backtest acceleration:

Create one experimental version of this EA that replaces repeated indicator calls with equivalent native calculations. Compare baseline, scalar, and matrix-and-vector variants on one month of EURUSD H1 data, repeat each run three times, verify identical warm-up and signals, and report measured throughput without assuming a speedup.

Low-latency OnTick pruning:

Profile this scalping EA over 10,000 identical ticks in three runs. Optimize only measured OnTick costs. Move invariant work, preallocate buffers, inline a genuinely hot small function, replace safe constant division only when equivalent, and place expensive strings or chart logging behind the DEBUG preprocessor condition. Repeat the benchmark and require identical signals, requests, and numeric outputs.

Incremental feature-engine optimization:

On the latest 3,000 ticks, profile this rolling pipeline and convert only its two most expensive full-window statistics to stable incremental updates. Define reset rules for gaps and revisions, bound numeric drift, and compare every output with the original.

Multi-symbol scheduler optimization:

Benchmark this multi-symbol EA on EURUSD, GBPUSD, USDJPY, and XAUUSD over 10 trading days. Replace all-symbol-per-tick scans with a fair new-bar and timer scheduler, prioritize open-position protection, and compare CPU time, maximum signal age, missed decisions, and duplicates.

Memory-layout and buffer-reuse study:

Compare the current array-of-objects layout with contiguous preallocated buffers on 10,000 synthetic feature rows. Repeat each version three times and report peak memory, median and 95th percentile time, bounds safety, and numeric equivalence.

ONNX inference latency budget:

Measure 1,000 identical ONNX calls in three runs, separating feature preparation, tensor copy, inference, decision, and request preparation. Reuse safe buffers and sessions, then report median, 95th, and 99th percentile latency with prediction parity.

Tick-storm degradation test:

Create three load levels, one, two, and four symbols, using 2,000 ticks per-symbol, open-position protection, chart updates, and diagnostics. Measure queueing, late decisions, memory growth, and tail latency. Defer optional work when protection latency exceeds its target.

Tester-search budget optimization:

Using the completed report from this parameter search, create a reduced search of at most 60 passes by removing invalid combinations, using one coarse-to-fine refinement, and caching invariant calculations. Run it over the previous five trading days using Open prices. Retain every new trial and compare the selected stable region with the existing original-grid report on the same validation slice without rerunning the original grid.

Fast-path and slow-path separation:

Split this EA into a tick-critical path and deferred UI, reporting, file, and news work. Benchmark both versions on 3,000 identical ticks, define stale-result and backpressure rules, and require identical trading decisions.

Profile-guided optimization:

Profile one two-week test three times, optimize only the function with the largest measured cost, then repeat the same profile and an output-equivalence check. Report the before-and-after call count and time.

OnTick workload reduction:

Audit OnTick over 3,000 ticks and move only the two largest noncritical tasks to new-bar, timer, transaction, or configuration events. Give every cached value an invalidation rule and verify identical decisions.

History and buffer efficiency:

Reduce CopyRates and CopyBuffer work in a 500-bar replay by requesting only changed ranges and reusing completed-bar data. Detect history revisions and compare call counts, runtime, and outputs before-and-after.

Allocation and object churn:

Over 3,000 ticks, locate the two largest sources of ArrayResize, string, object, or allocation churn. Apply one capacity or lifecycle change at a time and compare allocation count, peak memory, leaks, and outputs.

Logging overhead:

Run the same one-week backtest three times with verbose logging and three times with production logging. Avoid constructing disabled messages, preserve essential errors and audit events, and report median runtime and log size.

Mathematical kernel comparison:

Benchmark the current loop, an incremental version, and a native matrix-and-vector version on the same 10,000 numeric inputs. Include warm-up, run each five times, verify a declared tolerance, and keep the clearest version unless the gain matters.

Tester throughput:

Using one completed optimization report, rank the three largest avoidable costs among logging, initialization, indicator work, file and network access, and grid size. Estimate pass-count and runtime savings. Do not start another optimization.

Latency-sensitive execution path:

Measure 1,000 deterministic tick-to-request-preparation paths without placing orders. Separate feature calculation, decision, validation, and request construction. Remove only the largest local nonessential cost, then report median, 95th, and 99th percentile local time with identical request decisions. If correlated request and result timestamps already exist in the journal, summarize up to 20 end-to-end observations separately without attributing terminal, network, or broker components.