Login Page - Create Account

Support Board


Date/Time: Mon, 06 May 2024 03:07:55 +0000



DRAWSTYLE_COLOR_BAR does not work with DRAWSTYLE_BACKGROUND

View Count: 526

[2020-05-10 00:02:22]
Yoda - Posts: 106
I have a study that colors the bars when certain conditions are met.

I decided to add the option to switch between coloring the bars and coloring the background.

However, I found once I added DRAWSTYLE_BACKGROUND to the code, DRAWSTYLE_COLOR_BAR no longer worked.

I tried numerous other drawstyles, like DRAWSTYLE_ARROW_DOWN and DRAWSTYLE_POINT in place of DRAWSTYLE_COLOR_BAR and all of those worked.

The issue appears to be only with DRAWSTYLE_COLOR_BAR.

To demonstrate this issue, I created a study (1st example below) from the BackgroundDrawStyleExample in studies8.cpp and added the option to switch to DRAWSTYLE_COLOR_BAR. You will note that when you switch to Color bar, the bars are not colored.

If you comment out Subgraph_ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR; and un-comment either one of the two lines below it, you will see that both arrow down and the point works without any issue.

To further demonstrate this issue, I have a second study below. It is the same code as the first study, but I have commented out all of the lines related to Subgraph_Background and Subgraph_BackgroundDC. You will note that the bars are now being colored.

Is this a bug in SC or is there something I need to do to have DRAWSTYLE_COLOR_BAR working with DRAWSTYLE_BACKGROUND?


/******************************************************************************
Name      : BackgroundDrawStyleExampleWithColorBar01.cpp
Description    : Demonstrates issue when combining
            DRAWSTYLE_BACKGROUND & DRAWSTYLE_COLOR_BAR
Last Modified Date  : 20200509-1823
Version      : 0.01
Disclosure *****  : SEE DISCLOSURE BELOW CODE
******************************************************************************/

#include "sierrachart.h"

SCDLLName("BackgroundDrawStyleExampleWithColorBar01")

SCSFExport scsf_BackgroundDrawStyleExample(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_Background = sc.Subgraph[0];
  SCSubgraphRef Subgraph_BackgroundDC = sc.Subgraph[1];
  SCSubgraphRef Subgraph_ColorBar    = sc.Subgraph[2];
  SCSubgraphRef Subgraph_HighPrice  = sc.Subgraph[3];

  SCInputRef Input_ColorBar_or_ColorBackground  = sc.Input[1];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    sc.GraphName = "Background DrawStyle Example";
    sc.StudyDescription = "Background DrawStyle Example";

    sc.AutoLoop = true;
    
    sc.GraphRegion = 0;
    sc.DrawStudyUnderneathMainPriceGraph = 1; // not required in studies, but want color behind price for this study

    Subgraph_Background.Name = "Background";
    Subgraph_Background.DrawStyle = DRAWSTYLE_BACKGROUND;
    Subgraph_Background.PrimaryColor = COLOR_LIGHTGREEN;
    Subgraph_Background.SecondaryColor = COLOR_LIGHTPINK;
    Subgraph_Background.SecondaryColorUsed = true; // turn on if both colors are to be used
    Subgraph_Background.AutoColoring = AUTOCOLOR_POSNEG; // use positive/negative values to signify colors

    Subgraph_BackgroundDC.Name = "Background DataColor";
    Subgraph_BackgroundDC.DrawStyle = DRAWSTYLE_BACKGROUND;
    Subgraph_BackgroundDC.PrimaryColor = RGB(255,0,255);

    Subgraph_ColorBar.Name = "Background";
    Subgraph_ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR; // DOES NOT WORK
    //Subgraph_ColorBar.DrawStyle = DRAWSTYLE_ARROW_DOWN; // WORKS
    //Subgraph_ColorBar.DrawStyle = DRAWSTYLE_POINT; // WORKS
    Subgraph_ColorBar.PrimaryColor = COLOR_LIGHTGREEN;
    Subgraph_ColorBar.SecondaryColor = COLOR_LIGHTPINK;
    Subgraph_ColorBar.SecondaryColorUsed = true;  // turn on if both colors are to be used
    Subgraph_ColorBar.AutoColoring = AUTOCOLOR_POSNEG; // use positive/negative values to signify colors
    Subgraph_ColorBar.LineWidth = 8;

    Input_ColorBar_or_ColorBackground.Name = "Color Bar or background";
    Input_ColorBar_or_ColorBackground.SetCustomInputStrings("0: Color Background; 1: Color bar");
    Input_ColorBar_or_ColorBackground.SetCustomInputIndex(0);
    Input_ColorBar_or_ColorBackground.SetIntLimits(0,1);
        
    return;
  }

  // Do data processing
  int min = sc.BaseDateTimeIn[sc.Index].GetMinute();

  float High = sc.High[sc.Index];
  
  if (Input_ColorBar_or_ColorBackground.GetIndex() == 0) // Color Background
  {
    if (min > 0 && min < 15)
      Subgraph_Background[sc.Index] = 0; // do not color background
    else if (min >= 15 && min < 30)
      Subgraph_Background[sc.Index] = 1; // use primary color
    else if (min >= 30 && min < 45)
      Subgraph_Background[sc.Index] = -1; // use secondary color
    else if (min >= 45 && min < 60)
    {
      Subgraph_BackgroundDC[sc.Index] = 1;
      Subgraph_BackgroundDC.DataColor[sc.Index] = RGB(0, 0, 17*(60-min));
    }
  }
  else // 1st 15m no coloring, 2nd & 3rd color bars, 4th 15m color background
  {
    if (min > 0 && min < 15)
    {
      Subgraph_ColorBar[sc.Index] = 0;  // do not color bar
    }    
    else if (min >= 15 && min < 30)
    {
      Subgraph_ColorBar[sc.Index] = High;  
      Subgraph_ColorBar.DataColor[sc.Index] = Subgraph_ColorBar.PrimaryColor;
    }
    else if (min >= 30 && min < 45)
    {
      Subgraph_ColorBar[sc.Index] = High;
      Subgraph_ColorBar.DataColor[sc.Index] = Subgraph_ColorBar.SecondaryColor;
    }
    else if (min >= 45 && min < 60) // color background
    {
      Subgraph_BackgroundDC[sc.Index] = 1;
      Subgraph_BackgroundDC.DataColor[sc.Index] = RGB(0, 0, 17*(60-min));
    }
  }
