Login Page - Create Account

Support Board


Date/Time: Fri, 14 Mar 2025 19:09:22 +0000



[Programming Help] - User/Source code controlled settings

View Count: 1128

[2022-01-29 23:46:16]
Csurles2010 - Posts: 13
Hello everyone,

I'm trying to use source code to control draw styles. I also want to change the settings manually, as needed. Is there a way to do both? Control draw styles with source code and change study window settings manually? Once the source code changes the draw styles, user inputs have no effect.

Any help is greatly appreciated
Here is the code I have so far. It does what I need it to do. However, I can't change them manually.


    if (ShowRectangle.GetYesNo())
    {
      sc.Subgraph[1].DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_RECTANGLE_TOP;
      sc.Subgraph[2].DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_RECTANGLE_BOTTOM;

    }
    else
    {
      sc.Subgraph[1].DrawStyle = DRAWSTYLE_DASH;
      sc.Subgraph[2].DrawStyle = DRAWSTYLE_DASH;

[2022-01-30 05:51:29]
1+1=10 - Posts: 270
It’s hard to say what’s going on without more code. If what you’re trying to do is set a DRAWSTYLE only when the study is initially called, then you just need to move that code into an if (sc.Index == 0) { … } block. You’ll be able to change it manually and your study won’t rewrite the updated setting as the sc.Index should never be 0 again.

If you’re trying to do something else, please explain more.
[2022-01-30 16:35:22]
ForgivingComputers.com - Posts: 1021
Here is the code I have so far. It does what I need it to do. However, I can't change them manually.

Make sure the code is in the sc.SetDefaults block.

ACSIL Interface Members - Variables and Arrays: What Should Be Located in the sc.SetDefaults Code Block
Setting of defaults must be done in the sc.SetDefaults code block because otherwise when the settings are changed through the Study Settings window for the study, those changes will get reverted back to what the study function is setting them to if the code to change the sc.Subgraph, sc.Input and other settings is done outside of the sc.SetDefaults code block.

[2022-02-05 21:23:22]
Csurles2010 - Posts: 13
Thank you for responding. I moved the code into an if (sc.Index == 0) {} block and it had the same affect. It seems if a code to modify drawstyles is outside of the sc.SetDefaults block, then drawstyles can't be manually changed in the study settings window.

I wanted an input to change drawstyles, rather than manually change each subgraph. I have a bool that if true, it draws rectangles. When it's false the subgraph draw style is a dashed line. I can change this to yes or no inside the settings and inputs window. It will draw rectangle or dashed line.

This works as I want it, however, I can only ever have a rectangle or dashed line. I can't manually change to say, a solid line, in the subgraph settings window. The source code will always overwrite any manual changes in the settings window.
[2022-02-05 21:42:45]
1+1=10 - Posts: 270
One alternative I didn’t think of earlier is to use the custom string input type. For every drawstyle type you anticipate using you can have a custom string — e.g. “Line” to represent DRAWSTYLE_LINE.

Then outside of setDefaults you can get the input_selected_string which returns an int which can be sent to a switch statement or if/elif/elif chain.

Docs: ACSIL Interface Members - sc.Input Array: sc.Input[].SetCustomInputStrings()
[2022-02-05 21:55:18]
Csurles2010 - Posts: 13
I created a new input

SCInputRef Input_SourceCodeControlledSettings = sc.Input[0];

Then I put the code inside this block

if (Input_SourceCodeControlledSettings.GetYesNo()) {...}

If the input is true, the source code controls the settings and manual changes have no effect. If the input is false, the settings are intialized from sc.SetDefaults and I can change settings manually. The purpose of this code was to save time. I can change several subgraph styles with a toggle instead of manually changing each one back and forth.
[2022-02-05 22:08:57]
1+1=10 - Posts: 270
Right. You can do the same thing with the InputStrings.

Your input will as many strings as you want representing as many Drawstyles as you want.

Then in your study whichever “Drawstyle” string input you chose in the input can be applied to all the subgraphs the same way you’re doing right now.

I’m working but at some point I’ll send you an example.
[2022-02-05 22:39:33]
Csurles2010 - Posts: 13
Thank you much for your help. It's weird. It seems source code will always overwrite changes made in settings window. I read the settings window is populated from sc.SetDefaults and it's initialized only once. When changes to draw styles, colors, etc, are made in source code, manual changes won't have an effect. I was looking for a workaround, to allow source code "adjusted" settings as well as allow manual changes in subgraph settings window.

I initialize default settings and colors. I also programmatically change them. It seems we can't do both, control settings manually and programmatically? Once we code the settings outside of sc.SetDefault, they can only ever be changed again with source code?
Date Time Of Last Edit: 2022-02-05 22:44:39
[2022-02-06 00:53:50]
1+1=10 - Posts: 270
Once I actually focused on your issue it turned out what you're hoping for can be done, but it involves making inputs choosing whether the DrawStyle for a particular subgraph or group of subgraphs is controlled by the study or manually. Also, if you choose to have the study control the DrawStyles for a group of subgraphs, then it is possible for the study's DrawStyle selection input to have more than 2 choices. For example, the below working study has 3 example subgraphs and is capable of the following actions:

1. The first input chooses whether to control all subgraph DrawStyles manually.
2. The second input chooses whether to control the 1st subgraph's DrawStyle is chosen manually.
3. The third input is used to control any non-manually controlled Drawstyles and is capable of Line, Bar, or Square, although any drawstyle could be added to the list.

As a side note, yes, that is correct that sc.SetDefaults is only called once. It is not even called when you "apply/ok" a study settings window.


SCSFExport scsf_SubgraphsDrawStyle(SCStudyGraphRef sc)
{
SCInputRef should_select_subgraph_drawstyles_manually = sc.Input[0];
SCInputRef should_select_out1_subgraph_drawstyle_manually = sc.Input[1];
SCInputRef select_drawstyle_for_multiple_subgraphs = sc.Input[2];

SCSubgraphRef out1 = sc.Subgraph[0];
SCSubgraphRef out2 = sc.Subgraph[1];
SCSubgraphRef out3 = sc.Subgraph[2];

if (sc.SetDefaults)
{
sc.GraphName = "DrawStyle Example";
sc.GraphRegion = 1;

sc.AutoLoop = 1;

should_select_subgraph_drawstyles_manually.Name = "Should we select all subgraph drawstyles manually?";
should_select_subgraph_drawstyles_manually.SetYesNo(false);
should_select_out1_subgraph_drawstyle_manually.Name = "Should we select out1 drawstyle manually?";
should_select_out1_subgraph_drawstyle_manually.SetYesNo(false);
select_drawstyle_for_multiple_subgraphs.Name = "Select a drawstyle to use for multiple subgraphs:";
select_drawstyle_for_multiple_subgraphs.SetCustomInputStrings("Line;Bar;Square"); // IMPORTANT: You can add as many drawstyle names as you want here. For every string you must add a case statement below to set the Drawstyles according to these strings.
select_drawstyle_for_multiple_subgraphs.SetCustomInputIndex(1); // This is the index of the selected string drawstyle in the above 0- indexed "array". So entering 0 would select "Line", while 1 selects "Bar".

out1.Name = "out1";
out1.PrimaryColor = RGB(0,255,0);
out2.Name = "out2";
out2.PrimaryColor = RGB(255,0,0);
out3.Name = "out3";
out3.PrimaryColor = RGB(255,255,255);

}

// NOTE: This must be outside of sc.SetDefaults
if ( !should_select_subgraph_drawstyles_manually.GetYesNo() )
{
switch (select_drawstyle_for_multiple_subgraphs.GetIndex())
{
// IMPORTANT: For every drawstyle string you add above you must add a case where where you actually set the Drawstyles.
case 0: // Line
if( !should_select_out1_subgraph_drawstyle_manually.GetYesNo() )
out1.DrawStyle = DRAWSTYLE_LINE;

out2.DrawStyle = DRAWSTYLE_LINE;
out3.DrawStyle = DRAWSTYLE_LINE;

// If you had more than a few subgraphs you could use:
// for(int subgraph_idx = 0; subgraph_idx < # subgraphs; subgraph_idx++) {
// sc.Subgraph[subgraph_idx].DrawStyle = DRAWSTYLE_LINE
//}

break;
case 1: // Bar
if( !should_select_out1_subgraph_drawstyle_manually.GetYesNo() )
out1.DrawStyle = DRAWSTYLE_BAR;

out2.DrawStyle = DRAWSTYLE_BAR;
out3.DrawStyle = DRAWSTYLE_BAR;
break;
case 2: // SQUARE
if( !should_select_out1_subgraph_drawstyle_manually.GetYesNo() )
out1.DrawStyle = DRAWSTYLE_SQUARE;

out2.DrawStyle = DRAWSTYLE_SQUARE;
out3.DrawStyle = DRAWSTYLE_SQUARE;
break;
}
}

// Example outputs
out1[sc.Index] = sc.High[sc.Index];
out2[sc.Index] = sc.Low[sc.Index];
out3[sc.Index] = sc.Close[sc.Index];

}

[2022-02-06 00:55:12]
1+1=10 - Posts: 270
Sorry about the long-width strings. My IDE, VSCode automatically wraps them so I didn't realize they'd post that way.
[2022-02-06 03:20:25]
Csurles2010 - Posts: 13
Thank you. I didn't think to use a switch. It seems the key is to have a toggle for "script control" or "manual control". Using the switch I can toggle between styles. Then I can turn off "script control" and the styles save and I can change settings from the study settings window.
[2022-02-06 12:54:04]
1+1=10 - Posts: 270
My pleasure! Programming within the constraints of ACSIL definitely is different because sometimes I’m not exactly sure how the pieces fit together.

For instance, I initially thought sc.SetDefaults was called whenever you modified the study settings so I put the switch statement at the end of it but it didn’t work.

Anyway, good luck with your trading!
[2022-02-10 02:09:17]
Csurles2010 - Posts: 13
Thank you. It confused me as well. I read that sc.SetDefaults is called once when the study is added to the chart. Then it's not called anymore unless the study is removed and added again. The confusing part is that once source code controls settings like draw, color, etc., then changes in the study window have no effect. For now the switch is a great work around. Thank you for that suggestion.
[2022-06-28 07:23:12]
User92573 - Posts: 548
Hi, I found this thread really helpful however any thoughts as to why it won't compile correctly for me?

#include "sierrachart.h"
#include "scstudyfunctions.h"

SCDLLName("ManuallyAndProgrammatically_ChangeDrawStyle_Example")

//SCSFExport ManuallyAndProgrammatically_ChangeDrawStyle_Example(SCStudyInterfaceRef sc)
SCSFExport ManuallyAndProgrammatically_ChangeDrawStyle_Example(SCStudyGraphRef sc)
{

  SCInputRef should_select_subgraph_drawstyles_manually = sc.Input[0];
  SCInputRef should_select_out1_subgraph_drawstyle_manually = sc.Input[1];
  SCInputRef select_drawstyle_for_multiple_subgraphs = sc.Input[2];

  SCSubgraphRef out1 = sc.Subgraph[0];
  SCSubgraphRef out2 = sc.Subgraph[1];
  SCSubgraphRef out3 = sc.Subgraph[2];


  if (sc.SetDefaults)
  {
    sc.GraphName = "Man and Prog Change DrawStyle Example";
    sc.GraphRegion = 1;
    
    sc.AutoLoop = 1;

    should_select_subgraph_drawstyles_manually.Name = "Should we select all subgraph drawstyles manually?";
    should_select_subgraph_drawstyles_manually.SetYesNo(false);
    should_select_out1_subgraph_drawstyle_manually.Name = "Should we select out1 drawstyle manually?";
    should_select_out1_subgraph_drawstyle_manually.SetYesNo(false);
    select_drawstyle_for_multiple_subgraphs.Name = "Select a drawstyle to use for multiple subgraphs:";
    select_drawstyle_for_multiple_subgraphs.SetCustomInputStrings("Line;Bar;Square"); // IMPORTANT: You can add as many drawstyle names as you want here. For every string you must add a case statement below to set the Drawstyles according to these strings.
    select_drawstyle_for_multiple_subgraphs.SetCustomInputIndex(1); // This is the index of the selected string drawstyle in the above 0- indexed "array". So entering 0 would select "Line", while 1 selects "Bar".


    out1.Name = "out1";
    out1.PrimaryColor = RGB(0,255,0);
    out2.Name = "out2";
    out2.PrimaryColor = RGB(255,0,0);
    out3.Name = "out3";
    out3.PrimaryColor = RGB(255,255,255);
    
    return;

  }

// NOTE: This must be outside of sc.SetDefaults

  if (!should_select_subgraph_drawstyles_manually.GetYesNo())
  {
    switch (select_drawstyle_for_multiple_subgraphs.GetIndex())
    
    {
      // IMPORTANT: For every drawstyle string you add above you must add a case where where you actually set the Drawstyles.

      case 0: // Line
        if( !should_select_out1_subgraph_drawstyle_manually.GetYesNo() )
          out1.DrawStyle = DRAWSTYLE_LINE;

        out2.DrawStyle = DRAWSTYLE_LINE;
        out3.DrawStyle = DRAWSTYLE_LINE;

        // If you had more than a few subgraphs you could use:
        // for(int subgraph_idx = 0; subgraph_idx < # subgraphs; subgraph_idx++) {
        // sc.Subgraph[subgraph_idx].DrawStyle = DRAWSTYLE_LINE
        //}
        break;
        
      case 1: // Bar
        if( !should_select_out1_subgraph_drawstyle_manually.GetYesNo() )
          out1.DrawStyle = DRAWSTYLE_BAR;

        out2.DrawStyle = DRAWSTYLE_BAR;
        out3.DrawStyle = DRAWSTYLE_BAR;
        break;

      case 2: // SQUARE
        if( !should_select_out1_subgraph_drawstyle_manually.GetYesNo() )
          out1.DrawStyle = DRAWSTYLE_SQUARE;

        out2.DrawStyle = DRAWSTYLE_SQUARE;
        out3.DrawStyle = DRAWSTYLE_SQUARE;
        break;
    }  
  }  
    
  // Example outputs
  out1[sc.Index] = sc.High[sc.Index];
  out2[sc.Index] = sc.Low[sc.Index];
  out3[sc.Index] = sc.Close[sc.Index];


} // This block is broken but cannot see why?


Error is:

No study functions present

Many thanks
[2022-06-28 15:58:22]
Tony - Posts: 553
I think a study name always starts with "scsf_"

so in your code, try:

SCSFExport scsf_ManuallyAndProgrammatically_ChangeDrawStyle_Example(SCStudyGraphRef sc)

instead.
[2022-06-29 06:17:37]
User92573 - Posts: 548
Hi, Tony

Many thanks, I missed that when I changed the name. Absolutely correct but it still doesn't seem to work.

Error is:
No study functions present

Out of interest have you compiled the example?
[2022-06-29 06:27:43]
User92573 - Posts: 548
Okay solved. The AV was messing with the compile.
All working as example.
Many thanks.
[2022-06-29 06:47:25]
User92573 - Posts: 548
1+1=10

Thank you for providing such an excellent example and solution to the problem presented.
This was really helpful.

Many thanks
[2022-06-29 14:39:19]
JohnR - User831573 - Posts: 319
Here are a few other things to consider.

ACSIL Interface Members - Variables and Arrays: sc.SetDefaults

What Should Be Located in the sc.SetDefaults Code Block
2-> Setting of defaults. For example, you will want to set properties of a sc.Subgraph[] like the sc.Subgraph[].DrawStyle and the colors. You will want to set default study Input values with the sc.Input[].Set* functions. Setting of defaults must be done in the sc.SetDefaults code block because otherwise when the settings are changed through the Study Settings window for the study, those changes will get reverted back to what the study function is setting them to if the code to change the sc.Subgraph, sc.Input and other settings is done outside of the sc.SetDefaults code block.
7-> When using ACSIL Functions within the sc.SetDefaults code block and those functions interact with the chart, they will have no effect. They will return and do nothing.

There is also a section in the doc describing different conditions of when a study is called.
Working with ACSIL Arrays and Understanding Looping: When the Study Function is Called

JohnR

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

Login

Login Page - Create Account