Login Page - Create Account

Support Board


Date/Time: Sun, 22 Dec 2024 18:47:24 +0000



sc.GetStudyArrayFromChartUsingID not working correctly?

View Count: 1607

[2015-05-01 17:50:20]
CustomIndicators - Posts: 126
I'm trying to use this code in order to retrieve data from a special indicator I made.

void sc.GetStudyArrayFromChartUsingID(int ChartNumber, int StudyID , int SubgraphIndex, SCFloatArrayRef SubgraphArray)

So far, I haven't been able to pull anything other than price graph values.

The chart I'm trying to pull from for this test, is #1.
The StudyID looks to also be 1. In the Chart Studies popup, the list has one study on it, labeled: "1: Indicator. ID: 1"
Am I miss-understanding the subgraph index? The indicator is in the code:
SCSubgraphRef Indicator = sc.Subgraph[0];


Now, this is what I'm using, trying to grab the value from that indicator:


SCFloatArray StudyReference;
sc.GetStudyArrayFromChartUsingID(1, 1, 0, StudyReference);

float valuE;
valuE = StudyReference[0];

SCString BufferOne;
BufferOne.Format("Value: %f", valuE);
sc.AddMessageToLog(BufferOne, 0);

This puts out to the Message Log:
Chart: AUDJPY 5 Sec #1 | Study: Indicator | Value: 0.000000 | 2015-05-01 17:47:24

If I have:

SCFloatArray StudyReference;
sc.GetStudyArrayFromChartUsingID(1, 1, 1, StudyReference);

float valuE;
valuE = StudyReference[0];

SCString BufferOne;
BufferOne.Format("Value: %f", valuE);
sc.AddMessageToLog(BufferOne, 0);

I get:
Chart: AUDJPY 5 Sec #1 | Study: Indicator | Value: 94.593498 | 2015-05-01 17:48:35

How can I get my indicator value? It tends to sit right around the 1.000 to -1.000 range.
[2015-05-02 20:54:12]
CustomIndicators - Posts: 126
So, any ideas?
[2015-05-03 06:23:41]
crazybears - Posts: 314
Hi ARGagnon

take a look here :

http://www.sierrachart.com/index.php?page=doc/doc_ACSILRefOtherTimeFrames.php#DirectReferencing


[2015-05-04 08:40:33]
Sierra Chart Engineering - Posts: 104368
The code you have in post #1 looks correct.

We did test the function and it does work correctly. Here is an example as it is used in Sierra Chart:


