cTrader order execution guide

cTrader ExecuteMarketOrder: Orders, Volume Units, and Indicator Signals

Calling ExecuteMarketOrder in a cTrader indicator triggers a compiler error because indicators cannot place trades. This guide explains how to execute market orders in a cBot, convert lots to volume units, and connect indicator signals to execution.

Direct answer

ExecuteMarketOrder is a method of the Robot class in cAlgo.API and cannot be called directly inside an Indicator. In cTrader, custom indicators only calculate and display chart outputs. To execute market orders from indicator signals, write your logic inside a cBot or call the indicator from a cBot. When executing orders, specify volume in units converted through Symbol.QuantityToVolumeInUnits.

What to know first

  • ExecuteMarketOrder belongs exclusively to the Robot base class. Indicators cannot place orders and will fail with CS0103 or CS1061.
  • Volume in ExecuteMarketOrder is measured in raw base units, not lot sizes. Passing 1.0 places 1 unit rather than 1 lot.
  • Use Symbol.QuantityToVolumeInUnits(lots) to convert lot values into broker-compliant volume units.
  • Always check TradeResult.IsSuccessful before accessing the resulting Position object.
  • Pineify cTrader AI Coding Agent generates complete single-file cBots with volume normalization and compiler verification.

Indicator vs cBot (Robot) capabilities in cTrader

CapabilityIndicator (cAlgo.API.Indicator)cBot (cAlgo.API.Robot)
ExecuteMarketOrder availabilityNot available (causes CS0103 compiler error)Native method with full order parameter support
Primary design roleCalculate data series and draw chart graphicsAutomate order execution and manage trading accounts
Account and position accessRead-only or restricted accessFull access to Positions, PendingOrders, and History
Volume handlingNot applicableRequires raw units via Symbol.QuantityToVolumeInUnits
Main event handlersInitialize() and Calculate(int index)OnStart(), OnTick(), OnBar(), OnStop()
Backtesting supportCannot be backtested directlyFull historical simulation in cTrader Backtesting

Why ExecuteMarketOrder fails inside an Indicator

cTrader enforces a strict architectural boundary between technical analysis and account execution. An Indicator class inherits from cAlgo.API.Indicator and is restricted to mathematical calculations and chart rendering. It has no access to account balance, position management, or order placement methods.

If you attempt to call ExecuteMarketOrder inside an Indicator, the C# compiler produces error CS0103: The name ExecuteMarketOrder does not exist in the current context. To trade an indicator signal, you must move the execution logic into a cBot (inheriting from Robot) or invoke the custom indicator from within a cBot.

  • Indicators only process data through Initialize and Calculate methods
  • Order execution methods exist only on the Robot base class
  • To automate an indicator, create a cBot that references the indicator output

How ExecuteMarketOrder works in a cTrader cBot

ExecuteMarketOrder sends an immediate market order to the broker. The call accepts trade direction, symbol, volume in units, order label, stop loss in pips, and take profit in pips.

The method returns a TradeResult object immediately upon completion or rejection. The caller should inspect TradeResult.IsSuccessful to handle broker rejections gracefully.

C# Calling ExecuteMarketOrder in a cBot
// Basic market order execution in a cBot
TradeResult result = ExecuteMarketOrder(
    TradeType.Buy,
    SymbolName,
    volumeInUnits,
    "MyStrategyLabel",
    20.0, // Stop Loss in pips
    40.0  // Take Profit in pips
);

if (result.IsSuccessful)
{
    Print("Position #{0} opened at {1}", result.Position.Id, result.Position.EntryPrice);
}
else
{
    Print("Order failed with error: {0}", result.Error);
}

Converting lot sizes with Symbol.QuantityToVolumeInUnits

A common bug in cTrader cBots is passing lot quantities directly to ExecuteMarketOrder. In cTrader, order volume represents base units (for example, 100,000 units for 1 standard lot of EURUSD). If you pass 1.0, the broker receives an order for 1 unit, which will be rejected for failing minimum volume limits.

Use Symbol.QuantityToVolumeInUnits to translate lot sizes into units. Then pass the result through Symbol.NormalizeVolumeInUnits to align with broker step sizes.

C# Lot to Volume In Units conversion
[Parameter("Volume (Lots)", DefaultValue = 0.1, MinValue = 0.01, Step = 0.01)]
public double QuantityInLots { get; set; }

private double GetNormalizedVolume()
{
    // Convert lots (e.g. 0.1) to volume in units (e.g. 10,000)
    double rawVolume = Symbol.QuantityToVolumeInUnits(QuantityInLots);

    // Normalize to broker volume step and boundaries
    return Symbol.NormalizeVolumeInUnits(rawVolume, RoundingMode.ToNearest);
}

Connecting Indicator signals to a cBot

To execute trades based on custom indicator conditions, instantiate the indicator inside your cBot using Indicators.GetIndicator. Read the indicator output series during OnBar or OnTick, and call ExecuteMarketOrder when your entry trigger occurs.

Ensure the cBot filters existing positions using Positions.FindAll with a distinct label and symbol name. This prevents the robot from opening duplicate positions or interfering with manual trades.

C# Bridging an Indicator to a cBot
// Inside a cBot class:
private MyCustomIndicator _indicator;

protected override void OnStart()
{
    _indicator = Indicators.GetIndicator<MyCustomIndicator>(14);
}

protected override void OnBar()
{
    double signal = _indicator.Result.Last(1);
    var openPositions = Positions.FindAll("MyCustomSignal", SymbolName);

    if (signal > 0 && openPositions.Length == 0)
    {
        double volume = Symbol.NormalizeVolumeInUnits(
            Symbol.QuantityToVolumeInUnits(0.1)
        );
        ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, "MyCustomSignal", 25, 50);
    }
}

Generating robust cBots with Pineify Coding Agent

Writing complete cBots with volume normalization, trade result handling, and indicator dependencies requires strict adherence to the cTrader Algo contract.

Pineify cTrader AI Coding Agent turns your indicator rules into single-file C# cBots. It incorporates correct ExecuteMarketOrder calls, handles unit conversions automatically, and tests code against cTrader.Automate 1.0.19 compiler diagnostics.

  • Transforms custom indicator formulas into automated cBot logic
  • Adds safe Symbol.QuantityToVolumeInUnits and step normalization
  • Validates TradeResult status and position references
  • Passes syntax and type checks before cTrader installation

Practical checks I use

Never pass raw lot numbers into ExecuteMarketOrder

In cTrader, 1.0 means 1 single unit of currency. Always convert lots to units using Symbol.QuantityToVolumeInUnits to avoid order rejections.

Always inspect TradeResult.IsSuccessful

Market orders can fail due to slippage, closed markets, or insufficient margin. I check IsSuccessful before reading result.Position.

Assign distinct labels to separate strategy positions

I assign a unique string label to every ExecuteMarketOrder call. That lets the cBot manage its own trades without touching manual positions.

Primary sources

Pineify is an information tool, not investment advice. Automated order execution and compiler checks do not guarantee strategy profitability or eliminate market risk. Always test cBots on demo accounts before trading with real capital.

Frequently asked questions

Build reliable cTrader execution robots with AI

Turn your indicator rules into automated cBots with error-free ExecuteMarketOrder calls, volume unit conversion, and compiler diagnostics in Pineify.

Open the cTrader Coding Agent