Support Board
Date/Time: Fri, 22 Nov 2024 16:31:49 +0000
Post From: Why does DRAWSYLE_BACKGROUND cause DRAWSTYLE_COLOR_BAR to stop working?
[2024-10-12 18:14:26] |
User719512 - Posts: 261 |
Build this study so you can see the issue. With Subgraph_BuySignal.DrawStyle = DRAWSTYLE_BACKGROUND;, the Subgraph_ColorBar will NOT work. With Subgraph_BuySignal.DrawStyle = DRAWSTYLE_BACKGROUND_TRANSPARENT;, the Subgraph_ColorBar will work. You can set these from the UI, so just build the sample once. Sample study code #include "sierrachart.h" #include <random> // Function to generate a random RGB color std::tuple<int, int, int> GenerateRandomRGBColor() { // Seed with a real random value, if available std::random_device rd; // Initialize a random number generator with the random seed std::mt19937 gen(rd()); // Define a distribution to generate values between 0 and 255 std::uniform_int_distribution<> distrib(0, 255); // Generate random values for Red, Green, and Blue components int red = distrib(gen); int green = distrib(gen); int blue = distrib(gen); // Return the RGB values as a tuple return std::make_tuple(red, green, blue); } // // scsf_RandomBarSignals // SCSFExport scsf_RandomBarSignals(SCStudyInterfaceRef sc) { SCString msg; int i; // // Subgraphs // i = 0; SCSubgraphRef Subgraph_BuySignal = sc.Subgraph[i++]; SCSubgraphRef Subgraph_SellSignal = sc.Subgraph[i++]; SCSubgraphRef Subgraph_ColorBar = sc.Subgraph[i++]; if (sc.SetDefaults) { sc.GraphName = "Random Bar Signals"; sc.AutoLoop = 0; sc.GraphRegion = 0; Subgraph_BuySignal.Name = "Buy Signal"; Subgraph_BuySignal.DrawStyle = DRAWSTYLE_BACKGROUND; Subgraph_BuySignal.PrimaryColor = COLOR_BLUE; Subgraph_BuySignal.LineWidth = 1; Subgraph_BuySignal.DrawZeros = 0; Subgraph_SellSignal.Name = "Sell Signal"; Subgraph_SellSignal.DrawStyle = DRAWSTYLE_BACKGROUND_TRANSPARENT; Subgraph_SellSignal.PrimaryColor = COLOR_RED; Subgraph_SellSignal.LineWidth = 1; Subgraph_SellSignal.DrawZeros = 0; Subgraph_ColorBar.Name = "Color Bar"; Subgraph_ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR; Subgraph_ColorBar.PrimaryColor = COLOR_GRAY; Subgraph_ColorBar.DrawZeros = false; return; } if (sc.UpdateStartIndex == 0) { // clear all SGs so Recalculate works properly for (int i = 0; i < SC_SUBGRAPHS_AVAILABLE; i++) { for (int barIndex = 0; barIndex < sc.ArraySize; barIndex++) { sc.Subgraph[i][barIndex] = 0; } } } // // Data processing on Manual Looping // for (int barIndex = sc.UpdateStartIndex; barIndex < sc.ArraySize; barIndex++) { if (sc.GetBarHasClosedStatus(barIndex) == BHCS_BAR_HAS_NOT_CLOSED) { continue; } auto [r, g, b] = GenerateRandomRGBColor(); if (r > 196) { Subgraph_BuySignal[barIndex] = sc.Close[barIndex]; } else if (r < 64) { Subgraph_SellSignal[barIndex] = sc.Close[barIndex]; } Subgraph_ColorBar[barIndex] = sc.Close[barIndex]; Subgraph_ColorBar.DataColor[barIndex] = RGB_COLOR(r, g, b); } } |