Coming from MQL4 and MQL5
A real import, the ideas side by side, and the names that translate.
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.
#property strictinput 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);}1
strategy "Imported expert advisor"2
market: EURUSD3
bars: 1h4
5
input Fast = 206
input Slow = 507
input Lots = 0.1 lots8
9
f = ema(close, Fast)10
s = ema(close, Slow)11
12
when f > s and trades.open().len == 0:13
buy size: Lots, stop: close - 250 * market.point_size, target: close + 500 * market.point_sizeLine 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 |
mode_ema | ema |
mode_smma | smma |
mode_lwma | wma |
price_close | close |
price_open | open |
price_high | high |
price_low | low |
price_median | hl2 |
price_typical | hlc3 |
price_weighted | ohlc4 |
mathabs | abs |
mathmax | max |
mathmin | min |
mathround | round |
mathfloor | floor |
mathceil | ceil |
mathsqrt | sqrt |
mathlog | log |
mathexp | exp |
mathpow | pow |
mathsign | sign |
_symbol | market.symbol |
symbol | market.symbol |
_point | market.point_size |
point | market.point_size |
bars | 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.