All Articles
cTrader cBot C# Guide Automated Trading

Complete Guide to cTrader & cBot Development (C#): Automated Trading Made Modern

Brokerlytic TeamApril 10, 2026
Key Takeaways:Master cTrader cBot development with C# β€” build automated trading robots, custom indicators, and advanced order management on one of the most modern trading platforms.

What is cTrader?

cTrader is a professional-grade trading platform known for its clean UI, transparency, and powerful API. Unlike MetaTrader's proprietary MQL, cTrader uses C# (.NET) β€” one of the world's most popular programming languages.

Why Choose cTrader?

  • Modern C# language β€” use a real programming language, not a proprietary one
  • Visual Studio support β€” full IDE with IntelliSense, debugging, NuGet packages
  • True ECN access β€” Level II pricing, no dealing desk
  • Advanced order types β€” market range, stop limit, advanced TP/SL
  • Copy trading built-in β€” native social trading feature
  • Open API β€” REST and FIX API for institutional-grade integration

Chapter 1: Getting Started with cBot Development

Setting Up

  1. Download and install cTrader Desktop from your broker
  2. Open cTrader Automate (click the robot icon or press Alt+A)
  3. Click New cBot β†’ name your project
  4. The built-in code editor opens with a template

Your First cBot: SMA Crossover

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SmaCrossoverBot : Robot
    {
        [Parameter("Fast Period", DefaultValue = 10)]
        public int FastPeriod { get; set; }

        [Parameter("Slow Period", DefaultValue = 30)]
        public int SlowPeriod { get; set; }

        [Parameter("Volume (Units)", DefaultValue = 10000)]
        public double Volume { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 20)]
        public double StopLossPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 40)]
        public double TakeProfitPips { get; set; }

        private MovingAverage _fastMa;
        private MovingAverage _slowMa;

        protected override void OnStart()
        {
            _fastMa = Indicators.SimpleMovingAverage(Bars.ClosePrices, FastPeriod);
            _slowMa = Indicators.SimpleMovingAverage(Bars.ClosePrices, SlowPeriod);
        }

        protected override void OnBar()
        {
            var fastCurrent = _fastMa.Result.Last(1);
            var fastPrevious = _fastMa.Result.Last(2);
            var slowCurrent = _slowMa.Result.Last(1);
            var slowPrevious = _slowMa.Result.Last(2);

            // Bullish crossover
            if (fastPrevious <= slowPrevious && fastCurrent > slowCurrent)
            {
                CloseAllPositions();
                ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume,
                    "SMA Cross", StopLossPips, TakeProfitPips);
            }

            // Bearish crossover
            if (fastPrevious >= slowPrevious && fastCurrent < slowCurrent)
            {
                CloseAllPositions();
                ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume,
                    "SMA Cross", StopLossPips, TakeProfitPips);
            }
        }

        private void CloseAllPositions()
        {
            foreach (var position in Positions.FindAll("SMA Cross", SymbolName))
            {
                ClosePosition(position);
            }
        }
    }
}

Chapter 2: Key Concepts in cTrader API

Position Management

// Open a buy order
var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, 10000,
    "MyBot", 20, 40);

if (result.IsSuccessful)
{
    Print("Order opened at: " + result.Position.EntryPrice);
}

// Modify an existing position
ModifyPosition(position, newStopLoss, newTakeProfit);

// Close a specific position
ClosePosition(position);

// Close partial volume
ClosePosition(position, 5000); // Close 5000 units of 10000

Pending Orders

// Limit order
PlaceLimitOrder(TradeType.Buy, SymbolName, 10000,
    Symbol.Bid - 10 * Symbol.PipSize, "Limit Buy", 20, 40);

// Stop order
PlaceStopOrder(TradeType.Sell, SymbolName, 10000,
    Symbol.Bid - 20 * Symbol.PipSize, "Stop Sell", 15, 30);

// Cancel pending orders
foreach (var order in PendingOrders)
{
    if (order.Label == "MyBot")
        CancelPendingOrder(order);
}

Working with Indicators

// Built-in indicators
var rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 14);
var bb = Indicators.BollingerBands(Bars.ClosePrices, 20, 2, MovingAverageType.Simple);
var macd = Indicators.MacdCrossOver(26, 12, 9);
var atr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);

// Access values
double rsiValue = rsi.Result.LastValue;
double upperBand = bb.Top.LastValue;
double lowerBand = bb.Bottom.LastValue;
double atrValue = atr.Result.LastValue;

Chapter 3: Building Custom Indicators

