Quick Answer
A cBot can build without errors, run without crashing, and still place no trades. In cTrader, a trade call such as ExecuteMarketOrder does not throw an exception when the server refuses it. It returns a TradeResult, and that object tells you if the call worked (IsSuccessful) and, if not, why (Error). If your code ignores the result, a refused order looks like "the cBot did nothing".
According to the cTrader reference, the ErrorCode enum has eleven values: TechnicalError, BadVolume, NoMoney, MarketClosed, Disconnected, EntityNotFound, Timeout, UnknownSymbol, InvalidStopLossTakeProfit, InvalidRequest and NoTradingPermission. Each one points to a different fix, and only some of them are worth a retry. The sections below show how to read the result, what each code usually means, and a cBot that prints the advice for every code without trading.
From the author: I build cBots in cTrader Automate and convert strategies from Pine Script and MQL5 to C#. In MQL5, the same job is done by trade return codes, and the habit is the same: check the answer of every request. In a converted cBot, the order call is often copied without the check, and then a failed order leaves no trace.
Key Facts
| Error value | What it means | Retry? | Usual fix |
|---|---|---|---|
| BadVolume | The volume is not valid | No | Round to the symbol's volume step and limits |
| NoMoney | Not enough money in the account | No | Reduce the volume, check the margin |
| MarketClosed | The market is closed | Later | Wait for the session |
| InvalidStopLossTakeProfit | The stop loss or take profit is not valid | No | Check the distance and the side |
| InvalidRequest | The request is invalid | No | Check the arguments of the call |
| UnknownSymbol | The symbol is unknown | No | Check the symbol name |
| NoTradingPermission | Trading API used without permission | No | Check the cBot access rights and the account |
| EntityNotFound | The position does not exist | No | The position is already closed: refresh your lookup |
| Disconnected | The server is disconnected | Later | Wait for the connection |
| Timeout | The operation timed out | Check first | Look at the positions before you send again |
| TechnicalError | A generic technical error | Maybe | Log the details, retry a few times with a wait |
The descriptions are from the cTrader reference. The "Retry?" and "Usual fix" columns are practical advice, not part of the reference.
How to Read the Result
Every order call returns a TradeResult. Check IsSuccessful first:
var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, "MyBot");
if (!result.IsSuccessful)
{
Print("Order failed: {0}", result.Error);
return;
}
Print("Opened position {0}", result.Position.Id);
When the order failed, the Position of the result can be empty. Using it without the check is a null error (see the NullReferenceException guide). The same applies to modify, close and pending order calls: they return a TradeResult too, and each deserves the same check. A check at the call is easy to follow in the log, because it shows which call failed.
Reading Each Code
BadVolume
The volume does not fit the symbol: below the minimum, above the maximum, or not a multiple of the step. In cTrader the volume is in units, not lots, so a number that looks right in lots can be wrong in units. Normalize the volume with the symbol's rules (the entry post shows a risk-based volume), and print the volume next to the error. A cBot that works in a backtest and gets BadVolume on a live account usually uses a different symbol rule or a different account size.
NoMoney
The account does not have enough free margin for this volume. Calculate the volume from the free margin or from a risk rule, and keep a buffer. A volume that looks small can still be too large for the leverage of the symbol. The MQL5 side of the same problem is in not enough money, 10019.
MarketClosed
The symbol is not tradeable at this moment: a weekend, a session break or a holiday. The cBot should check the time or simply handle the error and wait. Do not retry in a loop. The MQL5 guide on market closed, 10018 explains the sessions in more detail, and the idea is the same.
InvalidStopLossTakeProfit
The stop loss or take profit is on the wrong side of the price, too close to it, or not a valid number. Pips and prices are easy to mix up: a stop given in pips is a distance, a stop given as a price is a level. Check which one your call expects, as in Pine Script strategy.exit to cTrader C#. The matching MQL5 error is invalid stops, 10016.
InvalidRequest, UnknownSymbol, NoTradingPermission
These point to the call itself: an argument that does not make sense, a symbol name that does not exist on this account (a different broker names it differently), or a cBot that does not have the rights it needs (AccessRights) or an account that cannot trade. Print the arguments and the symbol name, and check the settings of the cBot instance.
EntityNotFound
The position or order you tried to change does not exist any more, for example because the stop loss closed it a moment ago. Look the position up again before you modify or close it, and treat the case as normal.
Disconnected and Timeout
The connection to the server is down, or the server did not answer in time. After a timeout, do not assume that the order failed: it may have been executed. Look at the open positions first, and send again only if the position is not there. After a disconnect, wait for the connection and then re-evaluate the signal instead of replaying an old one.
TechnicalError
A generic error. The community forum has several threads with this error on market orders. The cause in each case depends on the broker and the situation, and the reference does not list a cause. Log the symbol, the volume, the stops and the time, retry a small number of times with a wait, and contact the broker with the log if it keeps happening.
A Failure Handler
One method that every order call goes through keeps the rules in one place:
private bool CheckResult(TradeResult result, string what)
{
if (result.IsSuccessful)
return true;
switch (result.Error)
{
case ErrorCode.MarketClosed:
case ErrorCode.Disconnected:
Print("{0}: {1}. Waiting, will check again on the next bar.", what, result.Error);
break;
case ErrorCode.BadVolume:
case ErrorCode.NoMoney:
case ErrorCode.InvalidStopLossTakeProfit:
case ErrorCode.InvalidRequest:
Print("{0}: {1}. The request must change, not be repeated.", what, result.Error);
break;
default:
Print("{0}: {1}.", what, result.Error);
break;
}
return false;
}
Use it like this: if (!CheckResult(ExecuteMarketOrder(...), "Buy")) return;. The switch on a nullable enum may need a small change in your version (the type of Error), so check the signature in the code completion.
A Full cBot That Prints the Advice
This cBot does not place trades. It prints a short advice for every ErrorCode value, so you can read the table next to your own log. It needs using System; for Enum:
using System;
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ErrorAdviceBot : Robot
{
protected override void OnStart()
{
foreach (ErrorCode code in Enum.GetValues(typeof(ErrorCode)))
Print("{0}: {1}", code, Advice(code));
Stop();
}
private static string Advice(ErrorCode code)
{
switch (code)
{
case ErrorCode.BadVolume: return "Fix the volume (step, minimum, maximum), do not retry";
case ErrorCode.NoMoney: return "Reduce the volume, do not retry";
case ErrorCode.MarketClosed: return "Wait for the session";
case ErrorCode.InvalidStopLossTakeProfit: return "Fix the distance or the side, do not retry";
case ErrorCode.InvalidRequest: return "Check the arguments, do not retry";
case ErrorCode.UnknownSymbol: return "Check the symbol name";
case ErrorCode.NoTradingPermission: return "Check access rights and the account";
case ErrorCode.EntityNotFound: return "The position is gone: look it up again";
case ErrorCode.Disconnected: return "Wait for the connection, then re-check the signal";
case ErrorCode.Timeout: return "Check the positions before you send again";
default: return "Log the details, retry a few times with a wait";
}
}
}
}
Run it on a demo account and compare its list with the ErrorCode list in the reference of your version. If your version has more values, they fall into the default line.
Similar Problems
| Problem | What it means | Where to look |
|---|---|---|
| Order fails, no log line | The result is not checked | IsSuccessful and Error |
| Crash on result.Position | The order failed and the position is empty | Check IsSuccessful first |
| Works in the backtest, fails live | Different volume rules, margin or session | Print volume and symbol data |
| Same failure on every bar | A retry with no change | Back off, or fix the request |
| MQL5 return codes | The same idea on MetaTrader | MQL5 trade return codes |
Checklist: What to Check When a cTrader Order Fails
- Check
IsSuccessfulafter every trade call. - Print
Errorwith the symbol, volume, stops and time. - Match the code with the table: does the request need to change, or can it wait?
- Check the volume in units against the symbol's step and limits.
- Check the margin for the volume you send.
- Check the stops: pips or price, and the side.
- After a timeout, look at the positions before you send again.
- Retry only the codes that can pass, with a wait and a small limit.
- Test on a demo account before the cBot trades with real money.
Common Mistakes
- Ignoring the result of
ExecuteMarketOrder. - Using
result.Positionwithout checkingIsSuccessful. - Retrying
BadVolumeorNoMoneyin a loop. - Sending again after a timeout without looking at the positions.
- Mixing lots and units when you calculate the volume.
- Logging only "failed" without the error and the values.
FAQ
Related Guides
- cTrader C# error CS0029: the order result and its types.
- cTrader cBot crash: index was out of range: a runtime error after the cBot builds.
- cTrader C# error CS0165: a variable is read before it has a value.
- Pine Script strategy.entry to cTrader C#: orders, labels and risk-based volume.
- Pine Script strategy.exit to cTrader C#: stop loss and take profit in pips.
- MQL5 trade return codes: the same idea on MetaTrader.
- MQL5 not enough money error 10019: the margin side of the problem.
- MQL5 invalid volume error 10014: a volume that does not match the symbol rules.
- What to check in a trading bot before going live: a pre-live checklist for stops, lot size, spread and trade results.
- cTrader volume is in units, not lots:
QuantityToVolumeInUnits, the symbol minimum, maximum and step, andBadVolume. - cTrader cBot crashed: Error # with a long number: find the exception behind a crash.
Fix Compile Errors Without Guessing
If a cBot or an Expert Advisor does not build, paste the code and the error message into the CodeFlowOS Error Fixer. It suggests a minimal fix, explains each error and shows what changed. A fix uses 1 credit, with up to 3 attempts included, and the compiler check is optional. Outputs are not guaranteed, and code that compiles can still have wrong trading logic, so always review the result. Before a bot goes live, the Code Review is free during the early-bird period. CodeFlowOS also converts strategies between Pine Script, MQL5 and cTrader C#: try the converter page.
This article is educational. It does not describe trading performance and is not financial advice. Always build the code in cTrader Automate and backtest it before using it on a live account.