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

TradeDiagnostics - include file that explains why an EA cannot open a trade - MetaTrader 5용 라이브러리

Cesar De Los Reyes Sanchez
Cesar De Los Reyes Sanchez
5 (1)
Creyes EA — rule-based tools for MetaTrader 4 and 5.
조회수:
79
평가:
(1)
게시됨:
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

An Expert Advisor that "silently stops trading" is one of the most common questions on the forum. Usually the reason is simple (the Algo Trading button, an investor login, a closed session, a wrong lot step, not enough margin), but the EA only shows an error code, or nothing at all.

TradeDiagnostics report on a demo account

TradeDiagnostics.mqh runs all these checks at once and returns a report with one line per check:

  • OK: nothing wrong;
  • INFO: useful information (spread, stops level, filling modes);
  • WARN: trading is possible, but something may hurt it;
  • BLOCK: a new trade cannot be opened now, with the reason.

Checks

  1. Connection to the trade server.
  2. Algo Trading button of the terminal.
  3. "Allow Algo Trading" of the program itself.
  4. Account: trading allowed (not an investor login), automated trading allowed by the server, pending orders limit.
  5. Symbol: exists, is in Market Watch, trade mode (disabled, close only, long only, short only).
  6. Trading session open at the current server time (from SymbolInfoSessionTrade), with today's sessions.
  7. Age of the last tick, and spread against an optional limit.
  8. Volume: inside min/max and a multiple of the step (the correct value is suggested).
  9. Margin needed for the volume against free margin (OrderCalcMargin).
  10. Stops level, freeze level, execution and filling modes (information an EA often gets wrong).
  11. A final OrderCheck() of a market buy. OrderCheck only asks the terminal; nothing is sent to the server.

Functions

  • TD_Run(symbol, lot, maxSpreadPoints, report[]) runs every check and returns the worst status;
  • TD_Print(report[]) prints the report in the Experts log;
  • TD_ToText(report[]) returns the report as text (for Comment() or a file);
  • TD_Blockers(report[]) returns only the reasons that block trading.

Use in your own EA, for example in OnInit or when a trade request fails:

#include <TradeDiagnostics.mqh>

void CheckBeforeTrading()
  {
   STDCheck report[];
   if(TD_Run(_Symbol, 0.10, 30, report) == TD_BLOCK)
      Print("Cannot trade now: ", TD_Blockers(report));
  }

TradeDiagnosticsDemo.mq5 is a script that shows the report on the chart and in the Experts log. Inputs: symbol (empty = chart symbol), volume (0 = minimum volume) and a spread limit in points (0 = off). Put both files in the same folder (or the .mqh file in MQL5\Include) and compile the script.

The picture shows the real output on a demo account on a Saturday: everything is OK except the trading session, so the report says why no trade can be opened.

Notes

  • The OrderCheck line can be OK while the session is closed: OrderCheck does not look at the session, which is why the session is checked separately.
  • Results depend on your broker and account settings. This is a diagnostic tool only: it does not trade and it is not trading advice.
Spread Monitor Alert Spread Monitor Alert

Spread monitor for Gold (XAUUSD) and any symbol on MT5. Shows the spread now, its average and the highest of the day in a small panel and alerts when the spread opens above your limit or above twice the average. Open source code.

Pivot Points Daily Weekly Monthly Pivot Points Daily Weekly Monthly

Pivot points for Gold (XAUUSD) and any symbol on MT5. Classic or Fibonacci P, R1 to R3 and S1 to S3 from the previous day, week or month, one set per period, with an optional alert when a candle closes across a level. Open source code.

Broker Time Panel - server clock, local zone, measured offset, candle close countdown Broker Time Panel - server clock, local zone, measured offset, candle close countdown

The panel prints the broker's server clock, your local clock with its GMT zone, the offset between the two to the minute, and the countdown to the close of the chart's current candle. The offset is measured from the terminal's own clocks on every pass, so nothing is typed in and no broker zone is assumed. If you set a lead in seconds and enable a channel, it sends one alert per candle while a bid is available, with the seconds left and the bid; its eight objects stay out of the object list and cannot be selected.

ADR Levels: Average Daily Range, range used in percent, projected high and low (no repaint) ADR Levels: Average Daily Range, range used in percent, projected high and low (no repaint)

Average Daily Range from finished days, ADR high / low projected from today's low and high or from the open, range used in percent, a small panel and alerts at 80 / 100 percent. Day from broker or New York time. No repaint.