Loading…

Pre Trade Cost Gate

Transaction cost analysis is standard practice at any desk large enough to have one, and almost never done at retail size, where spread, commission and overnight carry are usually treated as background noise rather than added up against the specific edge a trade is meant to have. A trade with a real statistical edge can still be a losing trade after costs, and the only way to know is to add the costs up before, not after. This computes spread cost from the live quote, commission from a value you supply (MQL4 has no API to read a broker's own commission schedule, so this is an honest input rather than a broker read), and projected swap from the symbol's own long/short swap rates over the number of nights you expect to hold, netting a credit against a cost where the carry happens to be favourable. All money figures are built from the symbol's own tick value and tick size, never a hardcoded contract size, so the comparison is correct on FX, metals and indices alike. The word "gate" is doing some work here that MQL4 cannot actually do: there is no mechanism in the language for one program to intercept another's OrderSend call, including a call made by hand or by a different EA on the same account. This is a calculator you check before clicking your own trade, or a formula another EA's own entry logic could replicate before it calls its own OrderSend - not something that can reach out and stop a trade already in flight. Say so plainly, because implying otherwise is exactly the kind of overselling this catalogue avoids. Notes and limitations - Advisory only. It never sends, modifies or closes a trade, and it cannot intercept an order placed by another program or by hand - MQL4 has no such hook. - Swap figures from MarketInfo() are treated as points per lot per night, the common broker convention. A broker that quotes swap directly in money instead makes this projection approximate rather than exact - this is disclosed rather than silently assumed away. - The commission figure is only as accurate as what you type in; the tool has no way to verify it against the broker's real schedule. - Spread cost is computed from the spread at the moment the button is clicked and will differ from the spread actually paid if conditions change before a real order is sent.

Expert advisor · MT4 · v1.0 · Free

About Pre Trade Cost Gate

Pre Trade Cost Gate is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Proposed lots, Expected edge pips and Commission per lot round turn. MQL source code included.

Files in the download: PreTradeCostGate.ex4, PreTradeCostGate.mq4, PreTradeCostGate.txt.

Settings

SettingDefaultWhat it does
Proposed lots0.10Lot size the cost estimate is computed for
Expected edge pips5.0Your own estimate of the trade's edge, in pips
Commission per lot round turn0.0Broker commission per lot, round turn, in account currency (MQL4 cannot read this - enter it yoursel
Projected hold days1Nights the position is expected to be held, for the swap projection
Min net edge pips0.0Required buffer above breakeven, in pips, to count as a pass

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria