# Bring your Python scripts. Keep your work.

> You have spent years on your Python 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/python/

## A real example.

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

```
import pandas_ta as ta

df["fast"] = ta.ema(df["close"], length=20)
df["slow"] = ta.ema(df["close"], length=50)
df["rsi"] = ta.rsi(df["close"], length=14)
df["long"] = (df["fast"] > df["slow"]) & (df["rsi"] < 70)
```

becomes

```algobarsx
indicator "Imported Python script"
    pane: price

fast = ema(close, 20)
slow = ema(close, 50)
rsi_value = rsi(close, 14)
long = fast > slow and rsi_value < 70
```

- Exact: `df["fast"] = ta.ema(df["close"], length=20)` — a calculation carried over
- Exact: `df["slow"] = ta.ema(df["close"], length=50)` — a calculation carried over
- Adapted: `df["rsi"] = ta.rsi(df["close"], length=14)` — rsi is the name of a built-in here, so it became rsi_value
- Exact: `df["rsi"] = ta.rsi(df["close"], length=14)` — a calculation carried over
- Exact: `df["long"] = (df["fast"] > df["slow"]) & (df["rsi"] < 70)` — a calculation carried over

## How the ideas translate.

| In Python | In AlgoBarsX |
| --- | --- |
| `df["fast"] = ta.ema(df["close"], length=20)` | fast = ema(close, 20) |
| `ta.rsi(df["close"], length=14)` | rsi(close, 14) |
| `(a > b) & (c < 70)` | a > b and c < 70 |
| `a column named rsi` | renamed to rsi_value, so it does not hide the function |
| `df["close"].shift(1)` | close[1] |
| `df["high"].rolling(20).max()` | highest(high, 20). Rolling calculations come back as a decision, so you pick the function. |

A data-frame script has no orders in it, so it comes back as an indicator. Add `when` rules to turn it into a strategy.

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