# Common jobs, in MQL5 and in Forge

One card a job. Each answer is one line, not a whole file.

## Act once per new bar

**In MQL5:** `if (iTime(_Symbol, _Period, 0) != last_bar_time) { ... }`

```python
Nothing to write: compute() and on_bar see each closed bar once.
```

## One trade per bar

**In MQL5:** `Remember the bar of the last trade and skip until the next.`

```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:** `Filter positions by magic number.`

```python
tag="breakout" on the entry, then ctx.close(tag="breakout").
```

## Skip entries when the spread is wide

**In MQL5:** `if (SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) > max) return;`

```python
filters=[fg.Filter.max_spread(pips=2)]
```

## Trade only in set hours

**In MQL5:** `Compare TimeCurrent() hours with start and end inputs.`

```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.

## Close everything at a total profit or loss

**In MQL5:** `Sum the profit of open positions and close them all past a level.`

```python
basket = fg.Exit.basket(profit_cash=200, loss_cash=100)
```

## A grid with a cap

**In MQL5:** `Place pending orders at fixed steps up to a maximum count.`

```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.

## Round lots to the broker's step

**In MQL5:** `NormalizeDouble(lots / step, 0) * step, then clamp to the minimum and maximum.`

```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.
```