/*****************************************************************************
DISCLAIMER / WARNING:
This code is provided for educational purposes on an As Is, Where Is basis.
No express or implied warranties are provided.
There may be errors in this code, and it must not be used for live trading.
Trading is very risky and you can lose more than you have invested.
Past performance is not necessarily indicative of future results.
By using any of this code, you acknowledge and agree to the above.

******************************************************************************/
}


/******************************************************************************
Name        : OnlyColorBar02.cpp
Description      : Shows DRAWSTYLE_COLOR_BAR works when
            DRAWSTYLE_BACKGROUND is commented out
Last Modified Date  : 20200509-1849
Version        : 0.01
Disclosure *****  : SEE DISCLOSURE BELOW CODE
******************************************************************************/

#include "sierrachart.h"

SCDLLName("OnlyColorBar02")

SCSFExport scsf_BackgroundDrawStyleExample(SCStudyInterfaceRef sc)
{
  //SCSubgraphRef Subgraph_Background = sc.Subgraph[0];
  //SCSubgraphRef Subgraph_BackgroundDC = sc.Subgraph[1];
  SCSubgraphRef Subgraph_ColorBar    = sc.Subgraph[2];
  SCSubgraphRef Subgraph_HighPrice  = sc.Subgraph[3];

  SCInputRef Input_ColorBar_or_ColorBackground  = sc.Input[1];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults
    sc.GraphName = "Background DrawStyle Example";
    sc.StudyDescription = "Background DrawStyle Example";

    sc.AutoLoop = true;
    
    sc.GraphRegion = 0;
    sc.DrawStudyUnderneathMainPriceGraph = 1; // not required in studies, but want color behind price for this study
  /*  
    Subgraph_Background.Name = "Background";
    Subgraph_Background.DrawStyle = DRAWSTYLE_BACKGROUND;
    Subgraph_Background.PrimaryColor = COLOR_LIGHTGREEN;
    Subgraph_Background.SecondaryColor = COLOR_LIGHTPINK;
    Subgraph_Background.SecondaryColorUsed = true; // turn on if both colors are to be used
    Subgraph_Background.AutoColoring = AUTOCOLOR_POSNEG; // use positive/negative values to signify colors

    Subgraph_BackgroundDC.Name = "Background DataColor";
    Subgraph_BackgroundDC.DrawStyle = DRAWSTYLE_BACKGROUND;
    Subgraph_BackgroundDC.PrimaryColor = RGB(255,0,255);
  */
    Subgraph_ColorBar.Name = "Background";
    Subgraph_ColorBar.DrawStyle = DRAWSTYLE_COLOR_BAR; // NOW WORKS
    //Subgraph_ColorBar.DrawStyle = DRAWSTYLE_ARROW_DOWN; // WORKS
    //Subgraph_ColorBar.DrawStyle = DRAWSTYLE_POINT; // WORKS
    Subgraph_ColorBar.PrimaryColor = COLOR_LIGHTGREEN;
    Subgraph_ColorBar.SecondaryColor = COLOR_LIGHTPINK;
    Subgraph_ColorBar.SecondaryColorUsed = true;  // turn on if both colors are to be used
    Subgraph_ColorBar.AutoColoring = AUTOCOLOR_POSNEG; // use positive/negative values to signify colors
    Subgraph_ColorBar.LineWidth = 8;

    Input_ColorBar_or_ColorBackground.Name = "Color Bar or background";
    Input_ColorBar_or_ColorBackground.SetCustomInputStrings("0: Color Background; 1: Color bar");
    Input_ColorBar_or_ColorBackground.SetCustomInputIndex(1);
    Input_ColorBar_or_ColorBackground.SetIntLimits(0,1);
        
    return;
  }

  // Do data processing
  int min = sc.BaseDateTimeIn[sc.Index].GetMinute();

  float High = sc.High[sc.Index];
