Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 16:47:50 +0000



[User Discussion] - ACSIL: finding first bar for the trading day

View Count: 2510

[2014-02-23 02:11:45]
dominikos - Posts: 106
Is there an easy way to find out the value of first bar of referenced study from graph for the day? In my study, I have a reference to moving average and would like to find out what was the opening value for a given day.

Thanks
[2014-02-23 09:54:00]
Sierra Chart Engineering - Posts: 104368
This will determine the index that you need to use into the array for the referenced study Subgraph:

  // Bar index of beginning of trading day for bar at current index. This depends upon auto looping being true.
  SCDateTime DayStartDateTime =sc.GetTradingDayStartDateTimeOfBar(sc.BaseDateTimeIn[sc.Index]);
  int StartOfDayIndex= sc.GetContainingIndexForSCDateTime(sc.ChartNumber, DayStartDateTime);

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: 2014-02-23 09:54:43
[2015-04-30 09:54:14]
corbeste - Posts: 74
I have a follow up question - in some cases the first bar of the chart is not at the intraday start time - for example a thinly traded stock that starts trading a couple minutes after the open. How am I able to reference this bar?

I'm attempting to code a "HH/LL over N bars from open" indicator so I need the opening print. Right now the above code will use the closing bar from the prior day if there is no trade in the first couple minutes, which can throw off the calculation on gaps.
[2015-04-30 15:00:39]
jackw - Posts: 57
This will also work, and it relies on the date instead of the time to find the first bar of the day.

int FirstBarOfDay = sc.ArraySize - 1;
while (DATE_PART(sc.BaseDateTimeIn[FirstBarOfDay]) == DATE_PART(sc.BaseDateTimeIn[FirstBarOfDay - 1])) FirstBarOfDay --;

[2015-09-19 14:01:03]
User44052 - Posts: 34
Thank you, Jackw - your code works just fine.

The code provided by Sierra Chart Engineering gives different results if I use a tick chart (number of trades per bar). It will only give correct Daily Open if the chart is set to minute intervals.
[2015-10-11 13:46:48]
User44052 - Posts: 34
Just an update, the code proposed by Jack seems to go into an infinite loop if you attempt an auto-replay backtest (even without any orders). Here's the code that crashes Sierra - I have no idea why.

SCSFExport scsf_findFirstBar(SCStudyInterfaceRef sc)
{
  // Section 1 - Set the configuration variables and defaults
  if (sc.SetDefaults)
  {
    sc.GraphName = "First Bar";
    
    sc.FreeDLL = 1;
    sc.AutoLoop = 1; //Auto looping is enabled.
    sc.GraphRegion = 0;
    
    sc.Subgraph[0].Name = "Dummy Line Replicates Close";
    sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
    sc.Subgraph[0].PrimaryColor = RGB (0, 0, 255);
    
    return;
  }
  
  
  // Section 2 - Do data processing here
  int FirstBarOfDay = sc.ArraySize - 1;
  while (DATE_PART(sc.BaseDateTimeIn[FirstBarOfDay]) == DATE_PART(sc.BaseDateTimeIn[FirstBarOfDay - 1])) FirstBarOfDay --;

  sc.Subgraph[0][sc.Index] = sc.Close[sc.Index];
  
}

[2015-10-11 14:27:30]
ejtrader - Posts: 688
You can try this one..

while (DATE_PART(sc.BaseDateTimeIn[FirstBarOfDay]) == DATE_PART(sc.BaseDateTimeIn[FirstBarOfDay - 1]) && FirstBarOfDay > 0) FirstBarOfDay --;

[2015-10-11 18:59:46]
User44052 - Posts: 34
Brilliant, ejtrader. Now it works!
Thanks.

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

Login

Login Page - Create Account