Support Board
Date/Time: Mon, 21 Apr 2025 18:37:17 +0000
Post From: How to Use Visual Studio 2022 Community to Develop Custom Studies for Sierra Chart
[2025-02-22 17:04:03] |
ondafringe - Posts: 322 |
Visual Studio (VS) is a powerful IDE with a powerful debugger. Unfortunately, creating and configuring a custom study project with VS can be challenging and complicated. I have already written step-by-step instructions on how to configure a project, but recently someone expressed an interest in venturing deeper into the VS coding environment. So this is my attempt to bring things together in one place by providing step-by-step instructions to facilitate the entire creation/configuration process. This guide is for anyone who wants to take the next step and move their custom study development process to a full-fledged IDE. VS does have a learning curve (SC did too, and you survived!), so don't let these instructions scare you off because there are plenty of online resources available to help you along the way. And just like you don't have to know everything about SC to trade, and you don't have to know everything about C++ to code a custom study, you also don't have to know everything about VS to use it as your development platform. Once you get your custom study project created and properly configured, you will be able to edit, debug, build and deploy your project -- all from within the VS IDE -- without having to close and reopen SC, and without having to invoke the “Release All DLLs and Deny Load” in Sierra Chart (with one exception, covered below). Note: If you are only using Visual Studio as an editor and you are doing your build from within Sierra Chart, or you are using VSCode, the following may not/probably won't work. There may be other ways to accomplish the following, but this is how I do it. How to Create a Custom Study Project that will Generate a DLL • Download and install Visual Studio 2022 Community (install it anywhere you want) • Download Link: https://visualstudio.microsoft.com/vs/community/ • Open Visual Studio • Click “Create a New Project” • Make sure the three drop-down menus at the top are set to: C++ – Windows – Desktop • Select “Windows Desktop Wizard” • Click “Next” • Enter a name for your project (name your project the same name as your DLL, you can explore other options later) • Select a location for your project • Check “Place solution and project in the same directory” • Click “Create” • In the drop-down, select “Dynamic Link Library (.dll)” • Check “Empty Project” • Click “Ok” You should now have an empty custom study project. • Solution Explorer may or may not be open, but at the top of VS, click “View > Solution Explorer” to be sure • At the top of Visual Studio, you should see “Debug” and “x64” • You can select either “Release” or “Debug” depending on your needs • If you see “x86” change it to “x64” • In “Solution Explorer” (should be in upper-right of screen), click on the project name and, in the pop-up menu, click “Add” • Click “New Item” • Provide a name for your source file (.cpp), click “Add” • An empty source file (.cpp) should have been created and opened for editing IMPORTANT When you create a custom study project, you create a new, empty source file (.cpp) that resides in the project folder. If you are moving a previous custom study over to VS, you need to COPY the contents of the original source file (.cpp that is usually located in the ACS_Source folder) and PASTE it into this new, empty source file (.cpp) that resides in your project folder. Once you do that, you should never work with -- or reference -- that original source file ever again while working in VS. How to Configure a Custom Study Project • In “Solution Explorer,” right-click on your project name and, at the very bottom of the pop-up menu, click on “Properties” • Under “Configuration Properties > General > Output Directory” • Provide the path to the Sierra Chart “Data” folder (usually C:\SierraChart\Data\) • Under “Linker > General > Output File” • Provide the same path to the Sierra Chart “Data” folder and add $(TargetName)$(TargetExt) • That usually results in C:\SierraChart\Data\$(TargetName)$(TargetExt) • Under “Configuration Properties > VC++ Directories > Include Directories" • At the very end, after the semi-colon, add the path to the Sierra Chart “ACS_Source” folder" • That usually results in C:\SierraChart\ACS_Source\ At the top of Visual Studio, change “Debug” to “Release” – or vice versa – and repeat the above steps. When you use Visual Studio to create a custom study to run in Sierra Chart, it would be advantageous if you could update your study’s “dll” file without having to close and reopen Sierra Chart and without having to invoke the “Release All DLLs and Deny Load” in Sierra Chart. Visual Studio has Pre-Build and Post-Build events you can use to do just that. One Exception: If you change anything inside the "Set Defaults" block of code, after you build/deploy, you will have to remove the study from your chart, click "Apply," and re-add the study to your chart for those changes to take effect. What You will Need and How to Get It • Windows Powershell Version 6 (or higher) • Powershell Tools for Visual Studio 2022 As I understand, all versions of Windows, including Windows 11, only have Version 5.1 (or earlier) installed. To check your version, open Powershell and, at the prompt, type: $PSVersionTable :and press Enter. If you need to download and install the most recent version of Windows Powershell. The following download link was good as of 2025-02-21. Install it wherever you want. https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/PowerShell-7.4.4-win-x64.zip To install the “Powershell Tools for Visual Studio 2022” extension. At the top of Visual Studio: • Click “Extensions” • Click “Manage Extensions” • When the Extension Manager opens, search for “Powershell Tools” • You should see “Powershell Tools for Visual Studio 2022” in the results • Click on that extension, and, at the top of the adjacent pane, click "Install" Once you have Powershell and the Powershell Tools extension installed: Final Configuration • In Visual Studio, go to “Solution Explorer,” right-click on your project name and, at the very bottom of the pop-up menu, click on “Properties” • Under “Build Events > Pre-Build Event > Command Line” • Put this: {full path to the powershell.exe file} -File "ReleaseDLL.ps1" • Example: C:\Powershell\powershell.exe -File "ReleaseDLL.ps1" • Under “Build Events > Post-Build Event > Comand Line” • Put this: {full path to the powershell.exe} -File "ReloadDLL.ps1" • Example: C:\Powershell\powershell.exe -File "ReloadDLL.ps1" • Click “Okay” to exit At the top of Visual Studio, change “Debug” to “Release” – or vice versa – and repeat the above steps. I have attached the two Powershell script files; download and put them in the project folder. Open each file using any text editor and change “your.dll” to the name of your DLL (with no quotes). If you put the ReleaseDLL.ps1 and ReloadDLL.ps1 files in a folder other than the project folder, you will have to provide the full path to those two files in the pre-/post-build events, above. Make certain you set your Sierra Chart UDP port to the same port indicated in the two Powershell script files: • Global Settings > Sierra Chart Server Settings > UDP Port The UDP port doesn't have to be the same port I used, just make certain the port you use is the same in all three places. One last note: SC creates a DLL with a "_64" appended to the DLL name, VS does not, and "_64" in the DLL name is not required. For any existing custom studies you are currently using, where you plan to move further editing to VS, it would be wise to first remove that existing study from the chart, and delete the "_64.dll" file and all its associated files (_64.exp _64.lib _64.pdb) for that study from the SC data folder. Then build/deploy the new version of that study and re-add it to the chart. ************* !! WARNING !! ************* Based on the above configuration, other than the one exception (above), when you build/deploy from within VS, your changes will take effect IMMEDIATELY!! So if you are coding a study that actually places trade orders, make sure you leave SC in SIM mode until you are ABSOLUTELY CERTAIN you have all the bugs worked out -- because it would be very traumatic if something were to glitch out and you suddenly find yourself short 1,000 contracts in your real-money account! That would definitely ruin your day... maybe even your life!! :) *************************************************************************************** Okay, there you have it... to the best of my ability. You should now be ready to start coding. Yes, I feel you shaking your heads and freaking out! lol Don't worry, once you get your feet wet and use VS to develop a few studies, it will become second nature. Hopefully, all this will work for you, as it did for me. Damn that was long! lol **************************************************************************************** I do not take credit for figuring all this out by myself. Most of the credit goes to others, some from this forum, some from other forums. The only thing I can take credit for is for digging it all up and putting all the pieces together in one cohesive package. **************************************************************************************** Date Time Of Last Edit: 2025-02-25 22:00:03
|
![]() ![]() |