Bollinger Band Width Indicator

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class BollingerBandWidth : Indicator
    {
        [Parameter("Period", DefaultValue = 20)]
        public int Period { get; set; }

        [Parameter("Std Dev", DefaultValue = 2.0)]
        public double StdDev { get; set; }

        [Output("BB Width", LineColor = "DodgerBlue", PlotType = PlotType.Line)]
        public IndicatorDataSeries BBWidth { get; set; }

        [Output("Average", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries Average { get; set; }

        private BollingerBands _bb;

        protected override void Initialize()
        {
            _bb = Indicators.BollingerBands(Bars.ClosePrices, Period, StdDev, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            double width = (_bb.Top[index] - _bb.Bottom[index]) / _bb.Main[index] * 100;
            BBWidth[index] = width;

            if (index >= 50)
            {
                double sum = 0;
                for (int i = index - 49; i <= index; i++)
                    sum += BBWidth[i];
                Average[index] = sum / 50;
            }
        }
    }
}

Chapter 4: Advanced Risk Management

Dynamic Position Sizing

private double CalculateVolume(double riskPercent, double stopLossPips)
{
    double accountBalance = Account.Balance;
    double riskAmount = accountBalance * riskPercent / 100.0;
    double pipValue = Symbol.PipValue;

    double volume = riskAmount / (stopLossPips * pipValue);

    // Normalize to symbol constraints
    volume = Symbol.NormalizeVolumeInUnits(volume, RoundingMode.Down);
    volume = Math.Max(Symbol.VolumeInUnitsMin, Math.Min(Symbol.VolumeInUnitsMax, volume));

    return volume;
}

Trailing Stop with ATR

private AverageTrueRange _atr;

protected override void OnStart()
{
    _atr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
}

protected override void OnTick()
{
    double atrValue = _atr.Result.LastValue;
    double trailDistance = atrValue * 2;

    foreach (var position in Positions.FindAll("MyBot", SymbolName))
    {
        if (position.TradeType == TradeType.Buy)
        {
            double newSl = Symbol.Bid - trailDistance;
            if (position.StopLoss == null || newSl > position.StopLoss)
                ModifyPosition(position, newSl, position.TakeProfit);
        }
        else
        {
            double newSl = Symbol.Ask + trailDistance;
            if (position.StopLoss == null || newSl < position.StopLoss)
                ModifyPosition(position, newSl, position.TakeProfit);
        }
    }
}

Chapter 5: Backtesting & Deployment

Backtesting in cTrader

  1. Open cTrader Automate
  2. Select your cBot
  3. Click Backtest tab
  4. Configure: Symbol, Timeframe, Date Range, Initial Balance
  5. Click Start and analyze results

Key Metrics to Monitor

  • Net Profit β€” total P&L
  • Profit Factor β€” gross profit / gross loss (aim for > 1.5)
  • Max Drawdown β€” largest peak-to-trough decline
  • Sharpe Ratio β€” risk-adjusted return (aim for > 1.0)
  • Win Rate β€” percentage of winning trades

Going Live Checklist

  1. βœ… Backtest shows consistent results across multiple time periods
  2. βœ… Forward-test on demo account for at least 2 weeks
  3. βœ… Risk management tested with extreme scenarios
  4. βœ… VPS setup for 24/7 operation (if needed)
  5. βœ… Start with minimum lot sizes on live account

cTrader vs MetaTrader: Quick Comparison

FeaturecTraderMetaTrader
LanguageC# (.NET)MQL4/MQL5
IDEVisual Studio compatibleMetaEditor only
Order ExecutionTrue ECNVaries by broker
Copy TradingBuilt-in nativeThird-party plugins
UI QualityModern, sleekDated but functional
Community SizeGrowingMassive
API AccessREST + FIXLimited

Summary

cTrader offers the most modern trading development experience:

  1. Leverage C# skills β€” no proprietary language to learn
  2. Use professional tools β€” Visual Studio, NuGet, debugging
  3. True ECN trading β€” transparent pricing and execution
  4. Built-in copy trading β€” monetize your strategies
  5. Growing ecosystem β€” active community and broker support

Get started today: Download cTrader from your broker and start building your first cBot.

Frequently Asked Questions

What is the main concept of to cTrader & cBot Development (C#): Automated Trading Made Modern?

Master cTrader cBot development with C# β€” build automated trading robots, custom indicators, and advanced order management on one of the most modern trading platforms.

Who should read this guide?

This guide is perfect for both beginners looking to understand the basics and experienced traders wanting to refine their strategies in cTrader.