Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 11:02:09 +0000



[Programming Help] - ACSIL: Optimization of calculations and drawings

View Count: 1228

[2019-09-13 07:50:46]
BrMa - Posts: 77
Dear ladies and gentlemen,

I worked through the documentation and also tried already a lot of different approaches to resolve it but I'm stuck on the following issue:

My study needs two additional charts (same instrument but different periods and maximum history) to the one it is assigned to. For doing this I'm using the function
sc.OpenChartOrGetChartReference()
and as I'm using the manual looping-approach I also made sure I only call the function once during full-recalculation on
sc.UpdateStartIndex == 0
. In addition I'm setting the parameter
HideNewChart = 1
to avoid time consuming drawing-operations.

Debugging shows the recalculation of the study takes place three times (obviously the referenced charts tag if for recalculation and one time the recalculation takes place because of its own loading). However - as there is a lot of processing to do and many drawings to be made, the study turns out to be pretty slow.

Topic 1: Calculations

First of all, I'd like to achieve that calculations are only done once and not three times during the initial loading of the chart. To achieve this I already tried to detect "unnecessary" processing by using the functions
sc.ChartIsDownloadingHistoricalData()
and
sc.IsChartDataLoadingInChartbook()
. The idea behind: as long as data is loaded in the chartbook, there is no processing necessary as the main chart will be tagged for re-calculaton anyhow. Unfortunatelly this does not work because
sc.ChartIsDownloadingHistoricalData()
seems to return false if data is cached or downloaded already and seems not to be useful to determine if the main-chart will be tagged for a redraw.
sc.IsChartDataLoadingInChartbook()
seems also to be true if the main-chart is not downloading data anymore but processing the study - waiting for this to be false leads to the outcome, that no processing is done.

So my question: how can I check that:
1) all necessary data is loaded
2) referenced charts are processed and do not tag any redraws to the main chart for the process of opening anymore
3) and it is the "last" processing of the data out of the initial loading - so the "last" full recalculation

Topic 2: Drawings

Drawings seem to be very time-consuming in the processing of studies (if I'm doing the processings only without drawings during the opening of a chart, time-savings are up to 60% - during "ongoing" calculations on chart-updates it's up to 100%). And - of course - I'm "remembering" drawing-IDs and re-using them to make sure there are no multiple-drawings of the same item. This is especially critical during the ongoing updating of charts as the workload on the core used easily comes to its maximum although there are no calculations done in the study.
(Amendment: I also checked the beta-functionailty of OpenGL already, but my GPU goes up to 100% and stays there leaving the system in a stalled state. So, this is not an option for me for the time being.)

I tried to work around this issue by only drawing "visible marks" using
sc.IndexOfFirstVisibleBar and sc.IndexOfLastVisibleBar
but when doing historical analysis offline those are not updated and therefore "redraws" need to be forced by re-applying the settings to the study.

My question: is there a way to speed up drawing or to get the "visible" area in ACSIL if the chart is not triggered by an update but by scrolling the chart?

Thanks a lot for your suggestions on this in advance!
[2019-09-26 14:32:01]
BrMa - Posts: 77
Dear ladies and gentlemen,

I started this thread close to two weeks ago but there is no response up to now... could you please provide me with a short status?
Thanks a lot in advance!

Regards, Markus
[2019-09-26 15:30:37]
User907968 - Posts: 802
I tried to work around this issue by only drawing "visible marks" using

sc.IndexOfFirstVisibleBar and sc.IndexOfLastVisibleBar

but when doing historical analysis offline those are not updated and therefore "redraws" need to be forced by re-applying the settings to the study.

Did you read the information related to "sc.IndexOfFirstVisibleBar" -
ACSIL Interface Members - Variables and Arrays: sc.IndexOfFirstVisibleBar

Also this "sc.UpdateAlways" in relation to above -
ACSIL Interface Members - Variables and Arrays: sc.UpdateAlways
[2019-09-26 16:32:24]
BrMa - Posts: 77
Thank you for the reply. Yes I read the documentation - also on sc.UpdateAlways - the issue is, that my calculations are pretty time-consuming and I want to have them executed "as often as needed" ONLY. Using sc.UpdateAlways would even increase the load on the CPU. That's why I asked if there is a kind of event how I could determine the scrolling of the chart.

However - Topic 1: Calculations - is much more critical as it is about avoiding "unnecessary" calculations...
[2019-09-26 16:35:49]
binaryduke - Posts: 360
You could take a hybrid approach. Use sc.UpdateAlways. Store the index of the first and last visible bars in persistent variables. Only perform your time consuming calculations if you find that these have changed.
[2019-09-26 16:43:22]
BrMa - Posts: 77
@binaryduke: sounds like a valid approach! Thank you! :-)
Does anybody have an idea for "Topic 1: Calculations"?
[2019-09-26 16:49:02]
binaryduke - Posts: 360
Similar approach (assuming you don't have a gazillion outputs). Think about caching your calculation results into persistent variables or allocated dynamic memory; think about holding sc.ArraySize in a persistent variable and only calculating when there is a change to this; think about using manual rather than automatic looping.

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

Login

Login Page - Create Account