Login Page - Create Account

Support Board


Date/Time: Wed, 24 Apr 2024 14:01:21 +0000



[User Discussion] - Drawing line at all time high - performance issue

View Count: 4002

[2013-04-06 13:44:41]
T44 - Posts: 363
I am working with multiple instruments using intraday interval bar charts. I would like each intraday chart to reference a historical daily chart and calculate the all time high (and low).

My study is as follows:

//Get the symbol
const char* p_Symbol;
p_Symbol = sc.Symbol.GetChars();

//Get the chart reference of the daily chart for p_Symbol
  // Remember the chart number in a persistent variable to make the chart
  // lookup more efficient.
  int& ChartNumber = sc.PersistVars->i1;
  
  s_ACSOpenChartParameters OpenChartParameters;
  OpenChartParameters.PriorChartNumber = ChartNumber;
  OpenChartParameters.ChartDataType = DAILY_DATA;
  OpenChartParameters.Symbol = p_Symbol;
  OpenChartParameters.DaysToLoad = 4380;
  
  ChartNumber = sc.OpenChartOrGetChartReference(OpenChartParameters);
  
    if (ChartNumber != 0)
  {
    SCGraphData ReferenceChartData;
    
    // Get the arrays from the reference chart
    sc.GetChartBaseData(ChartNumber, ReferenceChartData);
    if (ReferenceChartData[SC_LOW].GetArraySize() == 0)
      return; // The array is empty
    

//Get the array size
int ArraySize = ReferenceChartData[SC_HIGH].GetArraySize();


/* Get the all time high
--------------------------*/
float ATH = 0;

for (int j = 0; j < ArraySize; j++)
{
if (ReferenceChartData[SC_HIGH][j] > ATH)
ATH=ReferenceChartData[SC_HIGH][j];
}

/* Get the all time low
--------------------------*/
float ATL = 99999; //some arbitrary large number dirty hack

for (int j = 0; j < ArraySize; j++)
{
if (ReferenceChartData[SC_LOW][j] < ATL)
ATL=ReferenceChartData[SC_LOW][j];
}

....


sc.Input[0].SetFloat(ATH);
sc.Input[1].SetFloat(ATL);


for (int k = 0; k < 2 ; k++) {
if (sc.Index == 0) {
sc.Subgraph[k][Index] = sc.Input[k].GetFloat();


Autolooping is off and I have a manual loop which only iterates through the sc.Input and sc.Subgraph in order to draw the horizontal line the whole way across the chart.

The issue I am running into is that it seems incredibly inefficient to have 5 intraday interval bar charts running a study which references the daily historical chart and iterates through 4,000 odd bars to find the all time high and low. I am receiving errors.
Warning the Custom DLL Study has just caused a CPU exception. Warning: This Custom DLL study may cause Sierra Chart to be unstable until you remove the study from your chart and restart Sierra Chart.

In addition, the chart windows are redrawing a lot slower than I would expect for a Q6600 CPU, which means I've done something terribly inefficient in the code. Help with this would be appreciated: what is the best way to get a horizontal line on an intraday chart positioned at the all time high for that symbol (in such a way as I can repeat for 52 week high etc).


Perhaps the better question would be how can I separate the piece of code which needs to run at most once per trading day (to get the highs and lows from the last 12 years on a daily historical chart) with the piece of code which needs to plot the lines. Could I store these values in a flat file or similar so that the values did not need to be wastefully recalculated every 'chart update interval'?
Date Time Of Last Edit: 2013-04-06 13:52:59
[2013-04-06 21:09:23]
Sierra Chart Engineering - Posts: 104368
We need the full source code to test what is causing the exception.

What we recommend you do is open a Historical Daily chart and add the Highest High/Lowest Low over N Bars. And then overlay that on to your Intraday chart by using the Study/Price Overlay study. You can then easily reference of the result in your study by using this method:
http://www.sierrachart.com/index.php?l=doc/doc_ACSILRefOtherTimeFrames.php#OverlayStudy
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
Date Time Of Last Edit: 2013-04-06 21:10:00
[2013-04-06 21:33:19]
Sierra Chart Engineering - Posts: 104368
Another thought is that in your manual loop study function is to check sc.UpdateStartIndex == 0 and only in this case check for the High and Low for efficiency. This is how we would do it.
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
[2013-04-07 10:42:05]
Sierra Chart Engineering - Posts: 104368
This problem will be resolved in the next release. However, for now please put a "return" at the end of the sc.SetDefaults code block. That is important.
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
[2013-04-07 11:10:31]
T44 - Posts: 363
Thank you. I have added the return and am no longer receiving the CPU exception.
My study now works but is very slow on the chartbook I am running with several dozens of charts.
If you have time, I would appreciate any further suggestions on how I could improve the performance.

My feeling is that the 12 levels I calculate based on the 4320 bar historical daily chart need only be calculated once at the time of opening the chartbook, stored either in memory or a flat file, and directly referenced by all the intraday charts I load. This would seem to be the most efficient way.
However, I do not know how to achieve this - specifically how to make a section of code in a study run only once, and how to store these level values and reference them from another study. Persistent variables appear to have their own instance per study.

I had thought of using your excellent feature of "copy chart drawings from chart #" to copy the lines, but lines drawn by study do not appear to be considered "drawings". Knowing what I am trying to achieve, any suggestions would be most welcome. Thanks again for your prompt replies and assistance.
[2013-04-07 11:15:01]
T44 - Posts: 363
I forgot to add, a function which returns the intraday bar period of the chart the study is running on would be most useful - I've checked the documentation and this does not seem to exist. A function which would return "10" on a 10 minute chart for example. Perhaps you would consider adding this as a feature in the future? I see there are already functions to tell if a study is running on a time based or volume based chart. This would allow a study to behave differently according to which timeframe was in use, which some may find useful.
[2013-04-07 20:22:28]
Sierra Chart Engineering - Posts: 104368
The standard way to do calculations only one time within a study is to check sc.UpdateStartIndex == 0 and only do the calculations when this is true. In this case, they will only be done when necessary. This is how we do it.

To know the timeframe per bar in an Intraday chart use sc.SecondsPerBar.
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

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

Login

Login Page - Create Account