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

CustomStopOut: your own margin call and stop-out levels, worst order closed first - MetaTrader 4용 스크립트

George Ciprian Mandache
George Ciprian Mandache
Mostly writing code that does stuff...
아직 없거나, 있어도 누군가 다시 만들어야 할 만큼 형편없는 인프라를 오픈 소스로 만듭니다. Docker에서 HTTP로 MetaTrader 5를 다루는 mt5-httpapi와 Linux에서의 MQL 컴파일도 그중 하나입니다. 모두 GitHub에 있습니다: https://github.com/psyb0t
조회수:
176
게시됨:
업데이트됨:
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

CustomStopOut is a script that puts your own margin call and stop-out levels on top of your broker's. Attach it to any chart and it checks the account every half second until you remove it. When the margin level falls below your margin call level, it alerts you. When it falls below your stop-out level, it does what the broker does at its own stop-out, only earlier: it closes the open order with the worst result, reads the margin level again, and closes the next one only if the level is still too low.

A broker's stop-out at 20% or 50% often comes too late and takes the whole account with it. With this script you choose the level, for example 100%, and keep the orders that are still fine.

What it does

  • Margin call alert once per fall: you get one alert when the margin level drops below your margin call level, and another only after it recovered and dropped again.
  • Worst order first: the order closed first is the open buy or sell with the lowest net result, profit plus swap plus commission, the order most brokers use at their own stop-out. After each close the script reads the margin level again, so it closes no more than it needs to.
  • One alert per close, with the ticket, symbol, buy or sell, lots, net result in the account currency, and the margin level before and after.
  • A close the broker refuses (market closed, off quotes) is alerted once with the error code and its meaning, the script moves on to the next worst order, and the refused one is tried again on the next check.
  • Only open buy and sell orders are closed. Pending orders are never touched.
  • No used margin, nothing to do: the script never alerts or closes on an account without open orders.
  • Filters: all symbols or the chart symbol only, any magic number or one.
  • Alerts go to the Alert window, push notifications and a sound, each switched on or off.

Inputs

Input Default Meaning
Margin call level, % 150 Alert below this margin level
Stop-out level, % 100 Close the worst order below this margin level
Check interval, milliseconds 500 Time between checks
Orders to close All symbols All symbols or the chart symbol only
Magic number to close -1 One magic number, or -1 for any
Maximum slippage on a close, points 30 Slippage allowed when closing
Alert window, Push notification, Sound on, off, off Where the alerts go

Checks at start

The script first waits up to 30 seconds for the terminal to connect and load the account, so the broker's levels it compares with are the real ones. It will not start with levels that cannot work, or without a connection, and says why in an alert:

not started reason="stop-out level 100.00% must be below the margin call level 100.00%"
not started reason="stop-out level 50.00% must be above the broker's stop-out level 50.00%, or the broker closes first"
not started reason="no connection to the trade server after 30 seconds"

The broker's levels are read from the account. Some brokers set them as an amount of money instead of a percentage; then there is no fixed margin level to compare with, so the script says so in the Experts tab and works on your percent levels alone.

What it prints

Every alert is also printed to the Experts tab:

started version=1.2 margin_call=150.00% stop_out=100.00% broker_margin_call=100.00% broker_stop_out=40.00% symbols=all magic=any interval_ms=500
margin call margin_level=140.00% call_level=150.00%
closed ticket=123456789 symbol=EURUSD side=buy lots=0.1 net=-44.40 USD margin_level_before=96.10% margin_level_after=118.30%
close refused ticket=123456789 symbol=EURUSD side=buy lots=0.1 err=136 desc="Off quotes"
stopped closed=1

The picture is a real run on a MetaTrader 4 demo account, with both levels set far above the account's margin level so the script had to close a small test order. Its first close was refused with "Off quotes" and the next check closed the order.

The Alert window and the Experts log of a MetaTrader 4 run that closed a test order

Keep the terminal running and connected: the script acts only while it runs. AutoTrading must be on and "Allow live trading" ticked in the script's settings for it to close orders; without them, it still alerts and tells you at start that closes will be refused.

StrictJson: RFC 8259 JSON parser and writer for MQL4 StrictJson: RFC 8259 JSON parser and writer for MQL4

One include file that reads and writes JSON in MQL4. It refuses broken JSON and tells you the line and column of the mistake, keeps numbers exact, reads and writes UTF-8 files, and saves your EA's settings to a file and loads them back.

Trade History Exporter for MT4 - closed trades to CSV with costs, MAE and MFE Trade History Exporter for MT4 - closed trades to CSV with costs, MAE and MFE

Saves your closed MT4 trades to a CSV file for your spreadsheet: one row per trade with points, costs, net result, MAE and MFE. Part closes are joined into one row.

Backtest Data Preflight: check broker bar history before a backtest Backtest Data Preflight: check broker bar history before a backtest

Check the first and last available bars and the gaps between bars for a date range before a backtest in the MetaTrader 4 Strategy Tester.

Hotkeys: keyboard shortcuts for MQL4 experts and indicators, set in the inputs Hotkeys: keyboard shortcuts for MQL4 experts and indicators, set in the inputs

One include file that gives your EA or indicator keyboard shortcuts the user types into the inputs, such as Shift+B. Each press fires one action, Shift+B never fires on a plain B, and a shortcut that cannot work is refused at start with the reason.