This repository has been archived on 2026-01-12. You can view files and clone it, but cannot push or open issues or pull requests.
Files
MeanRevisionEA/AGENTS.md
Kunthawat Greethong d79bf572ef docs: add AGENTS.md
2026-01-03 14:32:17 +07:00

3.6 KiB

MeanRevisionEA - Agent Guide

This repository contains a MetaTrader 5 Expert Advisor (EA) for XAUUSD trading using mean reversion strategies with Open Interest levels.

Build / Lint / Test Commands

MQL5 files are compiled via MetaEditor IDE, not command line. Use MetaEditor (F4 in MT5) → Open OI_MeanReversion_Pro_XAUUSD_A.mq5 → Press F7 to compile.

File Encoding: UTF-16LE with CRLF line endings. MetaEditor handles this automatically.

Testing: Use MetaTrader 5 Strategy Tester. No automated test framework.

Code Style Guidelines

Naming Conventions

Input Parameters: Inp prefix + PascalCase

input double InpLotSize = 0.1;
input bool InpUseStopLoss = true;
input ENUM_OI_SOURCE InpOISource = OI_SOURCE_MANUAL;

Global Variables: PascalCase (no prefix)

double DeltaPrice = 0.0;
double SpotPrice = 0.0;
int DailyTradeCount = 0;

Functions: PascalCase with descriptive names

void InitializeOILevels()
bool CheckGlobalConditions()
double CalculateLotSize(ENUM_POSITION_TYPE tradeType)

Local Variables: camelCase

double lotSize = NormalizeLot(ManualLotSize);
double riskAmount = balance * (InpRiskPercent / 100.0);

Object Names: Descriptive names with prefixes (e.g., "CP_" for control panel)

CreateButton("CP_Sell", x, y, width, height, "Sell Now", clrRed, clrWhite);

Enums and Constants

Enums: ENUM_ prefix, uppercase values

enum ENUM_MARKET_PHASE {
   PHASE_BULLISH,
   PHASE_BEARISH,
   PHASE_SIDEWAYS,
   PHASE_NEUTRAL
};

Imports and Includes

Use angle brackets with backslashes:

#include <Trade\Trade.mqh>
#include <Trade\AccountInfo.mqh>

Function Documentation

Use MetaTrader's standard format:

//+------------------------------------------------------------------+
//| Calculate Lot Size                                               |
//+------------------------------------------------------------------+
double CalculateLotSize(ENUM_POSITION_TYPE tradeType) { }

Error Handling

Check return values and validate inputs:

if(Trade.Buy(lotSize, _Symbol, SpotPrice, sl, tp, "BUY")) {
   Print("BUY executed");
} else {
   Print("BUY failed. Error: ", Trade.ResultRetcodeDescription());
}
if(PendingPriceValue <= 0) {
   Print("Invalid price");
   return;
}

Conditionals and Loops

No space after if/for, space after condition:

if(DeltaDeviation <= threshold)
   return false;
for(int i = PositionsTotal() - 1; i >= 0; i--) { }

Arrays and Strings

Use MQL5 functions for arrays and strings:

ArrayResize(result, count + 1);
ArraySort(CallLevels);
StringToDouble(), StringToInteger(), DoubleToString(value, _Digits)

Color and Object Management

Use MQL5 color constants and check object existence:

color PanelColor = C'30,30,30';
color TextColor = clrWhite;
if(ObjectFind(chart_id, name) < 0)
   ObjectCreate(chart_id, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(chart_id, name, OBJPROP_ZORDER, 1001);

Trade Operations

Normalize values and use CTrade library:

NormalizeDouble(price, _Digits)
NormalizeLot(lotSize)
CTrade Trade;
Trade.SetExpertMagicNumber(InpMagicNumber);
Trade.Buy(lotSize, _Symbol, price, sl, tp, comment);

Event Handlers

Implement required MQL5 handlers:

int OnInit()        // Initialization
void OnDeinit()     // Cleanup
void OnTick()       // Price tick
void OnTimer()      // Timer events
void OnChartEvent() // UI interactions

Comments

Use // for single-line, /* */ for multi-line. Thai comments acceptable for user messages.