Code migration guide
cTrader to thinkScript converter
cTrader indicator math may fit a thinkScript study, but a cBot has a much broader C# runtime; trade execution, services, asynchronous work, and position events must be removed or represented only as chart signals.
Generate a thinkScript draft, then save and test it in the thinkorswim editor as the intended study or strategy.
Conversion map
What changes between cTrader and thinkorswim
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 | Robots use lifecycle methods including OnStart, OnTick, OnBar, OnStop, and OnException; indicators calculate by index. | Declarative expressions are evaluated over chart data; studies, strategies, scans, and watchlist columns have different contexts. | Choose when each cTrader calculation should run in thinkorswim; matching syntax alone does not preserve timing. |
| Market data and history | Bars and DataSeries expose typed C# collections, while multi-timeframe data is requested explicitly. | Definitions and plots form time series and access prior values with bracket indexing or recursive definitions. | Recheck bar indexing, warm-up requirements, timeframe requests, and behavior on an unfinished bar. |
| Indicators and chart output | Indicator classes expose output series and use the cTrader Algo indicators API. | Studies use def, plot, painting, and built-in study functions to render chart analysis. | Map calculations before recreating plots, labels, colors, and platform-specific drawing objects. |
| Orders and positions | Robot methods submit and manage trades through Symbol, Positions, PendingOrders, and volume measured in units. | Strategies use AddOrder to add simulated orders to charts; platform conditional orders are a separate workflow. | Define fill timing, sizing, pyramiding or hedging, stops, and position ownership for the target platform. |
| Native validation | Build the C# project in cTrader Algo, resolve build output, attach it to the intended symbol, and run a cTrader backtest. | Paste into thinkScript Editor, save it as the correct study or strategy, add it to a chart, and inspect plots or the strategy report. | Treat generated thinkScript as a draft until it passes the target editor, chart, and backtest workflow. |
Code example
Moving-average cross: cTrader C# to thinkScript
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.
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);def fast = Average(close, 10);
def slow = Average(close, 20);
plot longSignal = fast crosses above slow;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 C# cBot or custom indicator project.
- 2
Choose the target artifact
Decide whether the result is a thinkScript study or strategy definition. This choice controls lifecycle methods and available APIs.
- 3
Rewrite through target APIs
Translate state, series, indicators, drawings, and orders into thinkorswim concepts instead of replacing function names.
- 4
Validate behavior natively
Paste into thinkScript Editor, save it as the correct study or strategy, add it to a chart, and inspect plots or the strategy report.
Manual decisions
Decisions code replacement cannot make
- Select the cTrader calculations that can run as declarative chart series.
- Replace C# objects, collections, and event state with supported thinkScript definitions.
- Convert cBot trades only to simulated AddOrder markers when that comparison is useful.
Limitations
What the draft cannot prove
- cTrader and thinkorswim 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 thinkorswim.
- Pineify can generate and revise a thinkScript draft, but the target platform remains the authority for compilation, loading, backtesting, and runtime behavior.
Use cases
When this conversion is useful
- Move a cTrader indicator into a thinkorswim chart study.
- Visualize cBot signals without porting its execution runtime.
- Adapt supported plots and alerts for thinkorswim users.
FAQ
cTrader C# to thinkScript questions
Official references
- cBot lifecycle
Spotware, checked 2026-08-10
- Introduction to cTrader cBots
Spotware, checked 2026-08-10
- thinkScript reference overview
Charles Schwab, checked 2026-08-10
- Creating thinkScript strategies
Charles Schwab, checked 2026-08-10
Related converters
Browse all convertersBuild the thinkScript draft with its native model in view
Bring the complete source and your artifact, timing, data, and order requirements. Validate the result in thinkorswim.