# Coming from thinkScript

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

Source: https://algobarsx.com/docs/from-thinkscript/

This is a real run of the importer on a small thinkScript script. The result compiles. 8 lines were read: 7 carried over exactly, 1 were adapted and 0 came back as decisions for you.

```algobarsx
input fastLength = 20;
input slowLength = 50;
def fast = ExpAverage(close, fastLength);
def slow = ExpAverage(close, slowLength);
plot FastLine = fast;
plot SlowLine = slow;
AddOrder(OrderType.BUY_TO_OPEN, fast crosses above slow);
AddOrder(OrderType.SELL_TO_CLOSE, fast crosses below slow);
```

```algobarsx
strategy "Imported study"
    market: EURUSD
    bars: 1h

input risk = 1%
input fastLength = 20
input slowLength = 50

fast = ema(close, fastLength)
slow = ema(close, slowLength)

when crosses_above(fast, slow):
    buy risk: risk, stop: atr(14) * 2, target: 2R

when crosses_below(fast, slow):
    close_all side: long

plot fast as FastLine
plot slow as SlowLine
```

## Line by line

| Status | Your line | What happened |
| --- | --- | --- |
| Exact | `input fastLength = 20` | the input fastLength carried over |
| Exact | `input slowLength = 50` | the input slowLength carried over |
| Exact | `def fast = ExpAverage(close, fastLength)` | fast carried over |
| Exact | `def slow = ExpAverage(close, slowLength)` | slow carried over |
| Exact | `plot FastLine = fast` | the plot FastLine carried over |
| Exact | `plot SlowLine = slow` | the plot SlowLine carried over |
| Adapted | `AddOrder(OrderType.BUY_TO_OPEN, fast crosses above slow)` | thinkorswim sizes an order by the chart settings, so this one risks a set share of the balance with an ATR stop: set the size you want |
| Exact | `AddOrder(OrderType.SELL_TO_CLOSE, fast crosses below slow)` | a closing order carried over |

## How the ideas translate

| In thinkScript | In AlgoBarsX |
| --- | --- |
| `input fastLength = 20;` | input fastLength = 20 |
| `def fast = ExpAverage(close, fastLength);` | fast = ema(close, fastLength) |
| `plot FastLine = fast;` | plot fast as FastLine |
| `fast crosses above slow` | crosses_above(fast, slow) |
| `AddOrder(OrderType.BUY_TO_OPEN, cond)` | when cond: with buy under it |
| `AddOrder(OrderType.SELL_TO_CLOSE, cond)` | when cond: with close_all side: long under it |
| `yes, no` | true, false |
| `BarNumber()` | bar.index |

> **Tip.** thinkScript orders carry no stop or size, so the import adds a `risk` input with a stop of two ATRs and a 2R target. Check those three numbers before anything else.

## Names the importer translates for you

| Their name | AlgoBarsX |
| --- | --- |
| `yes` | `true` |
| `no` | `false` |
| `double` | `number` |
| `barnumber` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) |
| `bar_number` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) |
| `getsymbol` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) |

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