Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 23:50:53 +0000



[Programming Help] - CPU Exceptions from Custom Studies

View Count: 731

[2021-11-28 22:54:59]
Sierra123 - Posts: 27
I keep running into these issues below with my Studies and I've not found a good way to isolate the issues.

Warning: The Custom DLL study "HLines1v1.scsf_ToolsHLines1v1" has just caused a CPU exception. | 2021-11-28 17:43:42.051 *
Warning: This Custom DLL study may cause Sierra Chart to be unstable until you remove the study from your chart and restart Sierra Chart. | 2021-11-28 17:43:42.051 *

I assumed I had and error which was overwriting a memory address because I use several arrays. I use both local arrays as well as keeping some arrays persisted in memory using the persistence calls.

e.g. if(p_Line != NULL) sc.SetPersistentPointer(2, p_Line);

At times I call the sc.UseTool to draw lines or text objects on the screen and I get a 0 return code, which indicates an error, but I do not know how to determine what the error is.

Sometimes I have been able to reduce the size of the arrays of memory allocations, and the CPU exceptions stop occurring, but I am suspicious that I've not really fixed the issues.

I have 10-15 reasonably complex studies working, but do run into these problems on a few other studies I've developed. I have tried commenting out my code section by section to determine where the issue is but that is a slow painful process.

1) Are there other debugging tips to isolate what the problems are? e.g. error codes, error reasons, etc.?
2) Is there a limit to the amount of memory (heap/stack/persistence) that can be allocated by a given study?
3) Is there a memory limit that spans all studies which is causing me to have a problem when I have all of the studies loaded?
[2025-02-20 09:43:54]
Deiter - Posts: 13
Have a look at Custom study cause CPU exception

The key line was: "You are dereferencing a null pointer, p_VolumeAtPrice, which is/causes undefined behavior." This got me to look at my code in a new way, and that led me to a solution. I hope this helps.
[2025-02-20 22:47:41]
ondafringe - Posts: 322
Are you using Visual Studio? it has a very powerful debugger.

If not, you should be, especially if you are coding complex studies.
[2025-02-20 23:55:19]
Deiter - Posts: 13
I am--but I am almost as new to Visual Studio as I am to C/C++. The debug capability in VS is the main reason I am learning to use it, rather than the text editors and Python notebooks I've used for coding in the past. I have bookmarked several Sierra Chart doc pages and user comment threads about leveraging the power of VS to help with ACS development, and I'm chipping away at it. So far, the compiler errors generated by the Sierra Chart remote build process have been great at guiding me to successful compilation and correct execution, but I know I need to become much stronger at debugging to get where I want to go.

Thank you for the recommendation! The Sierra Chart community is simply fantastic.
[2025-02-21 00:43:10]
ondafringe - Posts: 322
Are you creating/configuring/editing/building/deploying your studies, all from within VS, or are you simply using VS as an editor and building from within SC?
[2025-02-21 02:02:07]
Deiter - Posts: 13
Currently, I am using VS as an editor and relying on remote build via Sierra Chart. I have so many weak areas in my knowledge base that I am taking things very slowly. Right now my focus is on getting my simple ACS reasonably performant while also getting into a Git-based editing cycle. I'm a 50+ year-old Python script-kiddie who is finally trying to learn some C/C++, and I am just happy when I can get a clean compile on my simple ~200 lines of ACSIL.

I spent 2024 doing a lot of time in the Sierra Chart spreadsheet world, because I am much more comfortable in the Excel/Python/Pandas world of low-tech data analysis (I'm a manager type, not a comp sci guy). But like I grew beyond what I could achieve with Excel and started dabbling in Python for my data analysis needs in business, I recently decided to start getting serious about C++ to further my Sierra Chart abilities. It also helps that C/C++ are on my study path for some embedded development projects that I'm working on in my spare time.

If you have any recommended learning sources for leveraging the power of Visual Studio for ACSIL development, I would be most grateful.
[2025-02-21 02:54:46]
ondafringe - Posts: 322
If using VS as an editor and building from within SC suits your needs, then fine. You still have access to the debugger that way.

However, if you ever decide to take the next step and move your study development over to full-blown VS, let me know and I will write up a step-by-step for you (or for anyone else interested) on how to get started and how to set everything up using the free version of Visual Studio Community.

I'm not a code guru, but I get my work done. And if it makes you feel any better, I'm mid-70s and still plugging along. :)

Later...
Date Time Of Last Edit: 2025-02-21 03:54:10
[2025-02-21 13:55:23]
Deiter - Posts: 13
@ondafringe, I would be very grateful for such a guide to using Visual Studio more deeply in my ACS development work.

I am already deeply grateful for your comments here on the SC Support Board and over on NexusFi. 'Tis a good person who shares their learning with the world--especially at the intersection of two worlds with big problems, big money, and big personalities--coding and trading :)

Yes, the fact that you are a couple laps ahead of me on the running track of life--and still setting a strong pace--makes me feel very good. Keep it up, and keep us kids honest!
[2025-02-21 14:59:21]
ondafringe - Posts: 322
Okay, I'll put it all together and post it under a new thread with an appropriate title later today or this weekend.

BTW, NexusFi kicked me out of there a few years ago. One of their paid subscribers made an absurd comment about another user and I took exception to it. And since Big Mike makes his $$ from paid subscribers... lol
[2025-02-22 14:59:57]
Deiter - Posts: 13
By the way, this is where I'm at now - four different trade signals (Buy/Sell Entry, Buy/Sell Exit), displayed as ACS drawings at the price point where they occurred. The drawings provided by the SC spreadsheet studies are fantastic, but I found that having the drawings at either the top or bottom of a chart bar was not granular enough for my trading style--hence my delightful recent descent into the world of ACSIL and C++.

The key issue was controlling the rapid growth in the number of ACS drawings on the chart and the subsequent slow down in the chart (just like the SC documentation warns about). That's where a persistent double-ended queue came in. The attached GIF shows the 20 most recent trade signals being kept, while anything older gets deleted--the chart stays nice and responsive. For debugging, I used good ol' "print statements" to monitor variables, writing to the SC Message Log via sc.AddMessageToLog(). For context, this was from yesterday's NQ action, viewed on a 1k Volume chart.

I have some other ideas that I'll tinker with (e.g. add the ability to persist a certain number of drawings on each bar, to preserve some "visual memory" of the trade signals while still keeping the overall number of drawings under control), but the big hurdle for this idea has been cleared. The next major effort will be creating an ACSIL trade system so that I can back-test my criteria properly. I've done a lot of this via the awesome SC Spreadsheet System/Alert for Trading; now I get to throw some ACSIL at it :)

In addition to your insight about de-referencing a NULL pointer, @ondafringe, the following posts and docs were crucial (you already know all this, @ondafringe, I list this for future users who attempt something similar:
ACSIL Programming Concepts: Allocating Memory for Classes
Using Drawing Tools From an Advanced Custom Study: sc.DeleteACSChartDrawing()
Date Time Of Last Edit: 2025-02-22 15:09:44
imageChart settings for 1k Volume.png / V - Attached On 2025-02-22 15:09:25 UTC - Size: 62.99 KB - 21 views
image2025-02-21_GIF of Trading Signal ACS drawings.gif / V - Attached On 2025-02-22 15:09:32 UTC - Size: 9.6 MB - 20 views
[2025-02-22 17:07:38]
ondafringe - Posts: 322
Okay, I just posted it!

I am providing the link just in case someone stumbles across this thread in the future.
How to Use Visual Studio 2022 Community to Develop Custom Studies for Sierra Chart

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account