ARV EA Toolkit

  • Kütüphaneler
  • Roman Amirov
    Roman Amirov
    I’ve been trading Forex for over 5 years. During this time, I’ve tested a lot of third‑party EAs and realized a simple thing: if you want something done right, do it yourself! That’s why, instead of endlessly searching for the “perfect” ready‑made solution, I started turning my own trading ideas
  • Sürüm: 1.0
  • Etkinleştirmeler: 5
A dependency-free MQL5 library of independent building blocks for
Expert Advisor developers: risk-based position sizing, stop
construction, spread filter, logging, state persistence and a
retry state machine. No strategy, no profit claims.

---

ARV EA Toolkit is a dependency-free library of independent
modules for MQL5 Expert Advisor developers. Use only what you need;
the modules do not depend on each other except for a tiny shared
defines header. It contains no trading strategy and makes no
performance claims - it is correct plumbing for YOUR own logic.

Why it exists
  Most EA bugs are not in the signal - they are in the plumbing:
  wrong lot math, stops below the broker minimum, stacking positions,
  ignoring spread, lost state on reload, fragile close logic. This
  library gives you tested building blocks for exactly those tasks.

Modules (grouped by area)

  RISK & EXECUTION
    * ARV_RiskSizer.mqh    (CARVRiskSizer)   lot from risk %, money-at-risk.
    * ARV_StopBuilder.mqh  (CARVStopBuilder) build/validate SL/TP, broker min distance.
    * ARV_SpreadFilter.mqh (CARVSpreadFilter) current spread vs limit.
    * ARV_RiskToolkit.mqh  (CARVRiskToolkit) facade over the three above + position guards.
    * ARV_CloseRetry.mqh   (CARVCloseRetry, IARVRetryableOperation) exponential-backoff
                                             retry + escalation for close/order ops.

  DIAGNOSTICS & STATE
    * Logger.mqh           (CARVLogger)      4-level console/CSV logger.
    * ARV_Diagnostic.mqh   (CARVDiagnostic)  typed CSV streams (bar snapshot + events).
    * StateStore.mqh       (CARVStateStore)  key/value persistence over GlobalVariable
                                             + owner heartbeat (single-instance guard).

  MARKET UTILITIES
    * ARV_SymbolUtils.mqh  (CARVSymbolUtils) cached symbol specs + price/volume normalize.
    * ARV_TimeUtils.mqh    (CARVTimeUtils)   sessions (GMT), weekend window, new-bar, cooldown.
    * RegimeGate.mqh       (CARVRegimeGate)  ATR + SMA-drift + sigma/mu + cooldown filter.

  CORE (shared)
    * ARV_Defines.mqh      log levels, result codes, prefixes, heartbeat.

Included examples (MQL5\Experts\ARV\)
  * RiskToolkitDemo.mq5  - risk sizing, ATR stop, spread filter, single-position guard.
  * ARV_MinimalGrid.mq5  - Logger + StateStore + RiskToolkit + TimeUtils (fixed lot, equity stop).
  * ARV_Momentum.mq5     - RegimeGate + TimeUtils + RiskToolkit + CloseRetry + Diagnostic.
  (examples are API usage demos, NOT strategies)

Quick example
  #include <ARV\ARV_RiskToolkit.mqh>

  CARVRiskToolkit risk;
  risk.Init(_Symbol, 30);                       // spread limit, points
  double lot = risk.LotForRisk(_Symbol, 1.0, atr * 2.0);
  double sl, tp;
  risk.BuildStops(_Symbol, +1, ask, atr * 2.0, atr * 4.0, sl, tp);
  if(!CARVRiskToolkit::HasPosition(_Symbol, InpMagic) && risk.SpreadOK())
     trade.Buy(lot, _Symbol, 0.0, sl, tp, "comment");

API reference (public surface; abbreviated signatures, full declarations in headers)

Enumerations:
  enum ENUM_LOG_LEVEL;   // LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
  enum ENUM_ARV_RESULT;  // ARV_OK, ARV_ERR_PARAM, ARV_ERR_INIT, ARV_ERR_IO, ARV_ERR_MARGIN, ARV_ERR_DUPLICATE

Classes:
  CARVLogger; CARVStateStore; CARVRegimeGate;
  CARVSymbolUtils; CARVRiskSizer; CARVStopBuilder; CARVSpreadFilter;
  CARVRiskToolkit; CARVTimeUtils; CARVCloseRetry; CARVDiagnostic;
  IARVRetryableOperation;  struct ARVBarSnapshot;

