Login Page - Create Account

Support Board


Date/Time: Mon, 23 Jun 2025 15:59:12 +0000



Sierra should allow ability to treat +/- FLT_MAX like it does sc.Subgraph[].DrawZeros=0

View Count: 1360

[2022-02-12 02:03:21]
User719512 - Posts: 316
EDIT: please see reply #19 for an improved description of the request. Keeping the original thread below intact so that the comments below have relevant context.

To detect a higher high or lower low, you compare current value to previous value. So for the first comparison what is the initial value? In code usually you initialize the min to FLT_MAX and for max the FLT_MIN. That way the first real bar you compare against your variable is always greater than or less than the first real value. If like in my case we are not comparing a single bar, but rather a series of bars, trying to handle sc.Index=0 or creating some other tracking variable for each SG whether it is uninitialized is not an elegant solution. It also means you need to store 0 in the SG and constantly check whether the SG=0 is really 0 or it is uninitialized and zero for that reason. Such code is really cluttered and should be unnecessary.

A lot of times in code it is valid to initialize to zero. Since futures can trade negative as we have seen, we'd be broken if we used 0 for initial value since say if first bar for CL was like -5.20/-5.30 for high/low then we'd never detect that -5.20 high because max(0, -5.20) is 0 and we'd print the wrong bar. If you init to FLT_MIN then max(FLT_MIN, -5.20) works but if we store FLT_MIN or FLT_MAX in a Subgraph (SG), Sierra draws a chart really poorly. The scale jumps super wide and you have to manually set a constant range to get your chart back.

To fix Sierra, I think Sierra should allow the ability treat FLT_MIN/FLT_MAX like it does sc.Subgraph[].DrawZeros=0 for example in Study Price Overlay/etc. and not try to draw these values because the chart gets really messed up if you do!
Date Time Of Last Edit: 2022-02-12 21:07:54
[2022-02-12 06:40:28]
1+1=10 - Posts: 270
I think I understand your description.

In that case, I typically employ a simple check that sc.Index >= # of bars necessary for valid calculation. There’s no need to draw a subgraph on the 1st bar or even the first 1000 bars.

If you need to hold intermediate/background calculations you can also consider the never drawn 12 extra arrays that each subgraph has: ACSIL Interface Members - sc.Subgraph Array: sc.Subgraph[].Arrays[][]
Date Time Of Last Edit: 2022-02-12 07:08:57
[2022-02-12 08:48:27]
User431178 - Posts: 718
Maybe user719512 should fix their code instead of suggesting that Sierra Chart fix a non-existent problem.
Other users might actually utilise FLT_MIN for display purposes.
If you read the documentation for subgraphs, you would know the conditions under which the arrays are initialized to 0 (otherwise the previously set value is retained).

ACSIL Interface Members - sc.Subgraph Array: sc.Subgraph[].Data[] / sc.Subgraph[][]
[2022-02-12 12:20:19]
1+1=10 - Posts: 270
Maybe user719512 should fix their code instead of suggesting that Sierra Chart fix a non-existent problem.

Is that you, SC Engineering?
[2022-02-12 12:39:43]
User431178 - Posts: 718
No, but I am biased, because I use FLT_MIN for subgraph display in certain situations.
Date Time Of Last Edit: 2022-02-12 12:40:33
[2022-02-12 13:06:38]
1+1=10 - Posts: 270
No, but I am biased, because I use FLT_MIN for subgraph display in certain situations.

I hadn’t even considered that this would be a code-breaking change for some study authors! Yes, this is likely too risky of an API change for SC to consider.
[2022-02-12 13:21:19]
User719512 - Posts: 316
Which is why you would not change the current behavior, but rather Sierra could add functionally like sc.DrawZeros and add sc.Draw_FLT_MINMAX with the default of true for example.
[2022-02-12 13:30:33]
1+1=10 - Posts: 270
...but rather Sierra could add functionally like sc.DrawZeros and add sc.Draw_FLT_MINMAX with the default of true for example.

I'm not opposed to this in principle. Could you post some code illustrating the specific issue you're having? Perhaps there are alternatives that could be employed.
Date Time Of Last Edit: 2022-02-12 13:31:50
[2022-02-12 13:37:16]
User719512 - Posts: 316
If you read the documentation for subgraphs, you would know the conditions under which the arrays are initialized to 0 (otherwise the previously set value is retained).

One example where this breaks down is when you want to draw negative, zero, and positive subgraph values. In this case, there is no value you can set the subgraph value to and have Sierra not draw anything on the screen. For example, only draw the study during RTH hours and not Globex.
Date Time Of Last Edit: 2022-02-12 13:41:34
[2022-02-12 13:47:04]
1+1=10 - Posts: 270
If you read the documentation for subgraphs, you would know the conditions under which the arrays are initialized to 0 (otherwise the previously set value is retained).

One example where this breaks down is when you want to draw negative, zero, and positive subgraph values. In this case, there is no value you can set the subgraph value to and have Sierra not draw anything on the screen. For example, only draw the study during RTH hours and not Globex.

