Login Page - Create Account

Support Board


Date/Time: Thu, 26 Jun 2025 22:14:23 +0000



[Programming Help] - CPU exception

View Count: 1263

[2021-09-19 02:39:50]
Tony - Posts: 595
Hi,

One of the study I wrote sometimes causes a CPU exception, I
understand it should be my responsibility to find the issue,
but I think it has some uniqueness, and just in case there
might be a simple solution that I am not aware of...

The CPU exception never happens when all the candle bars fit
the width of the chart window (when there is no "dragging box"
within scroll bar);

When loaded candle bars don't fit the width of chart window, the
CPU exception only happens twice, milliseconds apart, right after
the study is reloaded (first time open a chartbook, or "Reload and
Recalculate" is selected under Edit menu, or rewind during replay),
after that, it never occurs again, either during live data feed or
replay.


Thanks,
[2021-09-19 14:46:41]
ForgivingComputers.com - Posts: 1071
Try putting in a return statement in the code near the top, starting in the sc.SetDefaults block and test it. If no CPU exception occurs, then keep moving the return down until you get the CPU exception. That should help narrow down when it is happening. If you have experience with the Visual Studio debugger, then attach to the Sierra process before adding the study, or opening the chartbook. You will often get more information about the CPU exception, like a divide by zero or array out of bounds condition.

Another thing you can try is to comment out blocks of code and then test.
[2021-10-30 06:11:55]
Tony - Posts: 595
Hi bradh,

I finally had time to do some investigation, thanks for the tips and tricks,
they worked great!

It turned out that the issue is related to s_BarPeriod::IntradayChartBarPeriodParameter1,
I used it as denominator in my coding, after I changed the code from:
BarPeriod.IntradayChartBarPeriodParameter1 to max(BarPeriod.IntradayChartBarPeriodParameter1, 1),
I don't get CPU exception message anymore. Not sure why it happened, because I never set bar
period to 0-0-0, there are always some numbers.

Thanks again,
Date Time Of Last Edit: 2021-10-30 06:13:27
[2021-10-30 11:13:24]
ForgivingComputers.com - Posts: 1071
Glad you figured it out. Isn't debugging fun? Divide by zero and array out of bounds conditions have created my most common CPU exceptions.

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

Login

Login Page - Create Account