MehaAI Trading Advisor
- Experts
- Rail Badreev
- Version: 1.0
- Activations: 8
MehaAI Trading Advisor
A smart Expert Advisor for MT5 that combines technical analysis and real-time news through OpenAI. It generates buy / sell / hold signals with SL/TP levels, takes into account risk, broker restrictions, and the current account state, then automatically executes and manages trades.
What it does
-
Scans the market across timeframes M1…MN1, calculates RSI, SMA(50/200), ATR, volatility, volumes, H1 support/resistance levels.
-
Enriches the context with internet sources: news, economy, politics, analysts’ opinions (via OpenAI + web search).
-
Returns JSON with action and SL/TP levels, explaining the reasoning (news + technicals + risk).
-
Trades automatically: opening/managing trades, setting SL/TP, calculating lot size based on MaxRisk.
Key features
-
Direct integration with OpenAI (Responses API) and built-in news web search.
-
Risk management: lot size is calculated from MaxRisk (portion of balance per trade), taking into account StopsLevel/FreezeLevel, lot step and margin.
-
Support for both netting and hedging (multiple positions per symbol): bulk SL/TP placement for all positions of the same symbol.
-
StrictDirection mode (optional): upon buy/sell signal, the EA does not open opposite trades for “netting adjustment” but reduces excess volume on the same side first (reduce-then-add).
-
Accurate net exposure logging: NET BUY/SELL X.XX across N positions.
-
Safe levels: SL/TP are set beyond Stops/Freeze with ATR-based buffer (SafeMinDist function) to avoid broker rejections.
-
Smart order execution: cycling through filling modes (IOC/FOK/RETURN), lowering volume on errors, short back-offs, delayed SL/TP placement (3 seconds) to bypass freeze zones.
-
Transparency: detailed logging and optional daily saving of AI responses.
How it works
-
Market and account data collection: candles M1…MN1, indicators, volatility, levels, balance/margin/positions.
-
Prompt generation with MaxRisk, instrument restrictions (lot step/minimum, Stops/Freeze, margin), and news context.
-
Receiving JSON from the model (action, SL, TP, reason).
-
Execution: lot calculation → opening/adjusting exposure (with StrictDirection) → bulk SL/TP placement.
Pairs and Timeframes
MehaAI works on all major Forex instruments.
The timeframe is not critical, since the advisor analyzes multiple intervals (M1...MN1).
For convenience, you can attach it to H1 or H4.
Backtesting
Due to external WebRequests (OpenAI + news feeds), the standard MT5 backtest does not reflect actual operation.
Instead, the advisor includes a simulation/test mode for the Strategy Tester (with RSI/ATR fallback), which helps imitate behavior.
True efficiency can only be observed on real or demo accounts.
Inputs
-
ApiKey — OpenAI key (via Inputs or Common\Files\ApiKey.txt ).
-
ModelName — OpenAI model (default gpt-5 / gpt-5-mini).
-
UseWebSearchTool — enable internet news.
-
MaxRisk — risk per trade (portion of balance, e.g. 0.02 = 2%).
-
MaxLot — limit on lot size.
-
StrictDirection — reduce-then-add mode (no opposite trades).
-
RequestIntervalMinutes — frequency of AI requests.
-
Candles_M1…MN1 — depth of history per timeframe.
-
UseMockInTester / MockJSON — offline mock for Strategy Tester.
-
SaveResponses / LogActions — save AI responses / detailed logs.
-
OpenAIURL, SaveApiKeyToCommonFile, FailInitIfNoApiKey — service settings.
Graphical Interface
Built-in chart panel:
-
Edit MaxRisk, MaxLot, interval, ModelName, candle depth;
-
Save parameters to memory;
-
Button to load API key;
-
Panel minimization.
Requirements and Installation
-
Obtain an OpenAI API key.
-
Add https://api.openai.com to Tools → Options → Expert Advisors → Allow WebRequest…
-
Enter the key via Inputs or place it in MQL5\Files\Common\ApiKey.txt .
Important: OpenAI limits and tiers for new accounts
-
New OpenAI accounts start at the Free Tier with limited quotas for the GPT-5 model (≈10k tokens per minute).
-
Even if you top up your balance, the account remains in Free Tier until at least $5 is actually spent on requests. After that, the account is automatically upgraded to Usage Tier 1, where higher limits become available and you can use GPT-5 with more candles and news context.
-
At the Free Tier you can use the gpt-5-mini model (including Web Search) until your account is promoted to Tier 1.
Notes
-
Works on both netting and hedging; for hedging, SL/TP are placed on all positions of the same symbol.
-
Due to external WebRequests, results cannot be fully tested in the Strategy Tester — use a demo account first.
-
Trading involves risks — profit is not guaranteed.