Reusable Expert Advisor Functions for Orders, Risk Sizing, and Bar Checks
Summary
This article presents a reusable function library for MQL4 Expert Advisors. Its order-opening functions support stop-loss and take-profit levels specified either as distances from entry or as absolute chart prices. Separate function variants address brokers that accept protective levels with the initial deal and those that require them to be set after opening. The library also includes functions for placing pending orders, though the supplied excerpt does not show their full details.
A time-level parameter can prevent another order with the same magic number until a specified time, including reopening on the same bar; the stored value is designed to survive terminal restarts. A margin-mode parameter selects among lot-sizing methods based on free margin or account balance, including versions that size for a predefined stop-loss loss and options that choose the smaller calculated size. The article warns that dynamic stop distances affect sizing and describes checks for available margin. It also covers array synchronization, new-bar detection, and minimum-history checks. These are implementation techniques, not evidence of trading performance.
Key ideas
- Order functions accept protective levels as either point distances or absolute prices.
- Function variants accommodate brokers that set stop-loss and take-profit levels at different stages.
- A persistent time limit can block repeated entries associated with the same magic number.
- Margin modes provide alternative lot calculations using free margin, balance, and stop-loss risk.
- New-bar and minimum-history checks help control when an Expert Advisor evaluates its logic.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.