How cTrader Initialize() handles + Calculate(int index) become Pine Script v6
In cTrader Automate (cAlgo.API), indicators instantiate built-in series once inside Initialize() (or OnStart() in a cBot) and index bar index chronologically from 0 up to the current bar. Every row below is generated at build time by pineForCtrader().
| cTrader Automate C# (cAlgo.API) | Pine Script v6 |
|---|---|
_ema = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 21); | float h_ema = ta.ema(close, 21) |
_sma = Indicators.SimpleMovingAverage(Bars.MedianPrices, 50); | float h_sma = ta.sma(hl2, 50) |
_rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 14); | float h_rsi = ta.rsi(close, 14) |
_atr = Indicators.AverageTrueRange(14, MovingAverageType.WilderSmoothing); | float h_atr = ta.atr(14) |
_bb = Indicators.BollingerBands(Bars.ClosePrices, 20, 2.0, MovingAverageType.Simple); | [h_bb_mid, h_bb_top, h_bb_bot] = ta.bb(close, 20, 2.0) |
_macd = Indicators.MacdCrossOver(Bars.ClosePrices, 26, 12, 9); | [h_macd_macd, h_macd_signal, h_macd_hist] = ta.macd(close, 12, 26, 9) |
_stoch = Indicators.StochasticOscillator(14, 3, 3, MovingAverageType.Simple); | float h_stoch_k = ta.sma(ta.stoch(close, high, low, 14), 3)
float h_stoch_d = ta.sma(h_stoch_k, 3) |
_dms = Indicators.DirectionalMovementSystem(14); | [h_dms_diPlus, h_dms_diMinus, h_dms_adx] = ta.dmi(14, 14) |
Bars.ClosePrices[index - 1]; | close[1] |
Functions.HasCrossedAbove(_fast, _slow, 0); | ta.crossover(_fast, _slow) |
Why cTrader MacdCrossOver(26, 12, 9) and Bars.ClosePrices[index - 1] need care
Two silent traps trip manual ports between cTrader C# and TradingView Pine Script v6: first, Indicators.MacdCrossOver(source, longCycle, shortCycle, signalPeriods) takes the slow period before the fast period, whereas Pine's ta.macd(source, fastlen, slowlen, siglen) takes fast first—the converter swaps them automatically. Second, cTrader indexes oldest-to-newest ([index] is the current bar and [index - 1] or .Last(1) is one bar ago), which maps to Pine's close and close[1].
cTrader [Parameter], [Output] attributes and cBot orders
C# property attributes become TradingView settings and plot() calls; ExecuteMarketOrder() and ClosePosition() map to strategy.entry(), strategy.exit() and strategy.close_all().
| cTrader Automate C# (cAlgo.API) | Pine Script v6 |
|---|---|
[Parameter("Fast EMA", DefaultValue = 21, MinValue = 2)]
public int FastLen { get; set; } | FastLen = input.int(21, "Fast EMA", minval = 2) |
[Output("Basis", LineColor = "DodgerBlue", PlotType = PlotType.Line, Thickness = 2)]
public IndicatorDataSeries Basis { get; set; } | plot(Basis, "Basis", color = color.blue, linewidth = 2) |
ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000, "TrendBot", 25, 50); | strategy.entry("TrendBot", strategy.long)
strategy.exit("Exit " + "TrendBot", "TrendBot", loss = 25 * 10, profit = 50 * 10) |
ClosePosition(position); | strategy.close_all() |
Source-enabled .algo packages vs compiled .NET binaries
Drop a .cs, .algo or .zip file above—everything stays inside your browser.
When can a cTrader .algo file convert to Pine Script?
- .algo built with "Include source code": cTrader packages the indicator or cBot as a ZIP archive containing the editable
.csfile alongside the compiled assembly. Our browser unpacker extracts the.cssource locally without uploading your file. - Closed-source .algo or .dll binaries: When an author builds without source code, the
.algoarchive holds only compiled.NETIL binaries. Those cannot be read as source code and are never decompiled here. - Pending orders, Chart.Draw* objects & OnTick() execution: cBot methods like
PlaceLimitOrder(),ModifyPosition()andChart.DrawTrendLine()are markedTODO(cTrader)with their exact C# line numbers. If you also track cTrader exports, see our cTrader trading journal & statement guide. - Converting from another platform? Try our MQL5 (.mq5) to Pine v6 converter, MQL4 (.mq4) to Pine v6 converter, NinjaScript (NT8 C#) to Pine v6 converter, or thinkScript to Pine v6 converter.