Coming from MetaTrader 5
What is the same
You already think in indicators and expert advisors. An MQL5 indicator becomes an fg.Indicator, with outputs in place of buffers. An expert advisor becomes an fg.Strategy, whose compute returns signals. The ideas map across, and the file is Python.
What is different
- Arrays run oldest first. Index 0 is the oldest bar and
-1is the latest closed bar. There is no series mode to switch on. - Missing values are NaN, not
EMPTY_VALUE. - Decisions are made on closed bars and filled at the next real price. A strategy does not run on every tick.
- Time is UTC. The broker's clock is available, converted for you.
- The data is arrays.
calculatefills whole arrays instead of looping overrates_total.
The traps page lists the mistakes that cost the most when porting.
Where to start
Read From MQL5 first. Then write your first indicator, which takes about three minutes.
If you already own an MQL5 indicator, the Indicators screen in Oathra can convert it. It turns the file into Python and says what translated exactly, what was approximated and what could not be converted.
MQL5 names, in Forge
- OnInit becomes setup(self, ctx). Refuse bad settings with raise fg.InvalidParams(...).
- OnDeinit becomes on_end(self, ctx, reason)
- OnTick becomes compute(self, d) for signals over whole arrays; on_bar(self, ctx) for logic per bar
- OnTimer becomes @fg.every(...) on a method
- OnTrade becomes on_order_event(self, ctx, event)
13 things in MQL5 have no Forge form. See the list.
A test of the same rules can give different numbers in MetaTrader and in Forge. Why a MetaTrader report and a Forge test differ lists the causes.
MQL4
MQL4 code is not converted. Settings files (.set) from MetaTrader 4 and 5 are read.