Login Page - Create Account

Support Board


Date/Time: Sun, 22 Dec 2024 10:14:32 +0000



ACSIL How to get the time for a bar index in a second Chart?

View Count: 3531

[2015-08-13 10:32:07]
Jayturn - Posts: 15
Can someone please point me to some documentation regarding how to access the DateTime at a bar index that is from a second chart? This is an example of what I need to do:


// Define the subgraphs we will be working with.
SCGraphData secondGraph;

// Get the base data for the second chart.
sc.GetChartBaseData(2, secondGraph);

// Define the first and last bars of the session for the second chart.
secondGraphEndBar = sc.GetNearestMatchForDateTimeIndex(2, sc.Index - 1);
secondGraphStartBar = sc.GetNearestMatchForSCDateTime(2, secondGraphEndBar);

// Loop through the bars.
for (int Index = secondGraphStartBar; Index <= secondGraphEndBar; Index++)
{
  // Get the time at the current index for the second chart?
  SCDateTime currIndexTime = ???
}

I know how to convert an index/DateTime from the main graph to an index in a different chart but I'm not sure how to reverse the procedure.
[2015-08-13 10:40:32]
Sierra Chart Engineering - Posts: 104368
You need to use this function to get the Date-Time array from another chart:
sc.GetChartDateTimeArray
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-13 10:47:44]
Sierra Chart Engineering - Posts: 104368
Also, this does not make sense:
secondGraphStartBar = sc.GetNearestMatchForSCDateTime(2, secondGraphEndBar);


The second parameter this function requires is always going to be a SCDateTime value. Not an index value.
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-13 11:27:45]
Jayturn - Posts: 15
Thank you very much for the assistance Sierra Team, you rock!

The secondGraphEndBar is a SCDateTime value, it's derived from sc.GetNearestMatchForDateTimeIndex(2, sc.Index - 1). That is how I am getting the previous day's date, if there is a better way you know of to get the previous day's date with sc.Index being the first bar of the current day's session and sc.Index being the last bar of the previous day's session, I'm definitely open to learning how my current logic can be optimized.

[Updated]
Apologies, you are correct about the code not making sense, I copy and pasted to simplify and in the process messed it up. I am using this logic to get the current day and previous day from the sc.Index:


// Get the the previous day's trading date.
SCDateTime prevDaySessionEnd = sc.GetTradingDayDate(sc.BaseDateTimeIn[sc.Index - 1]);
// Get the open time for the prev day.
SCDateTime prevDaySessionStart = sc.GetTradingDayStartDateTimeOfBar(prevDaySessionEnd);

// Define the subgraphs we will be working with.
SCGraphData secondGraph;

// Get the base data for the second chart.
sc.GetChartBaseData(2, secondGraph);

// Define the first and last bars of the session for the second chart.
secondGraphEndBar = sc.GetNearestMatchForDateTimeIndex(2, sc.Index - 1);
secondGraphStartBar = sc.GetNearestMatchForSCDateTime(2, prevDaySessionStart);

// Loop through the bars.
for (int Index = secondGraphStartBar; Index <= secondGraphEndBar; Index++)
{
// Get the time at the current index for the second chart?
SCDateTime currIndexTime = ???
}


Date Time Of Last Edit: 2015-08-13 11:45:47

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

Login

Login Page - Create Account