Code migration guide
thinkScript to cTrader converter
A thinkScript study or strategy needs a new cTrader C# artifact, explicit lifecycle and state, typed Bars access, and optional cBot order management; declarative plots and simulated orders are only the behavioral specification.
Generate a cTrader C# draft, then build it in cTrader Algo and test it with the intended symbol and account settings.
Conversion map
What changes between thinkorswim and cTrader
The migration is a model translation. Use this map to decide where the source behavior belongs before writing target syntax.
| Concern | Source model | Target model | Migration decision |
|---|---|---|---|
| Lifecycle | Declarative expressions are evaluated over chart data; studies, strategies, scans, and watchlist columns have different contexts. | Robots use lifecycle methods including OnStart, OnTick, OnBar, OnStop, and OnException; indicators calculate by index. | Choose when each thinkorswim calculation should run in cTrader; matching syntax alone does not preserve timing. |
| Market data and history | Definitions and plots form time series and access prior values with bracket indexing or recursive definitions. | Bars and DataSeries expose typed C# collections, while multi-timeframe data is requested explicitly. | Recheck bar indexing, warm-up requirements, timeframe requests, and behavior on an unfinished bar. |
| Indicators and chart output | Studies use def, plot, painting, and built-in study functions to render chart analysis. | Indicator classes expose output series and use the cTrader Algo indicators API. | Map calculations before recreating plots, labels, colors, and platform-specific drawing objects. |
| Orders and positions | Strategies use AddOrder to add simulated orders to charts; platform conditional orders are a separate workflow. | Robot methods submit and manage trades through Symbol, Positions, PendingOrders, and volume measured in units. | Define fill timing, sizing, pyramiding or hedging, stops, and position ownership for the target platform. |
| Native validation | Paste into thinkScript Editor, save it as the correct study or strategy, add it to a chart, and inspect plots or the strategy report. | Build the C# project in cTrader Algo, resolve build output, attach it to the intended symbol, and run a cTrader backtest. | Treat generated cTrader C# as a draft until it passes the target editor, chart, and backtest workflow. |
Code example
Moving-average cross: thinkScript to cTrader C#
These fragments show where the same signal starts in each API. They are not complete standalone programs; lifecycle setup, inputs, plots, and order handling still depend on the selected artifact.
def fast = Average(close, 10);
def slow = Average(close, 20);
plot longSignal = fast crosses above slow;var fast = Indicators.SimpleMovingAverage(Bars.ClosePrices, 10);
var slow = Indicators.SimpleMovingAverage(Bars.ClosePrices, 20);
bool longSignal = fast.Result.Last(2) <= slow.Result.Last(2)
&& fast.Result.Last(1) > slow.Result.Last(1);Workflow
A four-step migration path
Keep generation, target-platform validation, and behavior comparison as separate stages.
- 1
Inventory the source behavior
Separate calculations, plots, alerts, orders, external dependencies, and assumptions in a thinkScript study or strategy definition.
- 2
Choose the target artifact
Decide whether the result is a C# cBot or custom indicator project. This choice controls lifecycle methods and available APIs.
- 3
Rewrite through target APIs
Translate state, series, indicators, drawings, and orders into cTrader concepts instead of replacing function names.
- 4
Validate behavior natively
Build the C# project in cTrader Algo, resolve build output, attach it to the intended symbol, and run a cTrader backtest.
Manual decisions
Decisions code replacement cannot make
- Choose a cTrader custom indicator or cBot and create the correct class lifecycle.
- Translate recursive chart series into C# DataSeries or explicit state with warm-up handling.
- Design cBot volume, labels, stops, and error handling independently from thinkScript AddOrder markers.
Limitations
What the draft cannot prove
- thinkorswim and cTrader do not share one execution, data, or order model, so behavior can change even when both versions compile.
- Broker, symbol, session, timezone, history, and fill settings can change signals and backtest results on cTrader.
- Pineify can generate and revise a cTrader C# draft, but the target platform remains the authority for compilation, loading, backtesting, and runtime behavior.
Use cases
When this conversion is useful
- Port a thinkorswim study to a cTrader indicator.
- Rebuild thinkScript signals as a cBot with explicit risk controls.
- Move chart formulas into typed C# for native cTrader testing.
FAQ
thinkScript to cTrader C# questions
Official references
- thinkScript reference overview
Charles Schwab, checked 2026-08-10
- Creating thinkScript strategies
Charles Schwab, checked 2026-08-10
- cBot lifecycle
Spotware, checked 2026-08-10
- Introduction to cTrader cBots
Spotware, checked 2026-08-10
Related converters
Browse all convertersBuild the cTrader C# draft with its native model in view
Bring the complete source and your artifact, timing, data, and order requirements. Validate the result in cTrader.