Support Board
Date/Time: Mon, 24 Feb 2025 21:53:30 +0000
Study function keeps getting called even when the new bar is not added to chart
View Count: 1067
[2021-03-23 19:35:17] |
User741184 - Posts: 44 |
Hi, My chart's Bar Period Type is set to Volume Per Bar(setting 7500). And in my code I am printing sc.Index to Sierra Chart's log and also to the file to see how many bars are there in the chart. Also the automatic looping has been set. Here is the code snippet. SCString MessageText; sc.AddMessageToLog(sc.Index, 0); // Create and open a text file std::ofstream MyFile("filename.txt", std::ios::app); // Write to the file MyFile << sc.Index << std::endl; // Close the file MyFile.close(); Now as per the documentation, When your study function uses automatic looping, then it is automaticaly called once for every bar or column in the chart when the study is initially calculated. If there are 100 bars in the chart, then it will be called 100 times when your study is initially calculated. After that, the study function is called as the latest bar is updated and new bars are added. But the problem is, after printing 100 times the study gets called every few milliseconds as I can see the log message being printed every few milliseconds. The file also keeps updating at the same rate. The new bar is not available after few milliseconds then why the study function is being called again and again? |
[2021-03-23 19:42:41] |
John - SC Support - Posts: 38146 |
The study function is called with each update of the chart. This is controlled by the Chart Update Interval. Refer to the following: Working with ACSIL Arrays and Understanding Looping: Update Study Function Calls For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2021-03-23 20:54:26] |
User741184 - Posts: 44 |
The Chart Update Interval is set to 500 milliseconds. And the documentation says, The call into the study function will just be an update call with sc.Index/sc.UpdateStartIndex set to the prior array size. The following are the conditions for when this call happens. There is new trade market data received Historical downloaded data received Bid and ask data received Market depth data received Fundamental data received New orders or order updates for the symbol and trade account the chart is set to. Trade Position updates for the symbol and trade account the chart is set to. When records are read from the chart data file during a Replay of an Intraday chart When using sc.UpdateAlways = 1 The Trade >> Trade Simulation Mode On state has been changed. What if none of the conditions above is true and after 500 ms, would the study function be called? Is that a must condition that since the Update Interval is set to 500 ms so study function should be called after every 500 ms regardless of the fact that no new trade market data is available after 500 ms? |
[2021-03-23 21:52:30] |
John - SC Support - Posts: 38146 |
If there is no new market data and none of the other situations apply, then the study is NOT called.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2021-03-24 19:17:28] |
User741184 - Posts: 44 |
In such case, sc.Index will remain the same until the new bar is added to chart but the study function will keep getting called because of Chart Update Interval then how will we know in code that the new bar is added or the sc.Index has been updated?
|
[2021-03-24 19:34:27] |
User741184 - Posts: 44 |
How can I make that my study function is only called when new bar is added to chart and not gets called on every Chart Update? Since the Chart Update Interval is set to 500 milliseconds which makes the study function gets called too frequently. And I want the custom study to be called ONLY in case of new chart bar. How is that possible? |
[2021-03-24 20:23:59] |
John - SC Support - Posts: 38146 |
Refer to the following: ACSIL Programming Concepts: One Time Processing per Bar in the Chart For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2021-03-24 22:55:28] |
User741184 - Posts: 44 |
How to get the current/last bar always in every study function call? Even for the first time when for example there are 100 bars and sc.Index = 0, how to get the current/last bar in that scenario?
|
[2021-03-25 14:49:23] |
John - SC Support - Posts: 38146 |
You can know the last bar by comparing against the size of the array (minus 1, since it is a zero based array). This would be the sc.ArraySize variable. Refer to the following: ACSIL Interface Members - Variables and Arrays: sc.ArraySize For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: