Login Page - Create Account

Support Board


Date/Time: Sun, 28 Apr 2024 23:09:27 +0000



[Programming Help] - Continuous Contract and ReadIntradayFileRecordForBarIndexAndSubIndex

View Count: 626

[2020-04-06 13:17:09]
User79074 - Posts: 105
I am using ReadIntradayFileRecordForBarIndexAndSubIndex, and it begins to fail I have noticed when it tries to grab previous data from Continuous Contract. For example, it works the first 23 days on a 1 minute chart, then begins to fail on the 24th day, which is when it switches over to continuous contract and ReadIntradayFileRecordForBarIndexAndSubIndex is unable to read the bars from back then. Is there a solution for this? I want to be able to read intra day data regardless of how much data I am loading, even if it is old. Thanks in advance.
[2020-04-06 18:39:04]
Sierra Chart Engineering - Posts: 104368
Yes this does make sense, it is only going to read from the data file for the symbol of the chart. Not prior contract month symbols. Really we do not have a solution to this. You just need to use separate charts, one for each symbol.
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
[2020-04-06 20:01:32]
User79074 - Posts: 105
Is this something you cannot implement, for ReadIntradayFileRecordForBarIndexAndSubIndex to work on the entire chart even when using continuous contracts?
[2020-04-07 07:01:14]
Sierra Chart Engineering - Posts: 104368
No, this is far too involved to implement.
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
[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);
}




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

Login

Login Page - Create Account