Support Board
Date/Time: Sun, 24 Nov 2024 06:41:58 +0000
Post From: Drawing line at all time high - performance issue
[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
|