Common jobs, in MQL5 and in Forge
Forge API 1Updated 14 Oct 2026
One card a job. Each answer is one line, not a whole file.
Act once per new bar
In MQL5
text
if (iTime(_Symbol, _Period, 0) != last_bar_time) { ... }In Forge
python
Nothing to write: compute() and on_bar see each closed bar once.One trade per bar
In MQL5
text
Remember the bar of the last trade and skip until the next.In Forge
python
One new trade per bar on each symbol is the default. fg.Filter.max_trades(per="day", n=1) caps a day.Manage only your own trades
In MQL5
text
Filter positions by magic number.In Forge
python
tag="breakout" on the entry, then ctx.close(tag="breakout").Skip entries when the spread is wide
In MQL5
text
if (SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) > max) return;In Forge
python
filters=[fg.Filter.max_spread(pips=2)]Trade only in set hours
In MQL5
text
Compare TimeCurrent() hours with start and end inputs.In Forge
python
filters=[fg.Filter.session("08:00-17:00", tz="Europe/London")]Write the zone the hours are in. Broker server time has no zone name.
fg.FilterClose everything at a total profit or loss
In MQL5
text
Sum the profit of open positions and close them all past a level.In Forge
python
basket = fg.Exit.basket(profit_cash=200, loss_cash=100)A grid with a cap
In MQL5
text
Place pending orders at fixed steps up to a maximum count.In Forge
python
In on_fill, place the next level with ctx.order(fg.Order.limit(...)) while len(ctx.positions()) is below your cap.Forge has no grid declaration in FORGE_API 1, so the grid is written in a hook.
fg.OrderRound lots to the broker's step
In MQL5
text
NormalizeDouble(lots / step, 0) * step, then clamp to the minimum and maximum.In Forge
python
size=fg.Size.risk_pct(1.0) in fg.Signals. Forge rounds down to the lot step and refuses a size below the minimum.