How to debug a trading strategy with Visual Studio
Hey there, Protraders!
PTMC is not only a robust trading platform, but also a great tool for auto-trading implementation. It has powerful Algo Studio's backtesting features in the box and it grants an ability to boost your work with Visual Studio developing environment which is used by many coders around the world.
In previous review we shown you how to create a custom panel for PTMC trading platform using Visual Studio. This guide aims at arranging synergy between Algo Studio's backtesting and Visual Studio debugging. Lets start!
1) Set up the coding environment
Use MS Visual Studio.
Select File → New → Project .
In the following dialog window choose “.Net Framework 3,5”.
Select “Class Library” from drop-down list.
It is important to use .Net Framework 3,5 for PTMC coding.
2) Add references in Solution Explorer
Rightclick on References → Add Reference
Browse for additional PTLRuntime.dll and Commons.dll files from the PTMC root folder (AppData\Roaming\ProtraderMC(xxbit)).
These files basically introduce API and are crucial for PTMC add-ons functioning.
If you use Visual Studio version higher than 2012, it is necessary to change option in menu Debug→Options→Debugging→General (check Use Managed Compatibility Mode)
Now, create an entry point for a debugging purpose (use PTMC API's method OnQuote()).
3) Check PTMC version
Check the version of your PTMC client.
If it is 32 bit version, it is important to choose target platform.
By default it is stated as "any CPU", which is 32 bit.
You can select manually x86. Do not build it on x64, it won't work.
If your PTMC client is 64 bit — any option will work.
Compile an application in Visual Studio.
Return to PTMC client and run Algo Studio (in Tools menu).
Open module and browse for your newly build .dll file (Documents\Visual Studio\Projects).
Get back to your Visual Studio and select menu Debug → Attach to Process.
Find process algostudio.exe and bind to it.
Place a breakpoint at OnQuote() method.
Return to Algo Studio and run backtesting.
Now you are able to debug your market strategy in Visual Studio. Enjoy this powerful option from PTMC!
Have not tried PTMC yet? There is no better way to boost knowledge than to use it! Start trading with PTMC now!