Login Page - Create Account

Support Board


Date/Time: Mon, 19 May 2025 12:30:49 +0000



[User Discussion] - Accesing Prive Color Value

View Count: 417

[2024-02-02 08:32:09]
User366743 - Posts: 14
I have custom study (MQ Trender Pro) painting the price bars on main price chart. It works well visually.
However, in order to automate/ act on this study other than manually/ visually I would need to
reference to the price colors (the study does not have any meaningful output and does most of the the work internally.

the RGB colors painted are

RGB colors used:
magenta 255 0 255 -->10
gray 211 211 211 -->20
dark green 0 100 0 -->30
green 0 255 0 -->40
dark red 139 0 0 -->50
red 255 0 0 -->60
cyan 0 255 255 -->70

How do I access the color value of a current price bar?

=============================
My concept ASCIL - tell me what should I change to return the value of the price color.

#include "sierrachart.h"

SCDLLName("ReadColorBar")

SCSFExport scsf_ColorBar(SCStudyInterfaceRef sc)
{

SCSubgraphRef ColorBar = sc.Subgraph[0];

If (sc.GraphDrawType != GDT_CUSTOM)
{
ColorBar.Name = "Color Bar";
ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR;

unsigned int ColorValue = ColorBar.PrimaryColor;
int cVal = 0;

If (ColorValue = RGB(255,0,255)){
cVal = 10;
} else if (ColorValue = RGB(211,211,211)){
cVal = 20;
} else if (ColorValue = RGB(0,100,0)){
cVal = 30;
} else if (ColorValue = RGB(0,255,0)){
cVal = 40;
} else if (ColorValue = RGB(139,0,0)){
cVal = 50;
} else if (ColorValue = RGB(255,0,0)){
cVal = 60;
} else if (ColorValue = RGB(0,255,255)){
cVal = 70;
}


sc.FreeDLL = 1;

return;




}
else
{
//;
}





}
Date Time Of Last Edit: 2024-02-02 15:49:43
imageMQ_Colors_1.jpg / V - Attached On 2024-02-02 08:26:50 UTC - Size: 32.46 KB - 70 views
imageMQ_Colors_2.jpg / V - Attached On 2024-02-02 08:26:59 UTC - Size: 387.77 KB - 76 views
[2024-02-02 11:34:26]
User431178 - Posts: 682
Hello
To access the colors applied by that study you would need to get the data color array and inspect the value (color) at the relevant bar.

ACSIL Interface Members - Functions: sc.GetStudyDataColorArrayFromChartUsingID()
[2024-02-06 08:02:40]
User366743 - Posts: 14
OK. I cleaned up few things and the files compiled. However, I did not get the data I was looking for.
Example 1 (with the ColorBar member)
#include "sierrachart.h"
SCDLLName("ReadTest2")

/*
First Test by WP
*/
int cVal = 0;
unsigned int ColorValue = 0;
SCSFExport scsf_ColorBar(SCStudyInterfaceRef sc)
{

  SCString msg;
  SCSubgraphRef ColorBar = sc.Subgraph[0];
  SCInputRef i_myNumb = sc.Input[1];
  

/*
  if (sc.GraphDrawType != GDT_CUSTOM)
  {
    ColorBar.Name = "ColorBar";
        
    return;
  
  }
*/  
  if (sc.SetDefaults)  {
      sc.GraphName = "ColorBar";
      sc.GraphRegion = 0;
      i_myNumb.Name = "FirstVal";
        
      //sc.AutoLoop = 1;
      return;
    }

    
  ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR;
  ColorValue = ColorBar.PrimaryColor;

  /*
  255 0 255 magentra / entry
  211 211 211 gray / extended
  0 100 0 dark green / bullish
  0 255 0 light green / strong bullish
  139 0 0 dark red / bearish
  255 0 0 light red / strong bearish
  255 255 0 golden bar / long
  255 255 200 golden bar / short
  0 255 255 cyan / flat
  */  
    
    if (ColorValue == RGB(255,0,255)){
    cVal = 10;
    } else if (ColorValue == RGB(211,211,211)){
    cVal = 20;
    } else if (ColorValue == RGB(0,100,0)){
    cVal = 30;
    } else if (ColorValue == RGB(0,255,0)){
    cVal = 40;
    } else if (ColorValue == RGB(139,0,0)){
    cVal = 50;
    } else if (ColorValue == RGB(255,0,0)){
    cVal = 60;
    } else if (ColorValue == RGB(0,255,255)){
    cVal = 70;
    } else { cVal = ColorValue; }
    
  

  /*
  if (cVal == 0) {
    cVal = sc.Subgraph[0].DataColor[0]; //Up
  }

  if (cVal == 0) {
    cVal = sc.Subgraph[0].DataColor[3]; //Down
  }
  
  if (cVal == 0) {
    cVal = ColorBar.PrimaryColor; //Down
  }

  */
//It likely returns the default primary color - not what I'm actually looking for.
    i_myNumb.SetInt(cVal);
}

Example 2 with GetStudyDataColorArrayFromChartUsingID also compiled - likely with similar results (will return default values).
This function is rather hard to use in proper context...

#include "sierrachart.h"
SCDLLName("ReadTest3")

int cVal = 0;
unsigned int ColorValue = 0;



SCSFExport scsf_MyStudyColors(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_ColorBar = sc.Subgraph[0];
  SCInputRef Input_ChartStudySubgraph = sc.Input[0];
  //SCInputRef In_myNumb = sc.Input[1];
  SCString msg;

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults

    sc.GraphName = "MyStudyColors";

    sc.AutoLoop = 0;

    sc.GraphRegion = 0;
    //In_myNumb.Name = "FirstVal";
    Subgraph_ColorBar.Name = "Bar";
    Subgraph_ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR;
    Subgraph_ColorBar.PrimaryColor = RGB(200, 200, 0);

    Input_ChartStudySubgraph.Name = "Study Subgraph Reference";
    Input_ChartStudySubgraph.SetChartStudySubgraphValues(1, 1, 0);

    sc.CalculationPrecedence = LOW_PREC_LEVEL;

    return;
  }


  // Do data processing


  SCColorArray DataColorArray;
  sc.GetStudyDataColorArrayFromChartUsingID(Input_ChartStudySubgraph.GetChartNumber(), Input_ChartStudySubgraph.GetStudyID(), Input_ChartStudySubgraph.GetSubgraphIndex(), DataColorArray);

  if (DataColorArray.GetArraySize() > 0)
  {
    for (int BarIndex = sc.UpdateStartIndex; BarIndex < sc.ArraySize; BarIndex++)
    {

      Subgraph_ColorBar[BarIndex] = 1;
      Subgraph_ColorBar.DataColor[BarIndex] = DataColorArray[BarIndex];

    }
  }


}