Key functions:
  // Risk & execution
  static double CARVRiskSizer::ForPercentRisk(string symbol, double equity, double riskPct, double slDistance);
  static double CARVRiskSizer::ForFixedLot(string symbol, double lot);
  static double CARVRiskSizer::LossPerLot(string symbol, double slDistance);
  static double CARVStopBuilder::MinDistance(string symbol);
  static bool   CARVStopBuilder::BuildStops(string symbol, int dir, double entry, double slDistance, double tpDistance, double &sl, double &tp);
  static bool   CARVStopBuilder::BuildATRStop(string symbol, int dir, double entry, double atr, double mult, double &sl);
  static bool   CARVStopBuilder::ValidateStop(string symbol, double entry, double stop, int dir);
  bool          CARVSpreadFilter::IsSpreadOK() const;
  int           CARVSpreadFilter::CurrentSpread() const;
  // Facade + position guards
  void          CARVRiskToolkit::Init(string symbol, int maxSpreadPoints = 0);
  double        CARVRiskToolkit::LotForRisk(string symbol, double riskPct, double slDistance) const;
  double        CARVRiskToolkit::LotFixed(string symbol, double lot) const;
  bool          CARVRiskToolkit::BuildStops(string symbol, int dir, double entry, double slDistance, double tpDistance, double &sl, double &tp) const;
  bool          CARVRiskToolkit::StopsDistanceOk(string symbol, int dir, double entry, double sl, double tp) const;
  static int    CARVRiskToolkit::CountPositions(string symbol, long magic);
  static bool   CARVRiskToolkit::HasPosition(string symbol, long magic);
  // Symbol specs & normalization (singleton)
  static CARVSymbolUtils *CARVSymbolUtils::Instance(string symbol = "");
  double        CARVSymbolUtils::NormalizePrice(double price) const;
  double        CARVSymbolUtils::NormalizeLot(double lot) const;
  bool          CARVSymbolUtils::ValidateLot(double lot) const;
  // Time & sessions (static)
  static datetime CARVTimeUtils::ToGMT(datetime serverTime = 0);
  static int      CARVTimeUtils::GMTHour(datetime serverTime = 0);
  static bool     CARVTimeUtils::IsAsianSession(datetime serverTime = 0);
  static bool     CARVTimeUtils::IsLondonSession(datetime serverTime = 0);
  static bool     CARVTimeUtils::IsNewYorkSession(datetime serverTime = 0);
  static bool     CARVTimeUtils::IsLondonNewYorkOverlap(datetime serverTime = 0);
  static string   CARVTimeUtils::SessionName(datetime serverTime = 0);
  static bool     CARVTimeUtils::IsWeekendWindow(int friCloseHour, int monResumeHour, datetime serverTime = 0);
  static bool     CARVTimeUtils::IsNewBar(string symbol, ENUM_TIMEFRAMES tf, datetime &lastBarTime);
  static bool     CARVTimeUtils::CooldownElapsed(datetime &lastEvent, int seconds);
  static int      CARVTimeUtils::SecondsUntilGMTHour(int gmtHour);
  // Logging
  void CARVLogger::Init(string tag = ARV_LOG_DEFAULT_PREFIX, ENUM_LOG_LEVEL minLevel = LOG_INFO, bool console = true);
  bool CARVLogger::EnableCsv(string fileName, string header = "time,level,tag,message");
  void CARVLogger::Log(ENUM_LOG_LEVEL level, string message, string tag = "");
  void CARVLogger::Error(string message, string tag = "");
  void CARVLogger::Warning(string message, string tag = "");
  void CARVLogger::Info(string message, string tag = "");
  void CARVLogger::Debug(string message, string tag = "");
  void CARVLogger::Shutdown();
  // State persistence + single-instance guard
  void          CARVStateStore::Init(string nameSpace);
  static string CARVStateStore::MakeNamespace(long login, string symbol, long magic);
  void          CARVStateStore::SetDouble(string name, double value);
  double        CARVStateStore::GetDouble(string name, double def = 0.0) const;
  void          CARVStateStore::MarkAlive();
  bool          CARVStateStore::IsAlive(int maxAgeSec = ARV_INSTANCE_HEARTBEAT_SEC) const;
  // Regime gate
  bool   CARVRegimeGate::Init(string symbol, ENUM_TIMEFRAMES tf, int atrPeriod, int maPeriod, int cooldownBars, string tag);
  bool   CARVRegimeGate::IsFavorable(double referenceDistance, double minRatio, double maxRatio, double minSigmaMu, bool requireTrend);
  double CARVRegimeGate::ATR();
  // Retry state machine
  bool CARVCloseRetry::Run(IARVRetryableOperation *op, CARVLogger *log, bool &outEscalated);
  bool CARVCloseRetry::Run(IARVRetryableOperation *op, CARVLogger *log = NULL);
  // Diagnostics (CSV)
  void CARVDiagnostic::Init(string prefix, string symbol = "", bool immediateFlush = true);
  void CARVDiagnostic::Bar(const ARVBarSnapshot &snap);
  void CARVDiagnostic::Event(string type, string key1, double val1, string key2, double val2);

Who it is for
  * MQL5 developers who want reliable risk/plumbing without re-writing it.
  * Sellers/students who want a clean reference implementation.

Requirements / compatibility
  * MetaTrader 5, current MQL5 build. Standard includes only.
  * No DLLs, no network, no third-party libraries.
  * Full source (.mqh) included; examples use <Trade\Trade.mqh> only.

What it is NOT
  * NOT an Expert Advisor and NOT a trading strategy.
  * No signal, no edge, and NO profit promise.
  * Example EA results are illustrative only.

Updates & support
  * Version 1.00. Bug reports and feature requests via product messages.
    Planned: minor helper additions only.

Yazarın diğer ürünleri
RA Mean Reversion Portfolio RA Mean Reversion Portfolio, MetaTrader 5 için çoklu döviz Expert Advisor'ıdır. İki döviz çiftinde istatistiksel olarak aşırı günlük hareketler arar ve bu hareketlerin son ortalamasına geri döneceği varsayımıyla işlem yapar. Her iki çift tek bir grafikten işlenir ve tek bir risk limitiyle tek bir portföy olarak yönetilir. Her işlem bir Stop Loss ile korunur. Strateji türü: D1 üzerinde çoklu döviz portföy ortalamaya dönüş (tasarımı gereği trend karşıtı). Expert Advisor
Filtrele:
Değerlendirme yok
Değerlendirmeye yanıt