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.
cTrader order execution guide
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.
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.
| Capability | Indicator (cAlgo.API.Indicator) | cBot (cAlgo.API.Robot) |
|---|---|---|
| ExecuteMarketOrder availability | Not available (causes CS0103 compiler error) | Native method with full order parameter support |
| Primary design role | Calculate data series and draw chart graphics | Automate order execution and manage trading accounts |
| Account and position access | Read-only or restricted access | Full access to Positions, PendingOrders, and History |
| Volume handling | Not applicable | Requires raw units via Symbol.QuantityToVolumeInUnits |
| Main event handlers | Initialize() and Calculate(int index) | OnStart(), OnTick(), OnBar(), OnStop() |
| Backtesting support | Cannot be backtested directly | Full historical simulation in cTrader Backtesting |
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.
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.
// 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);
}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.
[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);
}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.
// 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);
}
}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.
In cTrader, 1.0 means 1 single unit of currency. Always convert lots to units using Symbol.QuantityToVolumeInUnits to avoid order rejections.
Market orders can fail due to slippage, closed markets, or insufficient margin. I check IsSuccessful before reading result.Position.
I assign a unique string label to every ExecuteMarketOrder call. That lets the cBot manage its own trades without touching manual positions.
Generate and check C# cBots with compiler diagnostics.
Migrate legacy cAlgo data access code to modern Bars collections.
Turn entry, exit, and risk rules into an editable C# robot.
Understand the structure and lifecycle of the cTrader Algo API.
Build custom technical indicators with parameters and chart outputs.
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.
Generate single-file cTrader C# cBots and custom indicators, then review compiler diagnostics in the same coding workflow.
Turn explicit entry, exit, position, and risk rules into editable single-file cTrader C# cBot source.
Distinguish cTrader Algo API, Automate, cAlgo, Open API, and FIX API before writing C# cBots or indicators.
Migrate legacy cAlgo.API.Internals.MarketSeries code to modern Bars properties with C# property mappings and compiler diagnostics.
Create editable cTrader C# custom indicator source for formulas, output series, and chart objects.
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