거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Result - type-safe error handling for MQL5 without exceptions - MetaTrader 5용 라이브러리

Maksym Yaroslavovych Libovych
Maksym Yaroslavovych Libovych
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.
| Korean English Русский 中文 Español Deutsch 日本語 Português Français Italiano Türkçe
조회수:
16
평가:
(1)
게시됨:
\MQL5\Include\Common\ \MQL5\Include\
MqlError.mqh (8.26 KB) 조회
\MQL5\Scripts\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

목적

이 포함 파일은 MQL5용 '값 또는 오류' 반환 유형을 제공하므로, 함수는 전역 변수인 GetLastError() / ResetLastError() 상태를 통해 처리하는 대신 성공 또는 실패를 명시적으로 보고할 수 있습니다. 전역 변수 방식은 잊어버리기 쉽고, 덮어쓰기 쉬우며, 아웃 매개변수와 "마법 같은" 반환 값을 강제로 사용해야 하는 단점이 있습니다.


기능

함수는 값을 포함하거나 오류를 포함하는 하나의 객체를 반환하며, 호출자는 값을 사용하기 전에 이를 확인해야 합니다.

  • ResultValue<T> 값 유형(숫자, 구조체)용.
  • Result<T> 포인터로 참조되는 객체(클래스)에 대한 동일한 계약입니다.
  • Error 경량 구조체(코드 + 설명); 코드는 EnumToString을 통해 읽기 쉬운 이름으로 매핑됩니다.
  • MQLError GetLastError / ResetLastError / SetUserError를 감싸는 얇은 래퍼입니다.
  • 매크로 — TRY , RETURN_ON_ERROR , PRINT_ON_ERROR , RETURN_SAME_ON_ERROR , RESULT_ON_ERROR 상용구 코드 없이 조기 반환을 전파하기 위한 것입니다.
  • 선택적 콜백 — Then , Match , MapError ( 최상위 또는 정적 함수를 받습니다. MQL5에는 클로저가 없습니다).

액세서: Value (), ValueOr (fallback), CurrentError (), IsError ().

사용법

오류 처리

// 스테이지 함수 (최상위 수준 — MQL5에는 클로저가 없음)
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); }

// 파이프라인: 읽기 -> 유효성 검사 -> 변환 -> (오류 주석 달기) -> 처리
void RunPipeline()
{
   SymbolDouble("EURUSD", SYMBOL_BID)
      .Then(EnsurePositive)
      .Then(ToPips)
      .MapError(Describe)
      .Match(OnOk, OnFail);
}

MetaQuotes Ltd에서 영어로 번역함.
원본 코드: https://www.mql5.com/en/code/74427

Clock (Spread) Clock (Spread)

What this indicator does Clock (Spread).mq5 is a MetaTrader 5 chart indicator that displays a small text label in the corner of the chart showing: Countdown timer until the current candle closes (in HH:MM:SS or MM:SS format, depending on timeframe) Current spread (Ask − Bid, in points), shown in parentheses next to the timer

Mediana Trendline Mediana Trendline

Draws parallel trend channels (Median, High, Low) on the current chart based on the last two closed candles of up to 7 higher timeframes (MN1, W1, D1, H4, H1, M30, M15), with individually configurable colors and line styles for each timeframe.

Pip Value Calculator Pip Value Calculator

실시간 PIP 값, 리스크 기반 로트 크기 설정, 맞춤형 거래량 리스크 분석 및 미결제 포지션 손익 — 이 모든 기능을 하나의 패널에서 확인하세요.

SniperGold SMC ProPlus  (Institutional Smart Money Concepts) SniperGold SMC ProPlus (Institutional Smart Money Concepts)

SMC chart indicator: market structure (BOS/CHoCH), volume weighted order blocks, multi timeframe FVG, equal highs/lows, liquidity sweeps, premium/discount zones, a 3 time frame bias panel and an optional trade setup readout. Closed bar logic only (no repaint). It draws and alerts, it does not place trades.