Login Page - Create Account

Support Board


Date/Time: Mon, 23 Jun 2025 20:53:53 +0000



[Programming Help] - ACSIL Renko Open Close

View Count: 1050

[2022-02-09 18:12:43]
User92573 - Posts: 565
Dear Support, I'm having trouble referencing some chart values and would be grateful for some assistance.


I can see in the in the headers subgraph reference.


#ifndef _SCCONSTANTS_H_
#define _SCCONSTANTS_H_

//Refer to ACSIL Arrays and Variables documentation for descriptions of each of these sc.BaseDataIn[] constants

const int SC_RENKO_OPEN        = 21;
const int SC_POINT_FIGURE_HIGH = SC_RENKO_OPEN;
const int SC_RENKO_CLOSE      = 22;
const int SC_POINT_FIGURE_LOW = SC_RENKO_CLOSE;


And in an example study with manual looping; Autoloop = 0 the use of the index.

sc.BaseDataIn[SC_RENKO_OPEN][BarIndex]

However, I am using a standard Renko 20t chart and an Autoloop Study where I simply want to populate:


SCSubgraphRef Subgraph_Renko_PriorOpen = sc.Subgraph[0];
SCSubgraphRef Subgraph_Renko_PriorClose = sc.Subgraph[1];
SCSubgraphRef Subgraph_Renko_Open = sc.Subgraph[2];
SCSubgraphRef Subgraph_Renko_Close = sc.Subgraph[3];

with


sc.BaseData[SC_RENKO_OPEN][-1];
sc.BaseData[SC_RENKO_CLOSE][-1];
sc.BaseData[SC_RENKO_OPEN];
sc.BaseData[SC_RENKO_CLOSE];

i.e.

SCSubgraphRef Subgraph_Renko_PriorOpen = sc.BaseData[SC_RENKO_OPEN][-1];
SCSubgraphRef Subgraph_Renko_PriorClose = sc.BaseData[SC_RENKO_CLOSE][-1];
SCSubgraphRef Subgraph_Renko_Open = sc.BaseData[SC_RENKO_OPEN];
SCSubgraphRef Subgraph_Renko_Close = sc.BaseData[SC_RENKO_CLOSE];

But this does not provide the price values as expected. I can see them in the "chart values for tools" listed as Renko Open, and Renko Close.

I just can't seem to reference it in ACSIL even though one of the example studies uses:

bool PriorBarUp = PriorRenkoOpen < PriorRenkoClose;

To determine direction.

Any help appreciated.
[2022-02-09 23:51:02]
1+1=10 - Posts: 270
Hi, I'm a fellow user that codes in ACSIL a lot.

1. "SCSubgraphRef" is a type like "int". You use it when you declare the Subgraph variables but not when you assign to them later in the study. See below.
2. You're confused about how to reference the data in an array whether you're using manual looping or automatic looping. See the example code below but it would be helpful to reread this: Working with ACSIL Arrays and Understanding Looping


SCSubgraphRef Subgraph_Renko_PriorOpen = sc.Subgraph[0];
SCSubgraphRef Subgraph_Renko_PriorClose = sc.Subgraph[1];
SCSubgraphRef Subgraph_Renko_Open = sc.Subgraph[2];
SCSubgraphRef Subgraph_Renko_Close = sc.Subgraph[3];

if(sc.SetDefaults)
{
// You would have the typical set-up code here
sc.Autoloop = true;
// NOTE: working with automatic looping is easier but in the link above you
// can see how to do manually looping correctly

}
NOTE: When you place a study on chart or recalculate it your study is called once for every bar before the last one. 'sc.Index' refers to the current bar that the study is processing. It starts at the first bar on the chart, bar 0, and increments all the way up to the last bar in the chart. Thus, if at every bar in the chart you want to refer to the previous bar you do sc.Index - 1. ... The check below is necessary because when sc.Index is 0, sc.Index - 1 == -1 which will be out of bounds for the sc.BaseData arrays.

if (sc.Index >= 1)
{
Subgraph_Renko_PriorOpen[sc.Index] = sc.BaseData[SC_RENKO_OPEN][sc.Index - 1];
Subgraph_Renko_PriorClose[sc.Index] = sc.BaseData[SC_RENKO_CLOSE][sc.Index - 1];
Subgraph_Renko_Open[sc.Index] = sc.BaseData[SC_RENKO_OPEN][sc.Index];
Subgraph_Renko_Close[sc.Index] = sc.BaseData[SC_RENKO_CLOSE][sc.Index];
}

[2022-02-10 00:51:26]
User92573 - Posts: 565
Hi thanks,

Yes, very useful I program quite a lot with ASCIL. Maybe my explanation was poor and I noticed a few errors pasting.

sc.SubgraphRef is actually an array as opposed to just an Integer variable.

For example:


SCSubgraphRef Subgraph_Range = sc.Subgraph[0]; // array

if (sc.SetDefaults)
{
sc.GraphName = "Bars Range";
sc.AutoLoop = 1; // called for every new bar as opposed to manual

etc. etc.
}

// do processing

Subgraph_Range[sc.Index] = sc.High[sc.Index] - sc.Low[sc.Index];


... and yes you can reference the bars back index with -1; -2; -3 etc.

So,


sc.BaseData[SC_RENKO_OPEN][-1]; // has two indexing options; 0 is the first element; -1 the second. Alt sc.Subgraph[][]
sc.BaseData[SC_RENKO_CLOSE][-1];
sc.BaseData[SC_RENKO_OPEN][0];
sc.BaseData[SC_RENKO_CLOSE][0];

... this is the method provided to input the Renko data as defined in Sierra's own examples.

