Creating and referencing .dll for cBot in Visual Studio 2019
Creating and referencing .dll for cBot in Visual Studio 2019
03 May 2020, 01:21
Hello,
I am trying to create a .dll for my cBot but get stuck in reference errors and I am not really familiar with VS2019.
Does someone have a step by step instruction how to create this for cTrader in Visual Studio, together with some basic source codes of the robot and the code for the .dll?
Most information I can find on the web is outdated, not working or incomplete. I think this will be a great help for many who wants to implement this.
Thank you very much in advance.
Kind regards,
Stephan
Replies
Amaizing
04 May 2020, 11:15
RE:
PanagiotisCharalampous said:
Hi Stephan,
There is nothing specific in cAlgo and cTrader for this. It works in the exact same way as any .Net project. To help you further, 'you need to provide us information on what error messages you receive and how to reproduce them.
Best Regards,
Panagiotis
Hi Panagiotis, I am familiar with building cBot and Indicators in the cTrader app but meanwhile I have so many supporting methods I want to bring them in a external class for which i was looking to do this with a .dll, however I am not experienced in Visual Studio. I've did some research online and tried to build tin in a .NET project but somewhere I need to reference the both source files (cbot and dll) to each other by code and some handlings in Visual Studio. Also I need to reference the dll in cTrader to the cBot. I just get stuck because somewhere as I just don't follow the right approach. With all things in life, it is easy as you know what to do. Therefore I kindly request if somebody can help me by sharing all the right steps and provide some working basic code. Thank you.
@Amaizing
PanagiotisCharalampous
04 May 2020, 11:27
Hi Stephan
If what you need is to add a reference of a dll to a cBot then do the following.
- Edit the cBot in VS
- Right click on References
- Choose "Add Reference..."
- In the pop up window, choose "Browse"
- Click on Browse, find your dll and add it
I hope this helps
Best Regards,
Panagiotis
@PanagiotisCharalampous
Amaizing
04 May 2020, 12:18
RE:
PanagiotisCharalampous said:
Hi Stephan
If what you need is to add a reference of a dll to a cBot then do the following.
- Edit the cBot in VS
- Right click on References
- Choose "Add Reference..."
- In the pop up window, choose "Browse"
- Click on Browse, find your dll and add it
I hope this helps
Best Regards,
Panagiotis
Hi Panagiotis ,
Thank you for your help. I managed to make a dll in a new .NET project, but this was empty and step by step online tutorial. But when I try to make this dll for my cbot in VS it does not work, reference, gives errors and/or was not saved as dll.
I really need a step by step instruction, just to start with a empty bot and create a new dll.
@Amaizing
PanagiotisCharalampous
04 May 2020, 12:43
Hi Stephan
You really need to provide more information. At this moment I do not understand what is the problem. You did not tell us what do you do in detail neither you provided information about what errors do you get. This is not a cBot/cTrader issue. It is a standard process of adding a new reference into a .Net project and I am pretty sure you will find tons of available resources with a simple google search. It is not cTrader specific.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Amaizing
04 May 2020, 14:27
RE:
PanagiotisCharalampous said:
Hi Stephan
You really need to provide more information. At this moment I do not understand what is the problem. You did not tell us what do you do in detail neither you provided information about what errors do you get. This is not a cBot/cTrader issue. It is a standard process of adding a new reference into a .Net project and I am pretty sure you will find tons of available resources with a simple google search. It is not cTrader specific.
Best Regards,
Panagiotis
Hi Panagiotis,
It is indeed not a cBot/cTrader issue and you can find tons of information about how to create a dll from a new .NET project in Visual Studio, however I cannot find anywhere a clear and whole instruction how to make this work for me in cTrader. Only how to reference a existing dll but before this i do first need to build a dll in VS. For this I do ask instructions on this forum.
Your post 14 Jan 2019, 10:35 was very helpful and lets take this as starting point.
In cTrader I create a new cBot and put here the next code:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
protected override void OnStart()
{
Print(General.GetPosCnt(this));
Print(General.GetLastCloseValue(this));
}
protected override void OnBar()
{
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
This I cannot Build because the General does not exist in the current context, also i do not have a dll yet. So I start with a default bot, I Build this successfully and then Edit in Visual Studio, after which Visual Studio 2019 opens with the code. Here I can paste the above code. The 'cBots and Custom Indicators' extension I do have installed. Then what should I do next to create the dll based on the code below?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
namespace cAlgo
{
public class General
{
public static int GetPosCnt(Robot robot)
{
int iPosCnt;
iPosCnt = robot.Positions.Count;
return iPosCnt;
}
public static double GetLastCloseValue(Robot robot)
{
return robot.MarketSeries.Close.LastValue;
}
}
}
As last, how to reference them and make this work as a whole in cTrader?
Thank you in advance.
Kind regards,
Stephan
@Amaizing
PanagiotisCharalampous
05 May 2020, 08:36
( Updated at: 21 Dec 2023, 09:22 )
Hi Stephan
It seems that you are trying to create an external dll using a cBot. This is not possible. cAlgo projects are not designed to generate a .dll. You need to create a standard C# Library in Visual Studio, develop your .dlll and thed add it as a reference to your cBot project. You cannot develop a .dll library using cTrader. If you want to do this within the solution of your cBot, follow the next steps
1. Create a new cBot and open in in VS
2. Right Click on the solution > Add > New Project...
3. Create a new Class Library project
4. Go back to the cBot project, right click on References > Add New Reference and add a reference to the newly created project
Then you can program your classes in the the external library and use them in your cBot
Best Regards,
Panagiotis
@PanagiotisCharalampous
fernando6475436
08 May 2020, 15:25
Helping my bro
Dude, your comment was deleted for some reason, but if you read it then here is the resource you asked about Share founders forex
@fernando6475436
PanagiotisCharalampous
04 May 2020, 10:16
Hi Stephan,
There is nothing specific in cAlgo and cTrader for this. It works in the exact same way as any .Net project. To help you further, 'you need to provide us information on what error messages you receive and how to reproduce them.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous