# Bring your MQL4 and MQL5 scripts. Keep your work.

> You have spent years on your MQL4 and MQL5 scripts. You should not have to start again. Paste one in, and AlgoBarsX rewrites it and tells you what it did to every line.

Source: https://algobarsx.com/convert/mql/

## A real example.

A real run of the importer (11 lines: 6 exact, 6 adapted, 2 your call).

```
#property strict
input int Fast = 20;
input int Slow = 50;
input double Lots = 0.10;
void OnTick()
{
   double f = iMA(NULL, 0, Fast, 0, MODE_EMA, PRICE_CLOSE, 0);
   double s = iMA(NULL, 0, Slow, 0, MODE_EMA, PRICE_CLOSE, 0);
   if (f > s && OrdersTotal() == 0)
      OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - 250 * Point, Ask + 500 * Point);
}
```

becomes

```algobarsx
strategy "Imported expert advisor"
    market: EURUSD
    bars: 1h

input Fast = 20
input Slow = 50
input Lots = 0.1 lots

f = ema(close, Fast)
s = ema(close, Slow)

when f > s and trades.open().len == 0:
    buy size: Lots, stop: close - 250 * market.point_size, target: close + 500 * market.point_size
```

- Exact: `input int Fast = 20 ;` — an input carried over
- Exact: `input int Slow = 50 ;` — an input carried over
- Exact: `input double Lots = 0.10 ;` — an input carried over
- Adapted: `void OnTick ( )` — OnTick became the script body, which runs once per bar; add evaluate: tick to run on every tick
- Exact: `double f = iMA ( NULL , 0 , Fast , 0 , MODE_EMA` — a variable carried over
- Exact: `double s = iMA ( NULL , 0 , Slow , 0 , MODE_EMA` — a variable carried over
- Adapted: `f > s && OrdersTotal ( ) == 0` — OrdersTotal() became the number of open trades
- Your call: `Symbol ( )` — Symbol() has no equivalent yet
- Adapted: `Ask` — Ask became the close: a backtest here has one price per bar, and live trading uses the right side of the spread
- Adapted: `Ask - 250 * Point` — Ask became the close: a backtest here has one price per bar, and live trading uses the right side of the spread
- Adapted: `Ask + 500 * Point` — Ask became the close: a backtest here has one price per bar, and live trading uses the right side of the spread
- Exact: `OrderSend ( Symbol ( ) , OP_BUY , Lots , Ask , 3 ,` — the order carried over with its stop and target
- Adapted: `if ( f > s && OrdersTotal ( ) == 0 ) OrderSend (` — a condition that places orders became a rule
- Your call: `the script header` — an expert advisor runs on whatever chart it is attached to, so EURUSD on 1h was filled in: set the ones you want

## How the ideas translate.

| In MQL4 and MQL5 | In AlgoBarsX |
| --- | --- |
| `input int Fast = 20;` | input Fast = 20 |
| `input double Lots = 0.10;` | input Lots = 0.1 lots |
| `iMA(NULL, 0, Fast, 0, MODE_EMA, PRICE_CLOSE, 0)` | ema(close, Fast) |
| `OrdersTotal() == 0` | trades.open().len == 0 |
| `OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, sl, tp)` | buy size: Lots, stop: …, target: … |
| `Point` | market.point_size |
| `PERIOD_H1, PERIOD_D1` | 1h, 1d |
| `void OnTick()` | the body of the script. Add evaluate: tick to the header if it must run inside the bar. |

Stops written as `Ask - 250 * Point` carry over literally. They read better, and survive gaps better, as distances: `stop: 250 points`.

## How to move a script.

1. **Paste or upload** Open the Terminal, choose Import, and paste your code or pick the file.
2. **Read every note** Each line is marked exact, adapted, or your call. Settle every “your call” before you go on.
3. **Read it back, then test** Check the plain-English description against what your old script did. Then run a test.

## What you gain.

- **It reads itself back** The compiler writes out what the script does in plain English.
- **Units are real** Percent, pips, R and money are types. Mix-ups are caught before anything runs.
- **One script everywhere** The same file draws, tests, alerts and trades.

> **Always read an import before you run it.** No converter is perfect, and some shapes of code import better than others. Other platforms leave things unsaid that AlgoBarsX makes you state, such as the market, the bar size and the trade size. Compare the plain-English description with what your old script did, and test before you deploy.

## Good questions.

**Will every script convert cleanly?** No. Simple, common shapes convert best. An import that does not compile says so, and every changed line carries a note. Always read the result.

**Do I lose my original?** No. Your old script is untouched. Lines that needed a choice keep the original as a comment.

**Is it free?** AlgoBars is $0 a month with no card. Credits pay for AI, tests and auto trades.

## Important

Trading is risky and you can lose money. AlgoBars is software, not a broker or an adviser. Backtests are hypothetical and leave out spread, fees, swaps and slippage. AlgoBarsX is in beta.
