Login Page - Create Account

Support Board


Date/Time: Sun, 19 May 2024 02:17:39 +0000



[Programming Help] - Trouble evaluating MACD values at previous closes

View Count: 643

[2016-11-08 15:47:19]
AcquaLife - Posts: 33
The title says it all. I want to evaluate MACD difference value at prior 15min bar closes. I want to save those into variables such as MACDDIFF1 MACDDIFF2 MACDDIFF3. I have been working with this code block provided by SC:
sc.MACD(sc.BaseData[SC_LAST], sc.Subgraph[0], 5, 10, 10, MOVAVGTYPE_SIMPLE);

//Access the individual lines
float MACD = sc.Subgraph[0][sc.Index]; //Access the study value at the current index

float MACDMovingAverage = sc.Subgraph[0].Arrays[2][sc.Index];

float MACDDifference = sc.Subgraph[0].Arrays[3][sc.Index];

//Copy to Visible Subgraphs
sc.Subgraph[1][sc.Index] = MACDMovingAverage;
sc.Subgraph[2][sc.Index] = MACDDifference;

So, what I have tried to do to evaluate the previous values of the MACD difference at previous 15min closes is
float MACDDifference = sc.Subgraph[0].Arrays[3][sc.Index];
float MACDDifference1 = sc.Subgraph[0].Arrays[3][sc.Index-1];
float MACDDifference2 = sc.Subgraph[0].Arrays[3][sc.Index-2];
The sc.Index-1, sc.Index-2, ect. does not seem to work. I have tried using SC_LAST or sc.Close and someother things.
Please illuminate some light on what I am doing wrong.

Thank you so much.
On another note, I have to say thanks to SC for providing all of this functionality at such a low cost... wow, I have searched for a long time to find something like this, and got really lucky to stumble across SC!
[2016-11-08 19:53:44]
AcquaLife - Posts: 33
Hello, can someone at least please confirm that from the above code float MACDDifference1 = sc.Subgraph[0].Arrays[3][sc.Index-1] would have the value of the MACD difference at the close of the last bar that has closed?
[2016-11-08 21:33:23]
Sierra Chart Engineering - Posts: 104368
This is generally correct. Understand that sc.Index during a full recalculation starts off at zero and goes up to the sc.ArraySize -1.

Refer to:
Working with ACSIL Arrays and Understanding Looping
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

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

Login

Login Page - Create Account