The issue is, as simple as it should be I cannot seem reference these value in my code?

Subgraph_Renko_PriorOpen[sc.Index] = sc.BaseData[SC_RENKO_OPEN][-1];
Subgraph_Renko_PriorClose[sc.Index] = sc.BaseData[SC_RENKO_CLOSE][-1];
Subgraph_Renko_Open[sc.Index] = sc.BaseData[SC_RENKO_OPEN][0];
Subgraph_Renko_Close[sc.Index] = sc.BaseData[SC_RENKO_CLOSE][0];   

Should populate the following four arrays with the Renko values after every bar.

Subgraph_Renko_PriorOpen[sc.Index] = the RENKO OPEN 1 bar ago.
Subgraph_Renko_PriorClose[sc.Index] = the RENKO CLOSE 1 bar ago
Subgraph_Renko_Open[sc.Index] = the RENKO OPEN current bar
Subgraph_Renko_Close[sc.Index] = the RENKO CLOSE current

All pretty simple but alas the [SC_RENKO_OPEN] and [SC_RENKO_CLOSE] are nowhere to be found?

That's what I'd hoped to explain.

Many thanks.
[2022-02-10 01:33:37]
1+1=10 - Posts: 270
Below I've pasted an entire study written by SC located in the ACS_Source folder within file "Studies2.cpp". That study happens to use manual looping. I don't know which examples you're referring to that use "sc.BaseData[SC_RENKO_OPEN][-1]" and "sc.BaseData[SC_RENKO_CLOSE][0]" but note below SC uses:
sc.Subgraph[SubGraph][BarIndex] = sc.BaseDataIn[SC_RENKO_OPEN][BarIndex]

I added comments with an arrow to help you find it quicker below. For sc.BaseData/sc.BaseDataIn[][] the second [] is used to grab data from a certain bar. Similarly, for subgraphs the last [] is which bar you're writing the value of the subgraph for. See the docs here: ACSIL Interface Members - Variables and Arrays: sc.BaseDataIn[][] / sc.BaseData[][]

Again, I highly recommend you refresh your memory of how to work with the data/subgraph arrays and understanding looping: Working with ACSIL Arrays and Understanding Looping

Lastly, if you take both parts of the code I wrote in my first response, it will do exactly what you asked for here:

Subgraph_Renko_PriorOpen[sc.Index] = the RENKO OPEN 1 bar ago.
Subgraph_Renko_PriorClose[sc.Index] = the RENKO CLOSE 1 bar ago
Subgraph_Renko_Open[sc.Index] = the RENKO OPEN current bar
Subgraph_Renko_Close[sc.Index] = the RENKO CLOSE current


SC's code:

SCSFExport scsf_BarsInTicks(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Bars in Ticks";
    //sc.GraphRegion = 0;
    sc.ValueFormat = VALUEFORMAT_WHOLE_NUMBER;
    sc.AutoLoop = 0;
    sc.GraphDrawType = GDT_OHLCBAR;
    sc.StandardChartHeader = true;
    sc.GraphUsesChartColors = true;

    return;
  }

  n_ACSIL::s_BarPeriod BarPeriod;
  sc.GetBarPeriodParameters(BarPeriod);
  int RenkoTicksPerBar = BarPeriod.IntradayChartBarPeriodParameter1;


  if (sc.IsFullRecalculation && sc.UpdateStartIndex == 0)
  {
    sc.GraphName.Format("%s in Ticks", sc.GetStudyName(0).GetChars());

    for (int SubgraphIndex = 0; SubgraphIndex <= NUM_BASE_GRAPH_ARRAYS; ++SubgraphIndex)
    {
      sc.Subgraph[SubgraphIndex].Name = sc.GetStudySubgraphName(0, SubgraphIndex);
    }

  }

  for(int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize; BarIndex++)
  {
    for (int SubGraph = 0; SubGraph <= NUM_BASE_GRAPH_ARRAYS; SubGraph++)
    {
      if (SubGraph == SC_VOLUME || SubGraph == SC_NUM_TRADES || SubGraph == SC_BIDVOL || SubGraph == SC_ASKVOL)
        sc.Subgraph[SubGraph][BarIndex] = sc.BaseDataIn[SubGraph][BarIndex];
      else
      {

        if (RenkoTicksPerBar != 0 && SubGraph == SC_OPEN)
          sc.Subgraph[SubGraph][BarIndex] = sc.BaseDataIn[SC_RENKO_OPEN][BarIndex] / sc.TickSize; // <---
        else if (RenkoTicksPerBar != 0 && SubGraph == SC_LAST)
          sc.Subgraph[SubGraph][BarIndex] = sc.BaseDataIn[SC_RENKO_CLOSE][BarIndex] / sc.TickSize; // <---
        else
          sc.Subgraph[SubGraph][BarIndex] = sc.BaseDataIn[SubGraph][BarIndex] / sc.TickSize;
      }
    }
  }
}

[2022-02-10 08:43:01]
User92573 - Posts: 565
Thank you, that's very helpful indeed.

The original auto-looping study is actually working which is what I wanted and TBH honest, I rightly, or wrongly, don't use manual looping except for building synthetic timeframes.

So, as is often the case it was just a minor error resulting from the incorrect use of:

sc.BaseDataIn[SC_RENKO_OPEN][BarIndex].

that was causing the issue.

Probably a little too tired at the time to be programming and missed the need for a specific index location which is, I suspect why you mentioned in (INT) and I didn't pick it up.

That said your input and time was really very helpful. Thank you!
[2022-02-10 12:50:35]
1+1=10 - Posts: 270
Happy to help! Good luck with your trading.

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

Login

Login Page - Create Account