Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 01:14:35 +0000



Why does DRAWSYLE_BACKGROUND cause DRAWSTYLE_COLOR_BAR to stop working?

View Count: 206

[2024-10-11 21:54:40]
User719512 - Posts: 264
Hi Sierra Chart Engineering,

Just discovered that a study with 2 Subgraphs will not work as expected when one is DRAWSYLE_BACKGROUND and the other is DRAWSTYLE_COLOR_BAR.

With DRAWSYLE_BACKGROUND on one and DRAWSTYLE_COLOR_BAR on the other, the Color Bar coloring is not working.

Setting the DRAWSYLE_BACKGROUND Subgraph to Ignore or DRAWSTYLE_BACKGROUND_TRANSPARENT shows the Color Bar coloring as expected (as well as the background coloring).

See attached image for the two scenarios with a random study I used...(1) busted, (2) working as expected.

Is this a bug in Sierra or some obscure way DRAWSYLE_BACKGROUND works?
imageScreenshot 2024-10-11 145326.png / V - Attached On 2024-10-11 21:53:47 UTC - Size: 50.61 KB - 35 views
[2024-10-11 23:09:59]
John - SC Support - Posts: 36286
We are not understanding the situation. Please get us a chart that shows this issue by following these instructions:
Support Board Posting Information: Providing Chartbook with Only a Single Chart
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-10-12 18:14:26]
User719512 - Posts: 264
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);

}
}

[2024-10-14 14:34:52]
John - SC Support - Posts: 36286
We do not give programming help. Since this is a custom study, we can not help.

We have set this thread as "Programming Help", so you may get help from others in the community.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-10-14 15:01:25]
User431178 - Posts: 541
Chart Studies: Background (ACSIL: DRAWSTYLE_BACKGROUND)

It's documented behavior.
[2024-10-14 16:09:52]
User719512 - Posts: 264
I was not asking for programming help John, I was providing an example of the issue since my first post was unclear so you could see for yourself. User431178 has provided a helpful link that explains the behavior. I missed looking for that in my original research.

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

Login

Login Page - Create Account