Partial cAlgo integration with Visual Studio 2015 FREE Community Edition

Created at 03 Mar 2016, 10:51
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!
gainer's avatar

gainer

Joined 24.01.2016

Partial cAlgo integration with Visual Studio 2015 FREE Community Edition
03 Mar 2016, 10:51


Waiting for the official integration of cAlgo with Visual Studio 2015 (I hope the FREE Community Edition), I elaborated this partial but fully functional solution

Above all, if you don't have it yet, download and install the powerful but TOTALLY FREE Visual Studio 2015 Community Edition

https://www.visualstudio.com/en-us/products/visual-studio-community-vs.as

During the installation, you can choose the full version (with web development, C++, Python and much much more...) or select only our loved C# environment for a lighter implementation

Now this is the procedure:

  1. Open as always a NEW EMPTY cBot or Indicator in cAlgo
  2. From the left menu, click on the dropdown menu arrow near the name of the new cBot/Indicator and select BUILD WITH SOURCE CODE
  3. Always from the same menu, select SHOW IN FOLDER and you should see your cAlgo file and a folder with the same name of your cBot or Indicator
  4. For now, simply let open this window with your cAlgo project
  5. Launch the Visual Studio 2015 Community Edition
  6. From the Visual Studio top menus: FILE -> choose NEW -> PROJECT FROM EXISTING CODE...
  7. A wizard windows appears, select VISUAL C# from the bottom dropdown menu
  8. Press NEXT button and it appears the SPECIFY PROJECT DETAILS window
  9. In the "Where are the files?" copy and past the full path from the cAlgo window you left open before, it will be something as "C:\Users\Marco\Documents\cAlgo\Sources\Robots\SniperServer cBot V01"
  10. Be careful, you must ENTER WITHIN your cBot/Indicator folder to select it, not stop at the "Robots" branch
  11. Be sure the "Include subfolders" option is checked
  12. In the following field specify the name for the new integrated project
  13. I use this convention: I call "RobotName cBot" the cAlgo project, and "RobotName cSharp" the integrated project... but of course you can use the name you want
  14. Choose the default CONSOLE APPLICATION as OUTPUT TYPE
  15. Press the FINISH button, Visual Studio works a while... and it's done!
  16. Note that you can apply this steps also to your already developed cBot/Indicator

Now you can start working on your new INTEGRATED PROJECT

Within Visual Studio expand the SOLUTION EXPLORER on the right and pin it to have always the files within reach

Probably you have to expand also all the folders of the new project and then double click to open your cBot,cs file

To complete the integration, you must add the "Main" function to your cBot/Indicator code and then add the reference to cAlgo API to Visual Studio Project

 

Add the "public static void main()" to YOUR cBot/Indicator CODE

.....

        [Parameter("Order label", DefaultValue = "ShootOne")]
        public string label { get; set; }

        [STAThread()]
        public static void Main()
        {
            Console.Write("Press a key to close...");
            Console.ReadKey();
        }

        protected override void OnStart()
        {

.....

 

How you can see, every coding you act within Visual Studio is immediately reported also in cAlgo... because now the two projects are fused in the same!

  1. Now right click on the REFERENCES branch in the LEFT SOLUTION EXPLORER and ADD REFERENCE...
  2. Select the last option BROWSE from the left menu
  3. Press the BROWSE bottom button and navigate to cAlgo API folder, probably something as "C:\Users\Marco\Documents\cAlgo\API"
  4. Double click on "cAlgo.API.dll"
  5. Ensure the cAlgo.API.dll is added and checked in the central Reference Manager Windows, then OK
  6. Now expand the REFERENCES branch in the right SOLUTION EXPLORER and you must see the just added cAlgo.API.dll

...and finally all the job is done!

  • You have your usually cBot/Indicator project in cAlgo
  • But now you have also a CONSOLE PROJECT in Visual Studio
  • You can work in Visual Studio with the intellisense and all the editor options
  • You can compile and launch the console within Visual Studio, call the different method of your cBot/Indicator, set the break points, follow the flow of your code and debug it
  • But remember... this is only a "partial" integretion, there are some limitation
  • In particular, every time you add a library/dll reference in Visual Studio, you must add it also from the top menu in cAlgo enviroment

That's all and have a nice job!


@gainer
Replies

gainer
03 Mar 2016, 14:55

Since it's only a partial integration of cAlgo with the Visual Studio 2015 (I always highlight in it's FREE but powerfull Community Edition), the cAlgo internal menu "Edit in Visual Studio" doesn't work and you have to open the project directly, but it's pretty simple

  1. In cAlgo use always the "Build with source code" option, it appears clicking the left dropdown arrow menu, next to your cBot/Indicator name
  2. Open Visual Studio 2015 from its icon and select the top left menu FILE -> RECENT PROJECT AND SOLUTION -> you have only to choose your

To be more specific, if you are interested in the details

  1. In cAlgo always from the same dopdown arrow menu on the left, next to your cBot/Indicator, select the last item "Show in folder"
  2. In the window that appears, you see your cBot/Indicator cAlgo installation file, but also a folder with the same name
  3. In this folder there is the cAlgo project, but also the Visual Studio integration
  4. Open the folder and double click on the file with the name you give to your integrated project, extension .sln, and the Visual Stuio opens it
  5. If you want to deploy or move the project, remember to copy both as the .cAlgo installation file and as its folder

Personally I use only the Visual Studio IDE to develop all my project and it works very fine, both as intellisense editor and as debugger

I hope this my be helpful, waiting for the official cAlgo integration!


@gainer