# Coming from MQL4 and MQL5

> A real import, the ideas side by side, and the names that translate.

Source: https://algobarsx.com/docs/from-mql4-and-mql5/

This is a real run of the importer on a small MQL4 and MQL5 script. The result compiles. 11 lines were read: 6 carried over exactly, 6 were adapted and 2 came back as decisions for you.

```algobarsx
#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);
}
```

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

## Line by line

| Status | Your line | What happened |
| --- | --- | --- |
| 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. |

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

## Names the importer translates for you

| Their name | AlgoBarsX |
| --- | --- |
| `mode_sma` | [`sma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-sma) |
| `mode_ema` | [`ema`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-ema) |
| `mode_smma` | [`smma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-smma) |
| `mode_lwma` | [`wma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-wma) |
| `price_close` | [`close`](https://algobarsx.com/docs/ref-var-bars/#ref-close) |
| `price_open` | [`open`](https://algobarsx.com/docs/ref-var-bars/#ref-open) |
| `price_high` | [`high`](https://algobarsx.com/docs/ref-var-bars/#ref-high) |
| `price_low` | [`low`](https://algobarsx.com/docs/ref-var-bars/#ref-low) |
| `price_median` | [`hl2`](https://algobarsx.com/docs/ref-var-bars/#ref-hl2) |
| `price_typical` | [`hlc3`](https://algobarsx.com/docs/ref-var-bars/#ref-hlc3) |
| `price_weighted` | [`ohlc4`](https://algobarsx.com/docs/ref-var-bars/#ref-ohlc4) |
| `mathabs` | [`abs`](https://algobarsx.com/docs/ref-fn-math/#ref-abs) |
| `mathmax` | [`max`](https://algobarsx.com/docs/ref-modifiers/#ref-max) |
| `mathmin` | [`min`](https://algobarsx.com/docs/ref-fn-math/#ref-min) |
| `mathround` | [`round`](https://algobarsx.com/docs/ref-fn-math/#ref-round) |
| `mathfloor` | [`floor`](https://algobarsx.com/docs/ref-fn-math/#ref-floor) |
| `mathceil` | [`ceil`](https://algobarsx.com/docs/ref-fn-math/#ref-ceil) |
| `mathsqrt` | [`sqrt`](https://algobarsx.com/docs/ref-fn-math/#ref-sqrt) |
| `mathlog` | [`log`](https://algobarsx.com/docs/ref-cmd-logging/#ref-log) |
| `mathexp` | [`exp`](https://algobarsx.com/docs/ref-fn-math/#ref-exp) |
| `mathpow` | [`pow`](https://algobarsx.com/docs/ref-fn-math/#ref-pow) |
| `mathsign` | [`sign`](https://algobarsx.com/docs/ref-fn-math/#ref-sign) |
| `_symbol` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) |
| `symbol` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) |
| `_point` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) |
| `point` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) |
| `bars` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) |
| `period_m1` | `1m` |
| `period_m5` | `5m` |
| `period_m15` | `15m` |
| `period_m30` | `30m` |
| `period_h1` | `1h` |
| `period_h4` | `4h` |
| `period_d1` | `1d` |
| `period_w1` | `1w` |
| `period_mn1` | `1M` |

> **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy.
