Coming from thinkScript
A real import, the ideas side by side, and the names that translate.
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.
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);1
strategy "Imported study"2
market: EURUSD3
bars: 1h4
5
input risk = 1%6
input fastLength = 207
input slowLength = 508
9
fast = ema(close, fastLength)10
slow = ema(close, slowLength)11
12
when crosses_above(fast, slow):13
buy risk: risk, stop: atr(14) * 2, target: 2R14
15
when crosses_below(fast, slow):16
close_all side: long17
18
plot fast as FastLine19
plot slow as SlowLineLine 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 |
bar_number | bar.index |
getsymbol | 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.