RobotAttribute

Created at 19 Apr 2015, 03:27
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!
lec0456's avatar

lec0456

Joined 14.11.2012

RobotAttribute
19 Apr 2015, 03:27


Can I use  RobotAttribute.Name to get the name of the robot?

 

 


@lec0456
Replies

WhiteSage
19 Apr 2015, 13:19

You can get the class name which is always the same as the indicator name (without spaces)

Type T = typeof(cAlgo.thisRobot);
Print(T.Name);

but its kind of redundant as changing the name of a cBot once it is changed away from the default name, doesn't re-factor the class name.

using System.Reflection;
namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
    public class classNamedTest : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Type T = typeof(cAlgo.classNamedTest);
            Print(T.Name + " and " + this.ToString() + " are the same.");
            Assembly A = T.Assembly;
            AssemblyName N = A.GetName();
            Print(N.Name + " is the indicators name.");
        }

    }
}

Name of cBot in IDE side bar is 'Indicator Named Test'

Result:

classNamedTest and classNamedTest are the same.
Indicator Named Test is the indicators name.

It would be handy if it was exposed, more so if changing the indicator or cBot name refactored the class name (same as Indicator name but with no spaces etc).


@WhiteSage

WhiteSage
19 Apr 2015, 13:42

RE:

WhiteSage said:

You can get the class name which is always the same as the indicator name (without spaces)

Sorry it is not always the same! 


@WhiteSage

lec0456
19 Apr 2015, 18:22

I think what I was looking for was just this.ToString()

It returns the name of the Algo.  It is for logging data into a separate database.


@lec0456

WhiteSage
19 Apr 2015, 19:33

Just be aware if you change the name of your cBot/Indicator but not the class name (in the code) your logs will not represent that new name unless you use typeof(class).Assembly.GetName.Name


@WhiteSage

lec0456
19 Apr 2015, 20:10

I'm not sure how you would even do that in cAlgo.  I thought they have to be the same.  Do you have an example?


@lec0456

WhiteSage
19 Apr 2015, 22:35

Example provided works, just paste in after the last using statement. For some reason beyond my control my test became un-linked and the class name wasn't changing automatically, sorry about that.
You need to add

using System.Reflection;

And set your  AccessRights to FileSystem as reflections requires it.
The one line magic you are looking for is:

Print(this.GetType().Assembly.GetName().Name);

and this will return the name as it is typed in the cAlgo interface.
Hazzah, Wizard stuff.

 


@WhiteSage