Code migration guide
thinkScript to cTrader migration guide for AddOrder and OnBar
A thinkScript study or strategy is a declarative chart specification, including AddOrder simulated orders. A cTrader port needs a new indicator or cBot, OnStart plus OnBar or OnTick, typed Bars or DataSeries, and optional Positions with volume in units.
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 and resolve build errors. Check an indicator on the intended chart; for a cBot, run a backtest with explicit symbol, timeframe, spread, and volume settings before demo testing. | 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#
The thinkScript study plots a current-series crossover. The cTrader fragment defines the condition using Last(2)/Last(1), completed bars when called from OnBar, but does not plot or submit an order. Match confirmation timing, initialize the indicators, and implement the intended chart output or cBot behavior separately.
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
List def and plot formulas, bracket or recursive series, and any AddOrder calls in the thinkScript study or strategy. Studies, strategies, scans, and watchlist columns are different contexts.
- 2
Choose the target artifact
Choose a cTrader custom indicator or cBot and create its class lifecycle. Robots use OnStart, OnTick, OnBar, OnStop, and OnException. Indicators calculate by index.
- 3
Rewrite through target APIs
Translate recursive chart series into C# DataSeries or explicit state with warm-up handling. Design cBot volume, labels, stops, and error handling on Positions and PendingOrders separately from AddOrder markers. Volume is measured in units.
- 4
Validate behavior natively
Build the C# project in cTrader Algo and resolve build errors. Check an indicator on the intended chart. For a cBot, run a backtest with explicit symbol, timeframe, spread, and volume settings before demo testing.
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
- thinkScript evaluates declarative expressions over chart data and reads prior values with bracket indexing or recursion. A cBot runs OnStart, OnBar, or OnTick, so that series needs DataSeries or explicit state and a warm-up rule.
- AddOrder adds simulated orders to a thinkorswim chart. Platform conditional orders are a separate thinkorswim workflow. A cBot submits trades through Positions and PendingOrders with volume in units.
- Pineify can generate and revise a cTrader C# draft. Building in cTrader Algo, checking the chart, and backtesting a cBot with symbol, timeframe, spread, and volume settings remain the validation steps.
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
- Creating thinkScript strategies
Charles Schwab
- cBot lifecycle
Spotware
- Introduction to cTrader cBots
Spotware
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.