BUG: [Robot] attribute is recognized even when commented out or in conditional comment

Created at 04 Nov 2014, 23:57
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!
AlexanderRC's avatar

AlexanderRC

Joined 04.02.2014

BUG: [Robot] attribute is recognized even when commented out or in conditional comment
04 Nov 2014, 23:57


The problem I encountered is that [Robot] attribute is recognized even when it is enclosed in //, /**/ comments or even in #if #endif conditional compilation pragmas.

I am using VS2010 and latest Spotware cAlgo if that matters.

Steps to reproduce.

1. Create a new Robot1 in cAlgo.

2. Use the minimal code

using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Robot1 : Robot
    {
    }
}

3. Edit in Visual Studio.

4. Add to the project additional class Robot2.cs with the following code. Note the Robo instead of Robot

using cAlgo.API;

namespace cAlgo
{
    //[Robo(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Robot2 : Robot
    {
    }
}

5. Compile in Visual Studio and in cAlgo. No errors should be reported.

6. Change Robo to Robot and try to compile in cAlgo and in Visual Studio. You should get an error message "Project "Robot1.csproj" contains more than one algo source file."

I am trying to create a Multi-cBot backtest solution here by gathering several cBots into one. This bug prevents me from creating the no hassle solution which would not require to touch even a single line of code by employing build symbols in conditional comments (#if).

Now I have to include the code for other cBots as linked .cs into a "multiCbot" VS2010 project and cripple the [Robot] attribute by changing it into something like //[Robo].

It took me 2 hours to figure this out.

Please fix.

And by the way, error message is not strictly correct. It refers to "source files" when they should refer to "classes marked with [Robot] attribute" (or [Indicator]).

 


@AlexanderRC
Replies

AlexanderRC
05 Nov 2014, 00:20 ( Updated at: 21 Dec 2023, 09:20 )

Also, symbols defined at the project level seem to be ignored.


@AlexanderRC

Spotware
05 Nov 2014, 11:57

The problem I encountered is that [Robot] attribute is recognized even when it is enclosed in //, /**/ comments

We can recommend you to remove Robot attribute instead of putting it into the comment. We are not going to change this behavior in near future.

You should get an error message "Project "Robot1.csproj" contains more than one algo source file."

We will change this message.

I am trying to create a Multi-cBot backtest solution here by gathering several cBots into one.

cAlgo and cTrader do not support .algo files with several algo types (cBots or Indicators).

Also, symbols defined at the project level seem to be ignored.

You are right, conditional compilation symbols are ignored. We will consider to support conditional compilation in the future.


@Spotware

AlexanderRC
05 Nov 2014, 13:43

RE:

Spotware said:

The problem I encountered is that [Robot] attribute is recognized even when it is enclosed in //, /**/ comments

We can recommend you to remove Robot attribute instead of putting it into the comment. We are not going to change this behavior in near future.

That is exactly what I am doing. That is a manual step. Too sad that tokenizer does not differentiate between comments (or excluded parts of the source code) and actually applied attribute. (I assume that the analysis for several classes with applied [Robot] attribute is done at the source level, not at the compiled [in-memory] assembly level).

You should get an error message "Project "Robot1.csproj" contains more than one algo source file."

We will change this message.

Good, the error message is misleading now. The introduction of VS integration permits us to use additional .cs files as a part of .csproj. Even files included by reference (from external directories) work as expected.

I am trying to create a Multi-cBot backtest solution here by gathering several cBots into one.

cAlgo and cTrader do not support .algo files with several algo types (cBots or Indicators).

That is why I have created a solution to run several cBots inside a main multi cBot to see the combined curve in backtesting mode or even to optimize volumes for individual cBots to get a smoother curve when they work simultaneously.

To minimize source code changes when compiling as part of invidual cBot or as a part of multi cBot I am using conditional compilation to include or exclude required changes for multi cBot integration. Removing [Robot] attribute via #ifdef should have allowed me to do just that. Now I have to add #define MULTI_CBOT and comment out [Robot] attribute and change it to something like //[NRobot] in a .cs for individual cBot when compiling it as a part of multi cBot.

Also, symbols defined at the project level seem to be ignored.

You are right, conditional compilation symbols are ignored. We will consider to support conditional compilation in the future.

The symbols are ignored only when defined at the project level. When I add #define FOOBAR into the source file directly, #if FOOBAR works later in that file as expected. The only effort to support project level symbols would be to pass symbol defines down to the C# compiler engine.


@AlexanderRC