Quick Answer
CS0117: 'TradeType' does not contain a definition for 'Long' means that the type exists, but the name after the dot does not. You wrote TradeType.Long, and TradeType has no member with that name. In cTrader it almost always happens with an enum or a type with fixed names: TradeType, MovingAverageType, TimeFrame, StopTriggerMethod and similar.
The fix is to use the name that the type really has. Type the type name and a dot in the editor and read the list that code completion shows, or open the cTrader Automate reference for that type. The sections below show the names that converted code gets wrong most often, and a table from MQL5 and Pine Script names to the cTrader names.
From the author: I build cBots in cTrader Automate and convert strategies from Pine Script and MQL5 to C#. CS0117 is the error you get when an MQL5 constant such as
MODE_EMAor a Pine word such asstrategy.longis turned into a C# name by guessing. The guess looks right and the compiler disagrees.
Key Facts
| What you see | Usual cause | Fix |
|---|---|---|
| 'TradeType' does not contain a definition for 'Long' | A Pine or MQL5 word used as a name | TradeType.Buy or TradeType.Sell |
| 'MovingAverageType' does not contain a definition for 'EMA' | An abbreviation instead of the real name | MovingAverageType.Exponential |
| 'TimeFrame' does not contain a definition for 'H1' | An MQL5 or chart short name | TimeFrame.Hour |
| A name that only differs in capital letters | C# is case sensitive | Copy the name from code completion |
| A name from an older or newer API | The member was added or renamed | Check the reference for your version |
| Same wording, but on a variable | The object is an instance, not a type | See CS1061 |
CS0117 vs CS1061
Both say "does not contain a definition". The difference is what stands in front of the dot. In CS0117, it is a type name (TradeType, MovingAverageType): the compiler looks for a fixed member, such as an enum value or a static member, and does not find it. In CS1061, it is a variable or an object (position, Bars): the object has no member with that name. When the word before the dot starts with a capital letter and is a type, think CS0117.
The Broken cBot
This cBot only prints. It has no order calls. Each marked line has a CS0117 error:
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class BrokenBot : Robot
{
private MovingAverage _ma;
private Bars _hourBars;
protected override void OnStart()
{
_ma = Indicators.MovingAverage(Bars.ClosePrices, 14, MovingAverageType.EMA); // CS0117: no member 'EMA'
_hourBars = MarketData.GetBars(TimeFrame.H1); // CS0117: no member 'H1'
}
protected override void OnBar()
{
TradeType side = Bars.ClosePrices.Last(1) > _ma.Result.Last(1)
? TradeType.Long // CS0117: no member 'Long'
: TradeType.Short; // CS0117: no member 'Short'
Print("Side {0}, hour bars {1}", side, _hourBars.Count);
}
}
}
The compiler reports one message for each name, for example 'MovingAverageType' does not contain a definition for 'EMA'. Check the exact text in your build.
Cause 1: Trade Direction Names
TradeType has two members, Buy and Sell. Pine Script uses strategy.long and strategy.short, and many platforms use "long" and "short" for the same thing. In cTrader, a long position is a buy, and a short position is a sell:
TradeType side = isUp ? TradeType.Buy : TradeType.Sell;
If you keep a direction of your own with the names Long and Short, define your own enum and convert once at the point where you place the order.
Cause 2: Moving Average Types
The MovingAverageType enum has full names and no abbreviations. According to the cTrader reference, its members are Simple, Exponential, TimeSeries, Triangular, VIDYA, Weighted, WilderSmoothing, Hull, DoubleExponential, TripleExponential and KaufmanAdaptive. So EMA, Ema, SMA and Exp do not exist.
| MQL5 or Pine name | cTrader name |
|---|---|
| MODE_SMA, ta.sma | MovingAverageType.Simple |
| MODE_EMA, ta.ema | MovingAverageType.Exponential |
| MODE_LWMA, ta.wma | MovingAverageType.Weighted |
| MODE_SMMA, ta.rma | MovingAverageType.WilderSmoothing (the closest match: compare the values with your chart) |
The last row is a match by meaning, not by name. Print both series on the same bars and compare them before you rely on it.
Cause 3: Time Frame Names
TimeFrame is a class with named members such as Minute, Hour, Daily, Weekly and Monthly, and numbered variants such as Minute5 and Hour4. Names that you see on a chart button (H1, M5, D1) or in MQL5 (PERIOD_H1) are not members, and TimeFrame.H1 gives CS0117. The reference lists the exact names; open the list in code completion once and copy the names you need:
Bars hourBars = MarketData.GetBars(TimeFrame.Hour);
Bars m5Bars = MarketData.GetBars(TimeFrame.Minute5);
Cause 4: Capital Letters and Typing
C# is case sensitive: TradeType.buy and TradeType.BUY are not TradeType.Buy. A member that you typed from memory is the easiest place for a one-letter mistake. Delete the name after the dot, type the dot again and let code completion offer the list. If the list does not show the name, it does not exist in your version.
Cause 5: A Member From Another Version of the API
An API grows. A name from a tutorial or from a forum post can come from an older or a newer version than the one you build with. If the name is spelled right and the type has it in the online reference but not in your code completion, check the version of the API your cBot uses. If the name is in your code completion but not in the reference, the reference page may be for a different version. Use what your own editor shows.
The Fixed cBot
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FixedBot : Robot
{
private MovingAverage _ma;
private Bars _hourBars;
protected override void OnStart()
{
_ma = Indicators.MovingAverage(Bars.ClosePrices, 14, MovingAverageType.Exponential);
_hourBars = MarketData.GetBars(TimeFrame.Hour);
}
protected override void OnBar()
{
if (Bars.Count < 20)
return;
TradeType side = Bars.ClosePrices.Last(1) > _ma.Result.Last(1)
? TradeType.Buy
: TradeType.Sell;
Print("Side {0}, hour bars {1}", side, _hourBars.Count);
}
}
}
The bot only prints. The Bars.Count check at the top avoids the runtime error described in cBot index out of range. Compare the printed side with the chart before you add an order, and test on a demo account.
Similar Errors
| Error | Message | What it means | |---|---|---| | CS0117 | 'Type' does not contain a definition for 'X' | The type has no member with that name | | CS1061 | 'Object' does not contain a definition for 'X' | The object has no member with that name | | CS0103 | The name 'x' does not exist in the current context | A name is unknown | | CS0246 | The type or namespace name could not be found | The type itself is unknown | | CS0029 | Cannot implicitly convert type | A value of the wrong type |
Checklist: What to Check When You See CS0117
- Read the type and the name in the message.
- Type the type name and a dot and read code completion.
- Replace Pine and MQL5 words (
Long,Short,EMA,H1) with the cTrader names. - Check capital letters.
- Check the reference for the member and the version of the API.
- Compare the meaning when a name maps by meaning only (the smoothed average).
- Build again after each change, and print the values.
- Test on a demo account before the cBot trades with real money.
Common Mistakes
- Guessing the name from the MQL5 constant.
- Using chart short names (
H1,M5) as members ofTimeFrame. - Writing
TradeType.Longafter reading Pine code. - Abbreviating
ExponentialtoEMA. - Assuming that a similar average is the same average without comparing values.
- Copying a name from a post for another API version.
FAQ
Related Guides
- cTrader C# error CS1061: the object is found, the member is not.
- cTrader C# error CS0103: the name does not exist in the current context.
- cTrader C# Error CS0246: a type name the compiler does not know.
- cTrader C# error CS0029: a value of the wrong type.
- cTrader C# error CS0019: an operator used between two types that do not work with it.
- cTrader cBot crash: index was out of range: a runtime error after the cBot builds.
- Pine Script strategy.entry to cTrader C#: order calls and
TradeType. - 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 CS0115: an
OnBarorOnTickoverride that does not match the base method.
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.