Quick Answer
CS0115: 'BrokenBot.OnBar(int)': no suitable method found to override means that your cBot contains a method marked override, but the Robot base class has no method with that name and those parameters. The compiler looks for OnBar(int), finds only OnBar(), and stops. In converted code it comes from three habits: parameters added to an event handler (OnBar(int index), OnTick(double price)), a misspelled handler name (OnBars, Ontick), and a handler that exists in another platform but not in cTrader.
The fix is to use the handler exactly as the Robot class declares it: the same name, the same parameters (usually none) and the keyword override. If you need the index or the price, read it inside the method from Bars or Symbol.
From the author: I build cBots in cTrader Automate and convert strategies from Pine Script and MQL5 to C#. In MQL5,
OnTick()andOnCalculate(...)are fixed functions with their own parameter lists, and indicator code passes anindexorrates_totalaround. When that shape is copied into a cBot, the handler gets parameters that the base class does not have, and the compiler says CS0115.
Key Facts
| What you see | Usual cause | Fix |
|---|---|---|
| OnBar(int): no suitable method found to override | A parameter was added | protected override void OnBar(), read the data inside |
| OnTick(double): no suitable method found to override | The same, with the price | protected override void OnTick(), read Symbol.Bid |
| OnBars() or Ontick(): no suitable method found | A typo in the name | Copy the name from code completion |
| A method that exists only on another platform | MQL5 or Pine names (OnInit, OnDeinit, OnCalculate) | Use OnStart, OnStop or OnBar |
| cannot change access modifiers when overriding (CS0507) | public instead of protected | Use the access level of the base method |
| return type must be 'void' (CS0508) | int OnStart() as in MQL5 OnInit | Return void |
What the Error Means
A cBot is a class that inherits from Robot. The platform calls special methods of the base class at fixed moments: when the cBot starts, when a tick arrives, when a bar opens, when the cBot stops. To run your own code at those moments, you override the base method, and the override must match the base method in name and parameters. If it does not, there is nothing to override, and the compiler reports CS0115.
According to the cTrader reference, the handlers include OnStart, OnTick, OnBar, OnBarClosed, OnStop, OnTimer, OnException and OnError(Error error). Some take no parameters and some take one, so check the reference or the code completion for the exact list in your version. Typing override in the class body and a space makes the editor offer the methods that can be overridden. That list is the safest source.
The Broken cBot
This cBot only prints. It has no order calls. Each marked method has a CS0115 error:
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class BrokenBot : Robot
{
protected override void OnStart()
{
Print("Started");
}
protected override void OnBar(int index) // CS0115: no OnBar(int) in Robot
{
Print("Bar {0}, close {1}", index, Bars.ClosePrices.Last(1));
}
protected override void OnTick(double price) // CS0115: no OnTick(double) in Robot
{
Print("Price {0}", price);
}
protected override void OnBars() // CS0115: no OnBars() in Robot
{
Print("New bar");
}
}
}
The compiler reports each method with its full signature, for example 'BrokenBot.OnBar(int)': no suitable method found to override. Check the exact text in your build.
Cause 1: Parameters Added to a Handler
An MQL5 indicator has OnCalculate(rates_total, prev_calculated, time[], ...), and a function that is called for each bar gets an index. In a cBot, the handler has no index. The current state of the market is on the objects of the cBot:
protected override void OnBar()
{
int lastIndex = Bars.Count - 1; // the index of the forming bar, if you need it
double lastClose = Bars.ClosePrices.Last(1); // the last closed bar
Print("Bar {0}, close {1}", lastIndex, lastClose);
}
protected override void OnTick()
{
double price = Symbol.Bid;
Print("Price {0}", price);
}
Read the value you need inside the method. The same applies to OnStart, which has no parameters, too. Use Bars.Count carefully on a short chart, as in the index out of range guide.
Cause 2: A Misspelled Name
OnBars, Onbar, OnTicks, OnStarted look right and do not exist. C# is case sensitive and the name must match exactly. A related trap: a method that has the right name but no override keyword gives a warning that it hides the base method (CS0114), which is easy to miss. Always write protected override void OnBar() with the keyword, so that a wrong name is an error and not a silent mistake.
Cause 3: Names From MQL5 or Pine Script
| MQL5 or Pine Script | cTrader |
|---|---|
| OnInit() | OnStart() |
| OnDeinit(reason) | OnStop() |
| OnTick() | OnTick() (same name, no parameters) |
| New bar logic with iTime or barstate.isnew | OnBar() or OnBarClosed() |
| OnTimer() | OnTimer(), started with Timer.Start(...) (check the reference) |
| OnTradeTransaction(...) | Events such as Positions.Opened and Positions.Closed |
The cTrader reference marks the old position hooks such as OnPositionOpened as deprecated and points to the Positions.Opened event instead. Prefer events for new code. If a name is not in the code completion of override, it is not a handler.
Cause 4: A Related Pair, CS0507 and CS0508
Two related errors appear when the name is right and the rest of the signature is not:
- Wrong access level. The base handlers are
protected.public override void OnBar()can give an error about changing access modifiers when overriding (CS0507). Copyprotected. - Wrong return type. In MQL5,
OnInit()returns anint(INIT_SUCCEEDED). A C#OnStartreturnsvoid.protected override int OnStart()can give an error about the return type (CS0508).
Check the exact messages in your build. In both cases, the editor's list after the word override gives the correct line.
The Fixed cBot
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FixedBot : Robot
{
protected override void OnStart()
{
Print("Started");
}
protected override void OnBar()
{
if (Bars.Count < 3)
return;
Print("Bar {0}, close {1}", Bars.Count - 1, Bars.ClosePrices.Last(1));
}
protected override void OnTick()
{
Print("Price {0}", Symbol.Bid);
}
}
}
The bot only prints. OnTick prints on every tick, so stop the bot after a few lines in a test, or remove that handler. Compare the values with the chart, and test on a demo account before you add orders.
Similar Errors
| Error | Message | What it means |
|---|---|---|
| CS0115 | no suitable method found to override | The base class has no method with this name and parameters |
| CS0507 | cannot change access modifiers when overriding | public where the base method is protected |
| CS0508 | return type must be 'X' to match the overridden member | A wrong return type |
| CS0114 | hides inherited member, add override | The name matches, override is missing |
| CS0534 | does not implement inherited abstract member | A required method is missing |
Checklist: What to Check When You See CS0115
- Read the signature in the message: the name and the parameter types.
- Type
overrideand a space in the class and read the list the editor shows. - Remove the parameters from handlers such as
OnBarandOnTick. - Check the name letter by letter, including capital letters.
- Replace MQL5 and Pine names (
OnInit,OnDeinit) with the cTrader ones. - Use
protected override void, withvoidas the return type. - Build again after each change, and print the values.
- Test on a demo account before the cBot trades with real money.
Common Mistakes
- Adding an
indexparameter toOnBar. - Writing
OnInitin a cBot. - Leaving out
override, so that a wrong name is not noticed. - Using
publicfor a handler that isprotected. - Returning
intfromOnStartas MQL5OnInitdoes. - Copying a handler from an indicator into a cBot.
FAQ
Related Guides
- cTrader C# error CS0120: a member that needs a cBot object is used without one.
- cTrader C# error CS0103: the name does not exist in the current context.
- cTrader C# error CS1061: the object is found, the member is not.
- cTrader C# errors CS1002 and CS1513: a missing semicolon, brace or parenthesis.
- cTrader C# error CS0161: a method that does not return on every path.
- cTrader cBot crash: index was out of range: a runtime error after the cBot builds.
- Pine Script barstate.isnew in MQL5: run logic once per bar on the MetaTrader side.
- Pine Script to cTrader C# cBot: the full conversion process.
- What to check in a trading bot before going live: a pre-live checklist for stops, lot size, spread and trade results.
- cTrader C# error CS0117: a type that has no member with that name, such as a wrong enum value.
- cTrader C# error CS0534: a custom indicator that is missing its
Calculate(int index)method. - cTrader error CS0535: does not implement interface member: a class that misses an interface member.
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.