---
title: "Creating Automated Strategies and Trading Tools - Examples - MCP and AI - MetaEditorのヘルプ"
description: "Uncertainty-gated portfolio EA: Online regime-change EA: Order-flow entropy EA: Structurally filtered order-book indicator... - Creating Automated Strategies and Trading Tools - Examples - MCP and AI"
image: "https://www.metatrader5.com/i/logo_metatrader5.png"
url: "https://www.metatrader5.com/ja/metaeditor/help/practical_examples/creating_automated_strategies"
---

[MetaEditorのヘルプ](https://www.metatrader5.com/ja/metaeditor/help) → [MCP and AI](https://www.metatrader5.com/ja/metaeditor/help/mcp_and_ai) → [Examples](https://www.metatrader5.com/ja/metaeditor/help/mcp_and_ai/practical_examples) → Creating Automated Strategies and Trading Tools

# Creating Automated Strategies and Trading Tools Using AI

> 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.

Uncertainty-gated portfolio EA:

Create a H1 EA for EURUSD, GBPUSD, and XAUUSD that forecasts the next return from the latest 300 bars, calibrates conformal intervals on a rolling 120-forecast window, and trades only when the interval implies positive expectancy after spread and commission. Reduce risk as intervals widen, cap correlated exposure, monitor coverage over the latest 30 forecasts.

Online regime-change EA:

Create a XAUUSD H1 EA that estimates online Bayesian change-point probabilities from the latest 250 completed-bars using returns, realized volatility, spread, and tick activity. Trade breakouts in persistent regimes, mean-reversion in stable ranges, and flatten above a configurable break probability. Display the evidence, probability, active model, and regime transitions.

Order-flow entropy EA:

Create a tick-driven EURUSD EA using the latest 2,000 ticks. Encode price direction, inter-arrival time, and tick-volume bursts. Calculate transition entropy over 200-tick windows. Use completed M5 momentum for direction, and trade only when momentum and an expansionary entropy state agree. Include spread limits, an entropy-shock exit, daily-loss protection, and a state panel.

Structurally filtered order-book indicator:

Create a Depth of Market indicator for the current exchange traded symbol. Over the latest 500 book events, distinguish quotes persisting at least 250 ms from fleeting liquidity, then plot raw and filtered imbalance, cancellation intensity, liquidity voids, and confirmed absorption. Use MarketBookAdd and MarketBookGet and show an explicit no-book-data state.

Cross-asset lead-lag network EA:

Create an H1 lead-lag EA for EURUSD, GBPUSD, USDJPY, and XAUUSD using the latest 300 completed-bars and one or two-bar lags. Keep only relationships stable in three consecutive 100-bar windows, trade a laggard when at least two leaders agree, normalize by volatility, cap common-factor exposure, and display the three strongest active links with signal age and cost.

Directional-change event EA:

Create a EURUSD directional-change EA from the latest 5,000 ticks. Use a configurable reversal threshold initialized from M5 ATR, retain the latest 100 confirmed events, and enter only when overshoot asymmetry, event duration, spread, and completed H1 direction agree. Exit on the opposite event or after 12 M5 bars and draw only confirmed events.

London breakout EA:

Create a EURUSD M15 London-breakout EA. Mark the first London hour, enter on a close outside its range with rising ATR with period 14 and tick-volume above its 20-bar average, and skip ranges above the 80th percentile of the previous 20 sessions. Risk 0.5 percent, take half at 1R, trail behind completed M15 swings, and stop after two losses or 2 percent daily drawdown.

Regime-adaptive trend EA:

Create a trend EA using a 20-bar Donchian breakout, ADX with period 14 above 25, the slope of EMA with period 100, and an ATR with period 14 stop. Risk 0.5 percent, add one position only after the first is protected, exit on a 10-bar channel reversal or volatility stop, and display regime, next level, risk, and skipped signal reason.

Asian-session mean-reversion EA:

Create an Asian-session mean-reversion EA for EURUSD and GBPUSD. Enter beyond two session VWAP standard deviations only when current volatility is below its 20 day median. Exit at VWAP or after eight M15 bars. Add a catastrophe stop, news, spread, slippage, daily-loss, and one-position-per-symbol controls.

Multi-symbol relative-strength EA:

Create a currency-strength EA for EURUSD, GBPUSD, USDJPY, USDCHF, AUDUSD, NZDUSD, and USDCAD. Rank currencies from the latest 60 completed H4 and D1 bars, trade only the strongest against the weakest when both rankings agree, rebalance once per H4 bar, cap shared currency exposure, and show the live ranking table.

Pairs-trading EA:

Create a pairs EA for two configurable symbols using the latest 120 H1 bars. Estimate a rolling 60-bar hedge ratio and spread z score, enter beyond an absolute z score of 2, exit below 0.5, and suspend entries when 60-bar correlation or mean-reversion stability fails. Value balance both legs and report legging, margin, and cost risks.

Account-telemetry position sizing:

Replace the fixed lots in this EA with dynamic sizing based on balance, equity, free margin, exposure, and the latest 50 closed trades. Compare fixed-fractional risk with quarter-Kelly. Use fixed-fractional when the sample has fewer than 30 trades or unstable payoff estimates. Enforce broker volume rules, a 0.5 percent trade-risk cap, 3 percent portfolio risk, and a 10 percent drawdown ceiling, logging every sizing decision.

Opening-range visualization indicator:

Create a non-repainting indicator for the Asian, London, and New York opening ranges. Extend each high, low, and midpoint, shade completed sessions, rank range size against the previous 60 sessions, alert once on the first closed-bar breakout, and label whether price held outside or returned within three bars.

Liquidity-sweep and structure indicator:

Create a non-repainting swing-sweep indicator using two completed-bars on each side of a swing. Confirm a sweep only after price closes back through the level and then breaks the latest opposing swing. Draw the sweep, confirmation, invalidation, and 1R, 2R, and 3R targets, and alert once after confirmation.

Multi-timeframe market dashboard:

Create a dashboard for the first 5 Market Watch symbols using the latest 200 bars on M15, H1, H4, and D1. Show trend, RSI, ATR percentile, spread-to-median ratio, swing distance, and data readiness. Support sorting and filtering, and open the selected symbol and timeframe on click.

Market Watch opportunity scanner script:

Create a script that ranks the first 12 Market Watch symbols from their latest 100 H1 bars by trend strength, volatility expansion, distance from the daily extremes, spread to ATR ratio, and session availability. Print the top five, export all 12 to CSV, and mark stale or insufficient data.

Historical trade analyzer script:

Create a script that analyzes the latest 100 closed trades by symbol, magic number, direction, weekday, hour, holding time, and win-loss sequence. Report expectancy, profit factor, drawdown contribution, and available MAE and MFE, then export the trade-level data and a ranked summary to CSV.

Symbol and broker diagnostics script:

Create a diagnostics script for one selected symbol. Report contract, volume, filling, stops, freeze, margin, session, and permission properties. Calculate current spread and percentiles from the latest 500 ticks, and validate one proposed volume, stop distance, and target distance.

Path-signature feature library:

Create PathSignature.mqh for the depth-two signature of completed-bar time, volatility-normalized return, and tick volume. Add SignatureTests.mq5 with six fixed cases: constant path, straight line, reversal, rectangle, duplicate observation, and missing interval. Compile and run it, read the Experts journal, and make at most two correction-and-recompile attempts, then report any remaining failures.

Self-exciting tick-arrival monitor:

Create a non-trading HawkesMonitor indicator with exponential-decay intensities for upward ticks, downward ticks, arrivals under 250 milliseconds, and spread widening. Include five fixed OnInit self-checks for decay, excitation, simultaneous events, long gaps, and bounds. Compile it, attach it to EURUSD M1 with Decay=0.8, inspect four visible buffers, then remove it.

Parsimonious volatility forecaster:

Create RoughVolatility.mqh implementing 20-bar historical volatility, HAR periods 1, 5, and 22, and a five-parameter rough-volatility-inspired forecast. Test constant prices, one jump, alternating returns, insufficient history, and extreme values. Compare one-step error on the latest 100 EURUSD H1 closed-bars and report which model wins without changing an EA.

Anytime-valid evidence monitor:

Add a bounded evidence monitor to EvidenceEA.mq5 that updates after each closed trade against zero expectancy, never reorders trades, and never triggers orders. Test wins, losses, zero, and bounded extremes in EvidenceTests.mq5. Backtest EURUSD H1 for the previous month with at most 30 trades, print the path, and report crossings of 2, 5, and 10.

Regret-aware signal ensemble:

Refactor four existing rules in EnsembleEA.mq5 into fixed modules and add exponential weights updated only after each previous outcome. On EURUSD M15 over five trading days, log the first 20 votes, losses, and weights, then compare the ensemble with equal weighting and each expert. Attach with ObserverMode=true, inspect its current state and journal once, then remove it without waiting for new market events.

## In this section

- Creating Automated Strategies and Trading Tools
- [Deploying Expert Advisors, Indicators, and Scripts](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/deploying_programs)
- [Researching and Analyzing Trading Algorithms](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/researching_algorithms)
- [Refactoring and Converting Existing Algorithms](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/refactoring_converting_algorithms)
- [Building Multi Timeframe Automated Strategies](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/multi_timeframe_strategies)
- [Generating Boilerplate Code and Frameworks](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/generating_boilerplate)
- [Debugging and Auditing Trading Algorithms](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/debugging_auditing_algorithms)
- [Optimizing Algorithms for Performance and Speed](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/optimizing_performance)
- [Using Self-Improvement Loops for Algorithms](https://www.metatrader5.com/ja/metaeditor/help/practical_examples/self_improvement_loops)

```json
{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [ {"@type": "ListItem", "position": 1, "item": {"@id": "https://www.metatrader5.com/ja/metaeditor/help", "name": "MetaEditorのヘルプ"}}, {"@type": "ListItem", "position": 2, "item": {"@id": "https://www.metatrader5.com/ja/metaeditor/help/mcp_and_ai", "name": "MCP and AI"}}, {"@type": "ListItem", "position": 3, "item": {"@id": "https://www.metatrader5.com/ja/metaeditor/help/mcp_and_ai/practical_examples", "name": "Examples"}}, {"@type": "ListItem", "position": 4, "item": {"@id": "https://www.metatrader5.com/ja/metaeditor/help/practical_examples/creating_automated_strategies", "name": "Creating Automated Strategies and Trading Tools"}} ]}
{ "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{ "@type": "Question", "name": "MetaTrader 5: Creating Automated Strategies and Trading Tools", "acceptedAnswer": { "@type": "Answer", "text": "Uncertainty-gated portfolio EA: Online regime-change EA: Order-flow entropy EA: Structurally filtered order-book indicator: Cross-asset lead-lag..." } }] }
```