----------------------------------------
My take on this problem is like follow (if I remember correctly from the distant past): most C++ classes (provide objects implementations) have set (to set a value or reference) and get (to get a value or reference) member functions.
This is not going to work here because I'm not looking for a value that I already have set or for a system default.
I'm looking for a value that has been set by a different object (study - MQ Trender Pro) and even though I can see its effect (color) - I do not have a direct reference to this object (the study does not provide any meaningful output reference is spreadsheet values),
thus this may never work, unless there is an implementation for accessing a color value directly from the graph or from the screen.
This should be possible because C+++ has a lot of power if in good hands (not mine yet).
/*
//from StackOverflow
#include<windows.h>
#include<stdio.h>

typedef WINAPI COLORREF (*GETPIXEL)(HDC, int, int);

int main(int argc, char** argv)
{

HINSTANCE _hGDI = LoadLibrary("gdi32.dll");
if(_hGDI)
{
while(true) {
GETPIXEL pGetPixel = (GETPIXEL)GetProcAddress(_hGDI, "GetPixel");
HDC _hdc = GetDC(NULL);
if(_hdc)
{
POINT _cursor;
GetCursorPos(&_cursor);
COLORREF _color = (*pGetPixel) (_hdc, _cursor.x, _cursor.y);
int _red = GetRValue(_color);
int _green = GetGValue(_color);
int _blue = GetBValue(_color);

printf("Red: 0x%02x\n", _red);
printf("Green: 0x%02x\n", _green);
printf("Blue: 0x%02x\n", _blue);
}
FreeLibrary(_hGDI);
}
}
return 0;
}

*/
[2024-02-06 08:22:40]
User431178 - Posts: 682

Example 2 with GetStudyDataColorArrayFromChartUsingID also compiled - likely with similar results (will return default values).

If the DataColor array is used in the referenced study, it will return the colors that have been set.
Returning the default value would render the function completely pointless, there are already other functions for that purpose.


This function is rather hard to use in proper context...

What is hard about it?
You read the color value at an index and compare it do a set of color values to ascertain which you have.




My take on this problem is like follow (if I remember correctly from the distant past): most C++ classes (provide objects implementations) have set (to set a value or reference) and get (to get a value or reference) member functions.
This is not going to work here because I'm not looking for a value that I already have set or for a system default.
I'm looking for a value that has been set by a different object (study - MQ Trender Pro) and even though I can see its effect (color) - I do not have a direct reference to this object (the study does not provide any meaningful output reference is spreadsheet values),
thus this may never work, unless there is an implementation for accessing a color value directly from the graph or from the screen.
This should be possible because C+++ has a lot of power if in good hands (not mine yet).

You don't need to worry about any of that, the function is providing you with a reference to the required data.
The platform has ownership of all the objects, the fact that you don't own the object in your study is irrelevant.
Date Time Of Last Edit: 2024-02-06 08:24:11
[2024-02-06 08:40:33]
User366743 - Posts: 14
OK. Sounds great.
Digressing here -If I somehow was able to get the object (as desired) and then set its value by accident
while the other process/ study was actively using it - this would likely cause an access violation and possible page fault or even
Windows blue screen. I'm not looking for any of that.
I was able to figure out most of the logic of how the colors are assigned - and this was may goal anyways. Chasing the results of a study without understanding
it fully was a poor approach on my part.
Date Time Of Last Edit: 2024-03-02 20:00:13

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

Login

Login Page - Create Account