Inherit from cAlgo.API.Bot

Created at 11 Dec 2020, 18:15
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JE

JeanPaul

Joined 17.10.2020

Inherit from cAlgo.API.Bot
11 Dec 2020, 18:15


I have a collection of bots that have common features. If I create an intermediate BotBase and inherit from cAlgo.API.Bot, like this

```

public class BotBase : cAlgo.API.Bot {

...

}

```

I made all my bots inherit BotBase rather than cAlgo.API.Bot. Now, when I try to Build in Visual Studio 2019, I am getting this error message:
"No algo source file was found in "MyBot.csproj"

This error is obviously coming from the cBot Visual Studio plugin.

Having a base class is a common practice in OOP, so I trust I am not doing anything out of the ordinary here.

Is there a workaround to enable a base bot class?


@JeanPaul
Replies

afhacker
12 Dec 2020, 12:44

There is no "cAlgo.API.Bot" class, you should inherit from "cAlgo.API.Robot" class, it works fine for me both for cBots and indicators.

The only problem is with "Parameter" attribute, if you define your parameters on base class for inherited classes the parameters will not show up on cTrader because they have set the "Parameter" attribute "Inherited" property to "False", not sure why they did that, I hope they fix this issue so we will be able to have our common parameters on single base class, for now the only solution is to make the parameter properties abstract so the child classes must override those parameter properties.


@afhacker

JeanPaul
14 Dec 2020, 16:44

RE:

afhacker said:

There is no "cAlgo.API.Bot" class, you should inherit from "cAlgo.API.Robot" class, it works fine for me both for cBots and indicators.

The only problem is with "Parameter" attribute, if you define your parameters on base class for inherited classes the parameters will not show up on cTrader because they have set the "Parameter" attribute "Inherited" property to "False", not sure why they did that, I hope they fix this issue so we will be able to have our common parameters on single base class, for now the only solution is to make the parameter properties abstract so the child classes must override those parameter properties.

Thank you, I meant cAlgo.API.Robot. But I have my base class in a different project ".cproj", do you is this the same for you?


@JeanPaul