Login Page - Create Account

Support Board


Date/Time: Mon, 06 May 2024 01:19:42 +0000



[Programming Help] - Float value truncated / simplified.

View Count: 1101

[2020-08-21 17:33:48]
User92573 - Posts: 484
Dear Support / forum I'm struggling with a conversion.

Any assistance appreciated.

This is a typical example and what I'd like is the values displayed in the Tool Values Window on a bar by bar basis. As is the case with the current float value.



SCSFExport scsf_FloatToString(SCStudyInterfaceRef sc)
{

SCSubgraphRef Subgraph_Value1 = sc.Subgraph[0];
SCSubgraphRef Subgraph_Value2 = sc.Subgraph[1];

if (sc.SetDefaults)
{


Subgraph_Value1.Name = "Value 1";
Subgraph_Value1.DrawStyle = DRAWSTYLE_IGNORE;

Subgraph_Value2.Name = "Value 2";
Subgraph_Value2.DrawStyle = DRAWSTYLE_IGNORE;

Input_ATRLength.Name = "ATR Length";
Input_ATRLength.SetInt(10);

return;

}

// Do processing

// ATR example

sc.ATR(sc.BaseDataIn, Subgraph_ATR, Input_ATRLength.GetInt() - 1, MOVAVGTYPE_SIMPLE);


float atrOneBarAgo = 0.0f;
?string? strOneBarAgo = "0"; // I want the float value presented in this string variable to 1 or 2 places after the point (obviously the code here is incorrect also)


atrOneBarAgo = Subgraph_ATR[sc.Index - 1]; // for example is 1.1234
strOneBarAgo = "?atrOneBarAgo?"; // 1.1 or 1.12 is the outcome I'm trying to achieve


sc.Subgraph[0]= atrOneBarAgo;
sc.Subgraph[1]= strOneBarAgo;


}


Many thanks
[2020-08-24 20:13:15]
User907968 - Posts: 802
You could use these functions
SCString::Format()

SCString::AppendFormat()

described here -
ACSIL Programming Concepts: SCString Methods

printf as reference in the above functions -

https://www.cplusplus.com/reference/cstdio/printf/
Date Time Of Last Edit: 2020-08-24 20:14:43
[2020-08-25 10:02:15]
User92573 - Posts: 484
That was a great help, Thank you.

However, it may be that as usual Sierra have already provided a simple solution - but - in my case it doesn't seem to want to work.

sc.ValueFormat = 2;

Ought to do exactly what I want except for the fact that when I recompile to code and reload the study "Settings >> ValueFormat = "Inherited".

I cannot seem to programmatically get the following instructions:

sc.ValueFormat

Type: Read/Write integer variable.

Initial value: 2.

sc.ValueFormat sets the numeric display format for all values in the sc.Subgraph[].Data arrays for the study. This can be one of the following values:

0 = Zero decimal places. Example output: 1
1 = One decimal place. Example output: 0.1
2 = Two decimal places. Example output: 0.01

... to set the study subgraphs to 0.01, or in ACSIL = 2.

    sc.GraphName = "ATR";
    sc.ValueFormat = 2;
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;
    sc.ScaleRangeType = SCALE_AUTO;

Still results in ValueFormat = "Inherited".

Any thoughts?

Many thanks.
[2020-08-25 10:45:26]
User907968 - Posts: 802
Yes, I seem to have answered a different question to the one you actually asked... Thought you wanted to do something with strings and numbers, hence my reply.

You have already found the correct information, sc.ValueFormat, why it isn't working for you I don't know, it certainly behaves as expected for me.

Have you previously saved any default setting for the study? You could try, 'Reset Defaults' on the study settings page.
[2020-08-25 13:49:33]
User92573 - Posts: 484
I had considered using strings as that would have enabled me to truncate; switch; if/then; a series of statements to get the desired outcome. So, the information you provided was excellent and will be of great value as I move forwards.

The issue/failure I'm having with:

sc.ValueFormat = 2;
Is that even with:

Subgraph_ATR.DrawStyle = DRAWSTYLE_IGNORE;
Subgraph_ATR.DrawStyle = DRAWSTYLE_HIDDEN;
and

sc.ScaleRangeType = SCALE_INDEPENDENT;// or SCALE_AUTO;
I can only set

sc.ValueFormat = 2; // in
sc.GraphRegion = 1; // or that is, any region except 0 which given its hidden/ignored is where I wanted it.

Ideally, I didn't want another region below the main graph that needed to be closed down.

If you have any thoughts I'd be really interested.

PS I should add that although ACSIL will not allow me to set Region = 0 if I want to use "sc.ValueFormat = 2", I can manually select Graph Region 1 in settings after the study has been applied.
Just not via ACSIL.


Many thanks.
Date Time Of Last Edit: 2020-08-25 14:02:30

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

Login

Login Page - Create Account