# Bring your thinkScript scripts. Keep your work.

> You have spent years on your thinkScript 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/thinkscript/

## A real example.

A real run of the importer (8 lines: 7 exact, 1 adapted, 0 your call).

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

becomes

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

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

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.

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