Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Librerie

Result - type-safe error handling for MQL5 without exceptions - libreria per MetaTrader 5

Maksym Yaroslavovych Libovych
Maksym Yaroslavovych Libovych
  • Algorithmic Trading Developer | MQL5, .NET, NinjaTrader al  Self-employed
  • Ucraina
  • 116
MQL5 Developer — Expert Advisors & Custom Indicators | NinjaTrader, QuantConnect
• I build and maintain algorithmic trading systems in MQL5 — Expert Advisors, custom indicators, and strategy backtesting/optimization.
Visualizzazioni:
127
Valutazioni:
(1)
Pubblicato:
\MQL5\Include\Common\ \MQL5\Include\ \MQL5\Scripts\
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

Purpose

This include file provides a value-or-error return type for MQL5, so functions can report success or failure explicitly instead of through the global GetLastError() / ResetLastError() state — which is easy to forget, easy to overwrite, and forces out-parameters and "magic" return values.


What it does

 A function returns one object that either holds a value or an Error; the caller must check before using the value.

  • ResultValue<T>  — for value types (numbers, structs).
  • Result<T>  — the same contract for objects held by pointer (classes).
  • Error  — a lightweight struct (code + description); codes map to readable names via EnumToString.
  • MQLError  — a thin wrapper over GetLastError / ResetLastError / SetUserError.
  • Macros —  TRY ,  RETURN_ON_ERROR ,  PRINT_ON_ERROR ,  RETURN_SAME_ON_ERROR ,  RESULT_ON_ERROR  — for early-return propagation without boilerplate.
  • Optional callbacks —  Then ,  Match ,  MapError  (they take top-level or static functions; MQL5 has no closures).

Accessors:  Value() ,  ValueOr(fallback) ,  CurrentError() ,  IsError() .

Usage

Error Handling

// Stage functions (top-level — MQL5 has no closures)
ResultValue<double> EnsurePositive(const double &value)
{
   if (value <= 0.0)
   {
      return ResultValue<double>::Fail("price must be positive");
   }
   return ResultValue<double>::Ok(value);
}

ResultValue<double> ToPips(const double &price)
{
   return ResultValue<double>::Ok(price / _Point);
}

Error Describe(const Error &error)
{
   return Error::Create(error.code, "pipeline failed: " + error.description);
}

void OnOk(const double &value)  { PrintFormat("[pipeline] result = %.1f pips", value); }
void OnFail(const Error &error) { PrintFormat("[pipeline] %s", error.description); }

// The pipeline: read -> validate -> transform -> (annotate error) -> handle
void RunPipeline()
{
   SymbolDouble("EURUSD", SYMBOL_BID)
      .Then(EnsurePositive)
      .Then(ToPips)
      .MapError(Describe)
      .Match(OnOk, OnFail);
}
Pip Value Calculator Pip Value Calculator

Live pip value, risk-based lot sizing, custom volume risk analysis & open position P/L — all in one panel.

ATR Ranked Support and Resistance Zones ATR Ranked Support and Resistance Zones

An educational MT5 indicator that builds support and resistance as price zones from confirmed pivots. Nearby reactions are merged using ATR-based distance, then ranked by repeated tests, rejection strength and recency. Only the strongest zones are displayed to keep the chart readable.

Equity Guard — Daily Loss Limit Guardian with Panic Panel Equity Guard — Daily Loss Limit Guardian with Panic Panel

Account-level daily loss guardian: when your daily loss reaches a configurable trigger, it closes all positions and pending orders and keeps the account flat until the next daily reset. Limits in percent or money, configurable reset time (server time), draggable visual panel with live gauge, and manual CLOSE ALL / LOCK buttons with click-to-confirm. Works on any broker, symbol, account size and currency — hedging and netting, no DLLs.

MACD Signals MACD Signals

Indicator edition for new platform.