Support Board
Date/Time: Sun, 22 Dec 2024 10:27:50 +0000
ACSIL Accessing Data from Multiple Charts - Do you have to use Autoloop = 0?
View Count: 3681
[2015-08-08 03:15:36] |
Jayturn - Posts: 15 |
Trading based on multiple timeframes is imperative to my strategies that I have programmed in NinjaTrader and I want to make a permanent shift to Sierra Charts. I'm comfortable programming in C++ but figuring out the best way to access the base chart data and attach studies to those from another study is proving a struggle. I am getting conflicting understandings between the documentation and example code in the ACS_Source files. It is my understanding that the entire study is looped for every Chart Interval Update. Therefore any request to sc.OpenChartOrGetChartReference() would happen on every interval, including setting the s_ACSOpenChartParameters to be used for opening a chart as part of the study. Code for scsf_Sum in studies7.cpp suggests you shouldn't frequently call sc.GetChartBaseData (which makes perfect sense). However if I step through the code (during replay) with Autoloop set to 0, the entire study gets run again on every Chart Interval Update. So I have two questions: 1) If using multiple timeframes, does sc.GetChartBaseData have to be invoked on every Chart Interval Update? 2) Autoloop = 0 only prevents calling the study multiple times when loading the chart for the first time and in fact calls the study on each Chat Interval update for live trading? Any help on this understanding would be greatly appreciated. |
[2015-08-08 06:59:03] |
Sierra Chart Engineering - Posts: 104368 |
Do you have to use Autoloop = 0? No.It is my understanding that the entire study is looped for every Chart Interval Update. This is not correct. Where did you come to this understanding in order for us to clarify this?Therefore any request to sc.OpenChartOrGetChartReference() would happen on every interval, including setting the s_ACSOpenChartParameters to be used for opening a chart as part of the study.
This is true, but this is very efficient. However, you can simply avoid this by only doing this when sc.IsFullRecalculation is nonzero. We will add this to the documentation.1. Yes, but this is very efficient. The key is not to do that at every bar, but only at every chart update. 2. This is sort of true. Using manual looping means that the study function is not called for each bar in the chart which only happens at a full recalculation which happens under various conditions. Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2015-08-08 23:25:28] |
Sierra Chart Engineering - Posts: 104368 |
Here is an updated code example: SCSFExport scsf_OpenChartOrGetChartReferenceExample(SCStudyInterfaceRef sc) { SCSubgraphRef Output = sc.Subgraph[0]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "OpenChartOrGetChartReference Example"; sc.StudyDescription = "This study demonstrates using the OpenChartOrGetChartReference function. This study does not calculate anything."; sc.AutoLoop = 0;//Manual looping // During development set this flag to 1, so the DLL can be modified. When development is done, set it to 0 to improve performance. sc.FreeDLL = 0; Output.Name = "Output"; Output.DrawStyle = DRAWSTYLE_LINE; Output.PrimaryColor = RGB(0,255,0); return; } // Do data processing // Remember the chart number in a persistent variable to make the chart // lookup more efficient. int& ChartNumber = sc.GetPersistentInt(1); //Only do this on a full recalculation. Could also use sc.UpdateStartIndex == 0 in the case of manual looping which we are using. if ( sc.IsFullRecalculation) { s_ACSOpenChartParameters OpenChartParameters; OpenChartParameters.PriorChartNumber = ChartNumber; OpenChartParameters.ChartDataType = INTRADAY_DATA; //This can also be set to: DAILY_DATA OpenChartParameters.Symbol = sc.GetRealTimeSymbol();//When want to use the symbol of the chart the study function is on, use sc.GetRealTimeSymbol() OpenChartParameters.IntradayBarPeriodType = IBPT_DAYS_MINS_SECS; OpenChartParameters.IntradayBarPeriodLength = 30*SECONDS_PER_MINUTE; // 30 minutes OpenChartParameters.DaysToLoad = 0;//same as calling chart // These are optional OpenChartParameters.SessionStartTime.SetTimeHMS(12, 0, 0); OpenChartParameters.SessionEndTime.SetTimeHMS(23,59,59); //OpenChartParameters.EveningSessionStartTime.SetTimeHMS(0,0,0); //OpenChartParameters.EveningSessionEndTime.SetTimeHMS(23,59,59); ChartNumber = sc.OpenChartOrGetChartReference(OpenChartParameters); } if (ChartNumber != 0) { SCGraphData ReferenceChartData; // Get the arrays from the reference chart sc.GetChartBaseData(ChartNumber, ReferenceChartData); if (ReferenceChartData[SC_LAST].GetArraySize() == 0) return; // The array is empty // Copy the reference chart array Last values to Subgraph 0. // Most likely the array from the reference chart is not // the same size as the array this study function is applied to. // Therefore, there is not going to be a correct column to column // correspondence. However, this is just a simple example. Output[sc.Index] = ReferenceChartData[SC_LAST][sc.Index]; } //This is an example of opening a Historical Chart with a Weekly bar period int& WeeklyChartNumber = sc.GetPersistentInt(2); if ( sc.IsFullRecalculation) { OpenChartParameters.Reset(); OpenChartParameters.PriorChartNumber = WeeklyChartNumber; OpenChartParameters.ChartDataType = DAILY_DATA; OpenChartParameters.HistoricalChartBarPeriod = HISTORICAL_CHART_PERIOD_WEEKLY; OpenChartParameters.Symbol = sc.GetRealTimeSymbol(); OpenChartParameters.DaysToLoad = 0; WeeklyChartNumber = sc.OpenChartOrGetChartReference(OpenChartParameters); } } Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2015-08-09 03:53:14] |
Jayturn - Posts: 15 |
Thank you for the fast and thorough response. It is clear the Sierra Team care about the needs of their customers. The example using sc.IsFullRecalculation is greatly appreciated and will serve as a good replacement for the persistent variable I was using as my workaround. I came to the understanding the entire study is looped for every chart interval based on the following: In the ArraysAndLooping documentation it's states the following for the "When the study function is called" In the case of manual looping, it will be called 1 time, but may be called a subsequent time when the chart is updated which normally is less than a second later. After the first chart update, the study function will not be called again, unless it is for one of the conditions explained in the next paragraph. After the initial calculation of the study, the study function is called when there is new trade data received, downloaded data received, bid and ask data received, market depth data received, new orders or order updates for the symbol, trade Position updates for the symbol, when records are read from the chart data file during a Replay of an Intraday chart, or when using sc.UpdateAlways = 1. I ran the Visual Studio debugger to see how this worked and found that when sc.Autoloop = 0, the study wouldn't loop through every bar on the chart after it was recalculated. sc.UpdateStartIndex would begin at the latest bar and a "for loop" on the sc.UpdateStartIndex is necessary to access the bars prior to the current index. If you run the replay however, after the initial load which runs the study function once, each trigger of the Chart Interval Update causes the study function to be called. Based on that, I came to the conclusion that a study function is called on each Chart Interval Update (after the initial loading of the study), regardless of the manual or auto loop setting. Is it possible that I am missing a finer detail to this, maybe autoloop calls the study function once for every event (new trade data received, downloaded data received, bid and ask data received, market depth data received... etc) included in Chart Interval Update whereas manual looping groups the events together and only calls the study function once for the group of events? Date Time Of Last Edit: 2015-08-09 03:53:38
|
[2015-08-11 10:05:21] |
Sierra Chart Engineering - Posts: 104368 |
The documentation has been clarified here: https://www.sierrachart.com/index.php?page=doc/doc_ACS_ArraysAndLooping.html#WhenFunctionCalled Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2015-08-11 21:04:04] |
Jayturn - Posts: 15 |
Thank you for clarifying the functions calls. It's much clearer to me now. Greatly appreciate the support your team offers.
|
To post a message in this thread, you need to log in with your Sierra Chart account: