Extending cAlgo Algorithms with cTrader internal DLLs

Warning: Parameter 2 to qtranxf_excludeUntranslatedPosts() expected to be a reference, value given in /homepages/12/d364152440/htdocs/gonzalopla/wp-includes/class-wp-hook.php on line 287

Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference, value given in /homepages/12/d364152440/htdocs/gonzalopla/wp-includes/class-wp-hook.php on line 287
Share this


cTrader cAlgo API comes with most of the data structures required for building indicators and experts advisors (aka bots in cTrader jargon). But when debugging the algorithm execution, Visual Studio shows class types not existing in the cAlgo API. This article shows how to access these objects or at least, how I have got access to them since I am not an expert in the .Net technology ins and outs and have no special interest on it.

Extending cAlgo objects

When trying to classify on-chart trendlines, I found that cTrader is assigning non-unique names to the new trendlines. If an old trendline was removed, when creating a new one, cTrader was reusing the names of the old trendlines to give a name to the new ones. On the image below, the trendline has been assigned “Trend Line 1” name because the old “Trend Line 1” object existed but was deleted before creating this last trendline.

For this reason, using the “Name” property of the trendline object is not a good choice, because any information stored within our program related to a trendline name could be overwritten if a new trendline is created with the same “Name”.

When analyzing the memory state at runtime we can observe that there is a property called “Uniqueid” that seems to fit in the idea of getting a default property to create a solid index of our “Chart” objects, avoiding any kind of collision due to repeated object names.

But when trying to access that property, we realize that the “ChartObject” class does not have it.

The IsAlive property could be used, which is good for internal indexing, but not friendly when trying to identify it by a human user. We should use the ChartObject object instead of a string to generate a reference to that trendline. In my opinion, it would result in worse code readability and maintenance.

If we debug the program, we find out that the trendline object is not a ChartObject instance, but a derived one called “SmallChartTrendline” and that it belongs to an unsupported namespace called “cTrader”.

The “Uniqueid” property must, therefore, be part of the “SmallChartTrendlineid” class but, how to reach it?

A quick check of the cTrader installation folder is enough to find the corresponding DLL file and other similar ones.

Now, we only have to add a reference to the specific DLL to our Visual Studio project and it will work for us.

Only the DLL in the folder of our cTrader installation can be used, because since we are attaching the debugger to the cTrader.exe process, we must use the same DLL that the cTrader.exe process is using.

If we try to copy the DLL to another location to organize our elements, we will get an error when executing. Therefore, the safest option is to just add a reference to it. We could use a symbolic link (aka shortcut) maybe, I have not tried it nor want to maintain that kind of structure for just one cTrader installation.

And doing this, we can now access properties of the Trendline object that were not reachable before through the “cAlgo” API.

Finally, using a symbolic link could be interesting as long as we maintain a reference of the cTrader version of the DLL.

Warning: Parameter 2 to qtranxf_excludeUntranslatedPostComments() expected to be a reference, value given in /homepages/12/d364152440/htdocs/gonzalopla/wp-includes/class-wp-hook.php on line 287

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.