Ah, this is a good example! I can envision a study's subgraph that ideally would output 1, 0, and -1. Yes, sc.Draw_FLT_MINMAX would improve this situation.
Date Time Of Last Edit: 2022-02-12 13:47:14
[2022-02-12 15:28:42]
User431178 - Posts: 718
Nothing breaks down, that was a statement of fact relating to how and when the arrays are initialized to 0.

The situation you describe is one where, unless it was mathematically important for zero to actually be zero, FLT_MIN can be useful for displaying 'zero' values, as visually the difference will be imperceptible, unless your study is displaying values in 10^-38 range.

But that is a different issue to comparing highs and lows, which was the original topic.
Date Time Of Last Edit: 2022-02-12 15:30:14
[2022-02-12 16:13:52]
1+1=10 - Posts: 270
The situation you describe is one where, unless it was mathematically important for zero to actually be zero, FLT_MIN can be useful for displaying 'zero' values, as visually the difference will be imperceptible, unless your study is displaying values in 10^-38 range.

I have liked your contributions so please don’t take what follows as a criticism.

Floats are signed so FLT_MIN is a very large negative number. It doesn’t work as an alternative to 0. I reply because I do think sc.DrawFLT_MINMAX would improve ASCIL for an alternative value used to indicate “don’t draw anything on these bars”.
Date Time Of Last Edit: 2022-02-12 16:14:55
[2022-02-12 17:21:42]
User431178 - Posts: 718
Floats are signed so FLT_MIN is a very large negative number. It doesn’t work as an alternative to 0

Please look at the specification for FLT_MIN & FLT_MAX, you will realise that this statement is simply not 100% accurate.
Date Time Of Last Edit: 2022-02-12 17:23:52
[2022-02-12 18:02:31]
1+1=10 - Posts: 270
Please look at the specification for FLT_MIN & FLT_MAX, you will realise that this statement is simply not 100% accurate.

You’re right! FLT_MIN is the smallest POSITIVE value. I think that was a rather unintuitive choice by the C++ committee. This is why I vastly prefer Rust.

Anyway, I wonder what SC will have to say about all this.
[2022-02-12 18:43:23]
1+1=10 - Posts: 270
Of course, if FLT_MIN is close to 0.0 it can’t be used for OP’s idea of higher highs/lows.

And as to whether FLT_MIN is a suitable replacement for 0 when “sc.DrawZeros = 0;” — I suspect in the majority of cases, that it is. As to all the cases, I’m not sure.
[2022-02-12 18:46:22]
User719512 - Posts: 316
I could rewrite my original request to refer to FLT_MAX and -FLT_MAX since referring to FLT_MIN is not correct. That would make this discussion confusion though and the conversation has been useful. I will restate the request in a new reply I will type up shortly.
[2022-02-12 19:37:26]
User431178 - Posts: 718
In many, but obviously not all, circumstances, setting scale type to Same as Region can also negate the issue described in the initial post.
[2022-02-12 21:02:27]
User719512 - Posts: 316
I have included code below that describes the desired behavior and attached 2 files that show the desired study output and also an issue with the values scale (automatic) when a subgraph is set to +/- FLT_MAX.
Maybe the best way to describe the desired result is:
How to create a study that can display -1, 0, 1 when a condition is true and not display anything when the condition is false?
The idea is that +/- FLT_MAX could be used as values Sierra does not plot similar to how sc.DrawZeros can be used to not draw a plot and could be controlled with something like sc.DrawInfinity to preserve existing behavior and enable new functionality.


#include "sierrachart.h"


//
// FLT_MAX_Test
//
SCSFExport scsf_FLT_MAX_Test(SCStudyInterfaceRef sc)
{
SCSubgraphRef Subgraph_SG0 = sc.Subgraph[0];

SCInputRef Input_UseFloatMax = sc.Input[0];


if (sc.SetDefaults)
{
sc.GraphName = "zzz_FLT_MAX_Test";
sc.AutoLoop = 1;
sc.DrawZeros = 1;
sc.GraphRegion = 1;
sc.DrawStudyUnderneathMainPriceGraph = 0;

Subgraph_SG0.Name = "SG0";
Subgraph_SG0.DrawStyle = DRAWSTYLE_POINT;
Subgraph_SG0.LineWidth = 10;
Subgraph_SG0.PrimaryColor = RGB(0,255,0);

Input_UseFloatMax.Name = "Use FLT_MAX";
Input_UseFloatMax.SetYesNo(1);

return;
}


/*
The idea of this test is to have a way that Sierra shows the value scale properly
and also that like how sc.DrawZeros will not display a Subgraph on the chart for 0
we also would like Sierra to not display a Subgraph for FLT_MAX and -FLT_MAX
so Subgraphs can be initialized/used with these extreme values so a study can
display -1, 0, 1 for example during some time periods, and not display
anything during other time periods, like RTH (show) and Globex (hide).

For this example -1, 0, 1 are all valid values and what we want to display when
a given condition is true. There is currently no value you can set
for the Subgraph that will not display anything on the chart when a condition is false and
the study should not diplay anything during that time.

If we think of +/- FLT_MAX as Infinity, then the ask is to have a Subgraph property
like sc.DrawZeros named something like sc.DrawInfinity which could default to
true and not break existing behavior, but would not draw the Subgraphs for
cases 0 and 4 below when false.
*/

int mod = sc.Index % 8;

// When No, use +/- 2 which is really the value/condition we do not want to display.
// As of Sierra v2353, it does not show the values scale properly when we use +/- FLT_MAX.
switch (mod)
{
case 0:
Subgraph_SG0[sc.Index] = Input_UseFloatMax.GetYesNo() ? -FLT_MAX : -2.0f;
break;

case 1:
case 7:
Subgraph_SG0[sc.Index] = -1.0f;
break;

case 2:
case 6:
Subgraph_SG0[sc.Index] = 0;
break;

case 3:
case 5:
Subgraph_SG0[sc.Index] = 1.0f;
break;

case 4:
Subgraph_SG0[sc.Index] = Input_UseFloatMax.GetYesNo() ? FLT_MAX : 2.0f;
break;

default:
break;
}

}