/*============================================================================*/
SCSFExport scsf_LargeTextDisplayForStudyFromChart(SCStudyInterfaceRef sc)
{
  SCSubgraphRef TextDisplay = sc.Subgraph[0];

  SCInputRef HorizontalPosition = sc.Input[0];
  SCInputRef VerticalPosition = sc.Input[1];
  SCInputRef DisplayInFillSpace = sc.Input[2];
  SCInputRef StudySubgraphReference = sc.Input[3];
  SCInputRef DisplaySubgraphName = sc.Input[4];
  SCInputRef SubgraphOffset = sc.Input[5];

  
  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    
    sc.GraphName = "Text Display For Study from Chart";
    
    sc.AutoLoop = 0;
    sc.GraphRegion = 0;

    TextDisplay.Name = "Text Display";
    TextDisplay.LineWidth = 20;
    TextDisplay.DrawStyle = DRAWSTYLE_CUSTOM_TEXT;
    TextDisplay.PrimaryColor = RGB(0, 0, 0); //black
    TextDisplay.SecondaryColor = RGB(128, 255, 255);
    TextDisplay.SecondaryColorUsed = true;
    TextDisplay.DisplayNameValueInWindowsFlags = 0;

    HorizontalPosition.Name = "Horizontal Position From Left (1-150)";
    HorizontalPosition.SetInt(20);
    HorizontalPosition.SetIntLimits(1,150);

    VerticalPosition.Name = "Vertical Position From Bottom (1-100)";
    VerticalPosition.SetInt(90);
    VerticalPosition.SetIntLimits(1,100);

    DisplayInFillSpace.Name = "Display in Fill Space";
    DisplayInFillSpace.SetYesNo(false);

    StudySubgraphReference.Name = "Study And Subgraph To Display";
    StudySubgraphReference.SetChartStudySubgraphValues(1, 1, 0);

    DisplaySubgraphName.Name = "Display Subgraph Name";
    DisplaySubgraphName.SetYesNo(false);

    SubgraphOffset.Name = "Subgraph Columns Back";
    SubgraphOffset.SetInt(0);

    sc.TextInputName= "Prefix Text for Display Value";

    
    // During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = false;

    return;
  }
  
  // Do data processing

  if (sc.HideStudy)//do nothing if study is hidden
    return;

  SCFloatArray StudyReference;
  //sc.GetStudyArrayFromChartUsingID(StudySubgraphReference.GetChartStudySubgraphValues(), StudyReference);

  sc.GetStudyArrayFromChartUsingID(StudySubgraphReference.GetChartNumber(), StudySubgraphReference.GetStudyID(), StudySubgraphReference.GetSubgraphIndex(), StudyReference);
  
  
  s_UseTool Tool;

  Tool.Clear(); // Reset tool structure for our next use. Unnecessary in this case, but good practice.
  Tool.ChartNumber = sc.ChartNumber;
  Tool.DrawingType = DRAWING_TEXT;
  
  Tool.LineNumber = 79212343+ (sc.StudyGraphInstanceID);
  if(!DisplayInFillSpace.GetYesNo() && !sc.Input[8].GetYesNo())
    Tool.BeginDateTime = HorizontalPosition.GetInt();
  else
    Tool.BeginDateTime = -3;

  Tool.Region = sc.GraphRegion;
  Tool.BeginValue = (float)VerticalPosition.GetInt();
  Tool.UseRelativeVerticalValues = true;
  Tool.Color = TextDisplay.PrimaryColor;
  Tool.FontBackColor = TextDisplay.SecondaryColor;
  Tool.FontBold = true;

  
  SCString ValueText;
  if (sc.TextInput.GetLength()>0)
  {
    ValueText+= sc.TextInput;
    ValueText += " ";
  }

  int ColumnsBack = SubgraphOffset.GetInt();
  float StudyValue = StudyReference[StudyReference.GetArraySize() - 1 - ColumnsBack];
  if (StudyValue == -FLT_MAX)//Patch for when referencing data from the Numbers Bars Calculated Values study. This value could be used.
    StudyValue = 0;

  ValueText +=sc.FormatGraphValue(StudyValue, sc.GetValueFormat());
  Tool.Text = ValueText;
  
  Tool.FontSize = TextDisplay.LineWidth;
  Tool.AddMethod = UTAM_ADD_OR_ADJUST;
  Tool.ReverseTextColor = false;
  
  
  sc.UseTool(Tool);
}


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
[2015-05-09 05:10:32]
CustomIndicators - Posts: 126
For anyone in the future with a similar issue, I found the error in my code. It was just a simple programming mistake.

I had:
SCFloatArray StudyReference;

sc.GetStudyArrayFromChartUsingID(1, 1, 0, StudyReference);



float valuE;

valuE = StudyReference[0];



SCString BufferOne;

BufferOne.Format("Value: %f", valuE);

sc.AddMessageToLog(BufferOne, 0);

When I should have had:
SCFloatArray StudyReference;

sc.GetStudyArrayFromChartUsingID(1, 1, 0, StudyReference);



float valuE;

valuE = StudyReference[sc.Index];



SCString BufferOne;

BufferOne.Format("Value: %f", valuE);

sc.AddMessageToLog(BufferOne, 0);

Date Time Of Last Edit: 2015-05-09 05:10:55

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

Login

Login Page - Create Account