EA Margin Level Alerts and Kill Switches
Margin level is the number your broker uses to decide when it starts closing your positions for you, and most traders check it only once the account is in trouble. If you run an expert advisor, an EA margin level alert belongs inside the EA, checked on ticks and on a timer, with the authority to act without you.
What does margin level actually measure?
Margin level is your account equity expressed as a percentage of the margin your open positions lock up. It measures how close the broker is to restricting and then force closing your trades, and nothing else, so it is not a measure of how far down you are.
Platforms use two thresholds, not one: a margin call level, where the account is warned and usually blocked from opening anything new, and a lower stop out level, where the server starts closing positions itself, one at a time. Both are set by the broker and both can be changed by it.
The ratio has two moving parts. Equity is your balance plus the floating profit and loss on open positions, and that floating figure already carries the swap and commission accrued on them. Used margin comes from position size, contract size and the requirement the broker applies to that instrument, so the ratio can fall with no move against you at all: raise the requirement before a weekend, or add to a basket, and the denominator grows by itself. A strategy that scales into a loser pushes both sides the wrong way at once, which is why the number can look comfortable and then collapse.
Requirements are broker and instrument specific. Gold and index CFDs are frequently treated differently from major pairs, so the same strategy can sit in a different margin band at two brokers. Our notes on broker selection cover what to compare.
Is a margin call the same as a drawdown breach?
No. A margin call is a broker event triggered by your equity against the margin your open positions require, while a drawdown breach is a rule event triggered by your equity against a starting balance or a peak, enforced by a prop firm or your own risk plan rather than by the platform.
They have different denominators, so they trigger independently. Modest size with wide stops can breach a daily loss rule while the margin level looks healthy, and heavy size can approach a stop out on a loss that is small in rule terms.
If you trade a funded or evaluation account, the rule types worth encoding usually include:
- a daily loss limit, measured on intraday equity at some firms and on closed balance at others
- an overall loss limit, either static from the starting balance or trailing behind the account high
- a reset boundary on the firm's chosen server time zone rather than your local clock
- restrictions on holding through scheduled news or over the weekend
- consistency or minimum trading day requirements
Firms word these differently and revise them, so read the current terms of the firm you are with. No EA can promise a pass; what it can do is stop the account before the rule you agreed to gets broken.
Why should the kill switch live in the EA rather than in my own monitoring?
The kill switch belongs in the EA because the moment it matters is the moment you are least able to act. Accounts empty in seconds during a release, or in a weekend gap priced before the platform opens, and a notification only tells you what already happened.
There is a mechanical reason too. The tick handler fires only on the symbol of the chart the EA sits on, so a basket across instruments is checked only when that one symbol quotes, and a timer event covers the rest. A rule that sends a message and does nothing else is a notification, not a kill switch.
What should an EA kill switch actually do when it fires?
A kill switch has four jobs: stop new exposure, remove existing exposure, tell you it happened, and stay off until you deliberately re-arm it. Anything that does fewer than all four leaves the account free to re-enter the trade that triggered it.
Concretely, the routine should:
- set an internal blocked flag that every entry function checks before it sends anything
- cancel pending orders, which are queued exposure and on most account types do not show in used margin
- close open positions, verifying afterwards rather than trusting the send result
- notify through a channel you genuinely read
- log the trigger reason, the margin level, the equity and the open position list
- persist the blocked state so a restart, a chart reload or a recompile does not silently re-arm it
Persistence is the step most often skipped: if the flag lives only in a variable, reopening the platform hands you a fresh EA with no memory of why it stopped.
What order should the kill switch use to avoid a half-closed basket?
Block new entries first, cancel pendings second, close positions third, then notify and persist. If closing comes first, entry logic can fire on the next tick while the closing loop is still working, and you finish flat on two symbols and freshly long on a third.
Closing a basket is a sequence of separate requests, and each can be requoted, rejected, partially filled, or refused while the terminal is busy. Loop, re-read the live position list, and loop again up to a bounded number of attempts. Verify by reading positions, never by the return code of the send.
If positions remain when the retries run out, keep the blocked flag set and keep retrying on the timer. On a hedging account an offsetting pair is one step, because closing one leg leaves the other naked. On a netting account you close one aggregate position per symbol, so watch for partial fills instead of leftover legs. Decide explicitly, too, whether the switch is strategy level, filtered by magic number, or account level and closing everything on the login.
Should the trigger be margin level or equity?
Use both, on separate thresholds. Margin level is the right trigger for avoiding a broker stop out, because it is the number the broker acts on, and equity is the right trigger for everything else, because your rules and your firm's rules are defined against equity rather than margin usage.
One catch on the margin side: with nothing open, used margin is zero and the platform reports no meaningful margin level, so skip the check when the account is flat rather than treating it as a crisis.
On a sanely sized account the equity floor binds first and the margin check is the backstop. Anchor that floor properly: capture start of day equity at the boundary the firm defines in server time, store a peak equity anchor for trailing rules, write both to disk, and include floating profit and loss.
A softer warning tier is worth having too, set before the hard stop rather than at it. Those warnings are review material for sizing, which is judged over a long run of trades, the point of reading a full track record instead of a week.
How do I test it before it matters?
Trigger it on purpose, on a demo account, with the threshold set so it fires immediately. A kill switch that has never actually fired is an assumption. Work through:
- a forced trigger with several positions open across different symbols
- a terminal restart straight after a trigger, confirming the block survives
- a connection drop mid close, confirming the retry loop finishes the job
- a symbol carrying a broker suffix, confirming the close loop still matches it
- a flat account, confirming the margin level check does not misfire with nothing open
- a manual trade the EA did not open, confirming the account level behaviour you chose
The JPTC EA Hub for MT4 and MT5 runs on your own account at your own broker, with the equity and margin protections sitting in the settings rather than in your attention. Start on demo, set the thresholds where your broker's requirements and your firm's rules actually sit, and make the switch fire once before you rely on it.
Automated forex and gold trading
Runs on your own account at your own broker. We host and set it up, so there is nothing to install and no VPS. No profit share, no monthly fee.
See how it works