Support Board
Date/Time: Mon, 19 May 2025 16:23:39 +0000
Post From: Accesing Prive Color Value
[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; } */ |