/*  
  if (Input_ColorBar_or_ColorBackground.GetIndex() == 0) // Color Background
  {
    if (min > 0 && min < 15)
      Subgraph_Background[sc.Index] = 0; // do not color background
    else if (min >= 15 && min < 30)
      Subgraph_Background[sc.Index] = 1; // use primary color
    else if (min >= 30 && min < 45)
      Subgraph_Background[sc.Index] = -1; // use secondary color
    else if (min >= 45 && min < 60)
    {
      Subgraph_BackgroundDC[sc.Index] = 1;
      Subgraph_BackgroundDC.DataColor[sc.Index] = RGB(0, 0, 17*(60-min));
    }
  }
  else // 1st 15m no coloring, 2nd & 3rd color bars, 4th 15m color background
  {
*/    
    if (min > 0 && min < 15)
    {
      Subgraph_ColorBar[sc.Index] = 0;  // do not color bar
    }    
    else if (min >= 15 && min < 30)
    {
      Subgraph_ColorBar[sc.Index] = High;  
      Subgraph_ColorBar.DataColor[sc.Index] = Subgraph_ColorBar.PrimaryColor;
    }
    else if (min >= 30 && min < 45)
    {
      Subgraph_ColorBar[sc.Index] = High;
      Subgraph_ColorBar.DataColor[sc.Index] = Subgraph_ColorBar.SecondaryColor;
    }
  /*  else if (min >= 45 && min < 60) // color background
    {
      Subgraph_BackgroundDC[sc.Index] = 1;
      Subgraph_BackgroundDC.DataColor[sc.Index] = RGB(0, 0, 17*(60-min));
    }
  }
  */
/*****************************************************************************
DISCLAIMER / WARNING:
This code is provided for educational purposes on an As Is, Where Is basis.
No express or implied warranties are provided.
There may be errors in this code, and it must not be used for live trading.
Trading is very risky and you can lose more than you have invested.
Past performance is not necessarily indicative of future results.
By using any of this code, you acknowledge and agree to the above.

******************************************************************************/
}

[2020-05-10 01:08:17]
Sierra Chart Engineering - Posts: 104368
We are fairly sure this is documented somewhere, but we just put together this Note in the Background Draw Style documentation:
https://www.sierrachart.com/index.php?page=doc/ChartStudies.html#DrawStyle_Background_Note
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
Date Time Of Last Edit: 2020-05-10 01:08:32
[2020-05-10 02:55:13]
Yoda - Posts: 106
we just put together this Note in the Background Draw Style documentation

Thank you, the note was very helpful. Using DRAWSTYLE_BACKGROUND_TRANSPARENT fixed the color bar issue.

Now that it is transparent, I've been trying to find a way in ACSIL to set the transparency level for DRAWSTYLE_BACKGROUND_TRANSPARENT.

I found that this can be done with drawing tools using TransparencyLevel. However when I tried Subgraph_ColorBackground.TransparencyLevel = 50; I received an error.

Is it possible to set the transparency level for DRAWSTYLE_BACKGROUND_TRANSPARENT? If so, please provide me with the appropriate link. If not, might it be possible to add this?
[2020-05-10 07:40:28]
Sierra Chart Engineering - Posts: 104368
Refer to:
ACSIL Interface Members - Variables and Arrays: sc.TransparencyLevel
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

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

Login

Login Page - Create Account