Date Time Of Last Edit: 2022-02-12 21:02:52
imageSierra_FLT_MAX1.png / V - Attached On 2022-02-12 20:57:48 UTC - Size: 78.36 KB - 182 views
imageSierra_FLT_MAX2.png / V - Attached On 2022-02-12 20:58:02 UTC - Size: 39.75 KB - 180 views
[2022-02-12 22:09:50]
1+1=10 - Posts: 270
Cool use of ‘%’ and switches.

One thing that does lend credence to the idea is SC actually uses a similar design pattern in their DTC protocol — link below quote:


In the case of DTC Binary encoding for messages, where message fields are optional, which are not set by either a Client or Server before sending a message, where that field is a numeric type, and where the default value of zero can be interpreted as a valid value, then DTC requires the field be set to its maximum value. The field description will specify this if it applies to that particular field. Otherwise, it does not.

In the case of a double, this will be DBL_MAX.

DTC Messages and Procedures: Indication of Unset Message Fields

I think we can all agree that DBL_MAX / FLT_MAX is at least as natural as 0.0 to indicate the absence of a value in a real—life financial time series.
Date Time Of Last Edit: 2022-02-12 23:42:36
[2022-02-13 15:38:05]
User431178 - Posts: 718
How to create a study that can display -1, 0, 1 when a condition is true and not display anything when the condition is false?

If all you are interested in is the visual effect, I have already presented a very simple solution, one that works within the existing framework.

SCSFExport scsf_FLT_MAX_Test(SCStudyInterfaceRef sc)
{
  SCSubgraphRef Subgraph_SG0 = sc.Subgraph[0];
  
  if (sc.SetDefaults)
  {
    sc.GraphName = "zzz_FLT_MIN_Test";
    sc.AutoLoop = 1;
    sc.DrawZeros = 0;
    sc.GraphRegion = 1;
    sc.DrawStudyUnderneathMainPriceGraph = 0;

    Subgraph_SG0.Name = "SG0";
    Subgraph_SG0.DrawStyle = DRAWSTYLE_POINT;
    Subgraph_SG0.LineWidth = 10;
    Subgraph_SG0.PrimaryColor = RGB(0, 255, 0);

    return;
  }

  int mod = sc.Index % 8;

  switch (mod)
  {
  case 0:
    Subgraph_SG0[sc.Index] = 0;
    break;
  case 1:
  case 7:
    Subgraph_SG0[sc.Index] = -1.0f;
    break;
  case 2:
  case 6:
    Subgraph_SG0[sc.Index] = FLT_MIN;
    break;
  case 3:
  case 5:
    Subgraph_SG0[sc.Index] = 1.0f;
    break;
  case 4:
    Subgraph_SG0[sc.Index] = 0;
    break;
  default:
    break;
  }
}

Anyway, time to bow out now, life is too short.
imageFLT_MIN.png / V - Attached On 2022-02-13 15:35:12 UTC - Size: 30.7 KB - 222 views
[2022-02-13 19:00:23]
User719512 - Posts: 316
If all you are interested in is the visual effect, I have already presented a very simple solution, one that works within the existing framework.

Thank you for that example. I can see that technique coming in handy in other scenarios.

However, that does not work for the real-world study we have. Users should be able to write alerts for the various conditions as well. I suppose an alert for >0 && <1.0 would catch FLT_MIN if you only used -1/FLT_MIN/1, but in our case, valid values are any value (not just price, but +/- percentages), and it is time of day, volume thresholds, delta thresholds, and conditions like that where we want the study to display information or not display information to the chart.
Date Time Of Last Edit: 2022-02-13 19:00:34

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

Login

Login Page - Create Account