Login Page - Create Account

Support Board


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



Post From: User/Source code controlled settings

[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];

}