Login Page - Create Account

Support Board


Date/Time: Fri, 12 Dec 2025 09:43:37 +0000



Post From: how to calculate and plot over arrays on different timeframes in ACSIL?

[2025-12-12 06:10:55]
User463324 - Posts: 1
Hi,

I have a base chart on 15 seconds timeframe, and I'm adding a custom study/indicator that calculates certain metrics over 1 min timeframe and plots them on my 15 second chart. My study adds automatically 1 min subchart using and OpenChartOrGetChartReference and I try to use subarrays using GetStudyExtraArrayFromChartUsingID for my custom calculations but indexing and aggregations over these sub arrays are not working right (summations are not valid and overall looping over these subarrays is returning strange results). source is below. What am I doing wrong?


SCSFExport scsf_SimulationBackgroundColor(SCStudyInterfaceRef sc)
{
SCSubgraphRef testSubgraph = sc.Subgraph[0];

SCInputRef Input_Length = sc.Input[0];

if (sc.SetDefaults)
{
sc.GraphName = "MyTest";
sc.StudyDescription = "MyTest";

Input_Length.Name = "Test Length";
Input_Length.SetInt(100);

sc.DisplayStudyInputValues = false;
sc.AutoLoop = true;
sc.DrawStudyUnderneathMainPriceGraph = 1;
}

const int P_ONE_MIN_CHART = 1;

int& oneMinChartNumber = sc.GetPersistentInt(P_ONE_MIN_CHART);
if (sc.IsFullRecalculation || sc.Index == 0)
{
s_ACSOpenChartParameters oneMinParams;
oneMinParams.PriorChartNumber = oneMinChartNumber;
oneMinParams.DaysToLoad = 0;
oneMinParams.ChartDataType = INTRADAY_DATA;
oneMinParams.Symbol = sc.GetRealTimeSymbol();
oneMinParams.IntradayBarPeriodType = IBPT_DAYS_MINS_SECS;
oneMinParams.IntradayBarPeriodLength = 1 * SECONDS_PER_MINUTE;
oneMinParams.HideNewChart = true;
oneMinParams.LoadWeekendData = true;
oneMinParams.UseEveningSession = true;
oneMinParams.UpdatePriorChartNumberParametersToMatch = true;
oneMinChartNumber = sc.OpenChartOrGetChartReference(oneMinParams);
sc.SetPersistentInt(P_ONE_MIN_CHART, oneMinChartNumber);
}

if (oneMinChartNumber != 0)
{
SCDateTimeArray oneMinDateTimes;
sc.GetChartDateTimeArray(oneMinChartNumber, oneMinDateTimes);

SCGraphData oneMinData;
sc.GetChartBaseData(oneMinChartNumber, oneMinData);
int dataIndex = oneMinDateTimes.GetArraySize() - 1;

SCFloatArray tpv;
sc.GetStudyExtraArrayFromChartUsingID(oneMinChartNumber, Input_Length.GetStudyID(), 0, 0, tpv);
SCFloatArray tpvSum;
sc.GetStudyExtraArrayFromChartUsingID(oneMinChartNumber, Input_Length.GetStudyID(), 0, 1, tpvSum);

float atp = (oneMinData[SC_LAST][dataIndex] + oneMinData[SC_HIGH][dataIndex] + oneMinData[SC_LOW][dataIndex]) / 3;
float tpvVal = atp * oneMinData[SC_VOLUME][dataIndex];
tpv[dataIndex] = tpvVal;
sc.Summation(tpv, tpvSum, Input_Length.GetInt());
SCString FormattedMessage;
sc.AddMessageToLog(FormattedMessage.Format("sc.index=%i dataIndex=%i oneMinDataLen=%i tpvLen=%i", sc.Index, dataIndex, oneMinData.GetArraySize(), tpv.GetArraySize()), 0);
testSubgraph[sc.Index] = tpvSum[dataIndex];
}
}