Support Board
Date/Time: Thu, 06 Feb 2025 01:43:59 +0000
Post From: Continuous Contract and ReadIntradayFileRecordForBarIndexAndSubIndex
[2020-04-07 11:01:04] |
User79074 - Posts: 105 |
I managed to get the ticks in a bar including continuous contracts by doing the following, posting for other people to see. Showing getting the volume of the candle by reading the ticks in the bar using function sc.GetNearestMatchForDateTimeIndex #include "sierrachart.h" SCDLLName("EmulatedData") #define RealVolume sc.Subgraph[0] #define EmulVolume sc.Subgraph[1] int openOneTickChart(SCStudyGraphRef sc) { // 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; OpenChartParameters.Symbol = sc.GetRealTimeSymbol(); OpenChartParameters.IntradayBarPeriodType = IBPT_NUM_TRADES_PER_BAR; OpenChartParameters.IntradayBarPeriodLength = 1; OpenChartParameters.ContinuousFuturesContractOption = CFCO_DATE_RULE_ROLLOVER; OpenChartParameters.DaysToLoad = 0;//same as calling chart ChartNumber = sc.OpenChartOrGetChartReference(OpenChartParameters); } return ChartNumber; } // Gets ticks inside bar at index x void getTicksAtIndex(SCStudyGraphRef sc, int x, int & firstTick, int & lastTick, SCGraphData & OneTickData) { int oneTickChartNumber = openOneTickChart(sc); sc.GetChartBaseData(oneTickChartNumber, OneTickData); firstTick = sc.GetNearestMatchForDateTimeIndex(oneTickChartNumber, x); // If last bar on main chart if (x == sc.ArraySize-1) lastTick = OneTickData[0].GetArraySize()-1; else lastTick = sc.GetNearestMatchForDateTimeIndex(oneTickChartNumber, x+1) - 1; } void getEmulatedVolume(SCStudyGraphRef sc, int x) { int firstTick; int lastTick; SCGraphData OneTickData; getTicksAtIndex(sc, x, firstTick, lastTick, OneTickData); EmulVolume[x] = 0; for (int i = firstTick; i <= lastTick; i++) EmulVolume[x] += OneTickData[SC_VOLUME][i]; RealVolume[x] = sc.Volume[x]; } void calcEmulatedData(SCStudyGraphRef sc) { for (int i = 0; i < sc.ArraySize; i++) getEmulatedVolume(sc, i); } SCSFExport scsf_Emulated_Volume_With_GetNearestMatchForDateTimeIndex(SCStudyGraphRef sc) { if (sc.SetDefaults) { sc.AutoLoop = 0; sc.GraphName = "Emulated Data"; RealVolume.Name = "Real Volume"; RealVolume.DrawStyle = DRAWSTYLE_DASH; RealVolume.PrimaryColor = RGB(0,0,0); EmulVolume.Name = "Emul Volume"; EmulVolume.DrawStyle = DRAWSTYLE_POINT; EmulVolume.PrimaryColor = RGB(0,0,0); return; } calcEmulatedData(sc); } |