Login Page - Create Account

Support Board


Date/Time: Mon, 06 May 2024 06:02:25 +0000



[Programming Help] - Accessing a subgraph value at an index

View Count: 905

[2019-11-06 07:38:15]
User907968 - Posts: 802
The line of code below is part of the problem, as it is always refering to the value held at the first index (0) of the BarClose subgraph:

BarOpen[Index] = BarClose[0];

Provide some more detail on what you are trying to achieve and maybe we can find the solution?
[2019-11-06 13:43:24]
brenanstewart - Posts: 28
I want the variable StackPullValue to be charted as normal candlesticks where I can see the open, high, low, and close for each bar. BarClose is working properly. It is continually updating as the StackPullValue changes. I want BarOpen to show me what StackPullValue was when a new candlestick bar opens. So I want the first value every time the index is incremented. I also want the high and low values for each bar to be displayed by the subgraphs BarHigh and BarLow. Does this make sense? I'm just trying to plot standard candlesticks.
[2019-11-06 15:23:21]
bradh - Posts: 854
There is a problem with your declaration of the subgraph and then assigning a value to it. The basic method follows. You will need to modify it to suit your needs.

Let's say you want the BarOpen subgraph to be equal to the Bar Open for each bar.

The SCSubgraphRef declaration should be (you cannot assign a value to it like SC_OPEN when declaring it):

SCSubgraphRef BarOpen = sc.Subgraph[0];

You then assign the Open to the subgraph like this:

BarOpen[Index] = sc.BaseDataIn[SC_OPEN][Index];

[2019-11-06 16:23:06]
brenanstewart - Posts: 28
Ok so I changed all of the subgraph declarations to:

SCSubgraphRef BarOpen = sc.Subgraph[0];
SCSubgraphRef BarHigh = sc.Subgraph[1];
SCSubgraphRef BarLow = sc.Subgraph[2];
SCSubgraphRef BarClose = sc.Subgraph[3];

I'm still assigning values to BarClose using:

BarClose[Index] = StackPullValue;

I tried to assign values to BarOpen using:

BarOpen[Index] = BarClose.Arrays[0][Index];

to get the first value of BarClose at each index. This doesn't generate any errors when I build it. But when I add the study to my chart, BarOpen is always 0.
[2019-11-06 17:04:28]
User907968 - Posts: 802
you cannot assign a value to it like SC_OPEN when declaring it

This is not techically correct, 'SC_OPEN' is declared in scconstants.h as a const int with a value of 0.

The following declarations amount to the same thing:

SCSubgraphRef BarOpen = sc.Subgraph[0]
SCSubgraphRef BarOpen = sc.Subgraph[SC_OPEN]
[2019-11-06 17:09:54]
brenanstewart - Posts: 28
I thought those were the same but I wasn't sure. Either way, I don't think my subgraph declarations are the problem. The problem I'm having is how to get BarOpen, BarHigh, and BarLow to display the proper values? BarClose is the only subgraph that I have gotten to work properly.
[2019-11-06 17:21:52]
bradh - Posts: 854
This is not technically correct, 'SC_OPEN' is declared in scconstants.h as a const int with a value of 0.

The following declarations amount to the same thing:

SCSubgraphRef BarOpen = sc.Subgraph[0]
SCSubgraphRef BarOpen = sc.Subgraph[SC_OPEN]

Yes, you are right, I did not know that. But why bother? What value does using those constants add? How does that prevent you from using another Subgraph[0] by mistake? I have never seen anyone declare SubgraphRefs using constants this way. From a support standpoint, I want all my subgraphs numbered sequentially, so I can easily scan the list to ensure the next one I create has not already been used. I do the same thing with SCInputRefs and persistent variables.

Using SC_OPEN instead of 0 does not assign the value of the bar's open to the subgraph, which I assumed, perhaps incorrectly, was what the original poster wanted to do.

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

Login

Login Page - Create Account