Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 06:28:47 +0000



[Programming Help] - Can SetCustomStudyControlBarButtonEnable be put in sc.SetDefaults ?

View Count: 212

[2024-01-02 13:48:46]
BenjFlame - Posts: 324
Can I put


sc.SetCustomStudyControlBarButtonEnable(SellEntryButtonId, 0);
sc.SetCustomStudyControlBarButtonText(SellEntryButtonId, "Short");

in sc.SetDefaults to set default state of buttons ?
[2024-01-02 22:33:46]
PS2004 - Posts: 47
Hi!
I recomment you to write a test Study for every question like this and try it out yourself!
Although it is possible as of 02/01/2024, SC version 2569.
Greetings,
PS
[2024-01-03 09:19:07]
BenjFlame - Posts: 324
Thanks.
If something works it might still be bad practice and not recommended, thus such question.
[2024-01-03 10:11:58]
PS2004 - Posts: 47
I like to do everything which is Button or MenuItem related outside the sc.SetDefaults block.
There are two main reasons for this:

1. Because of this part of the documentation here: ACSIL Interface Members - Variables and Arrays: sc.SetDefaults
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.
I don't necessarily think that this applies for the CS Buttons too, since it works, but just to be sure.

2. This maybe not applies for your specific case, but here is another quote from this part of the documentation:
If you modify the source code for a study and rebuild the DLL when an instance of the study is on a chart and the chart is open, and you do not remove the study from the chart and add it again, then all of the default settings like Input and Subgraphs settings in the sc.SetDefaults code block will not change back to defaults. They will remain as they were previously were.
This means that if you modify the code and rebuild it, during the development phase, and as you should, you specify an sc.LastCallToFunction block which resets the name of the Buttons, it won't be renamed. Thus if you include the naming of the Button in the sc.SetDefaults block, you need to write the same code elsewhere for a fluid development process.

My method: I use a persistent variable called "runOnce", which runs only once, then never again, until the Study is closed/rebuilded, etc. In that "runOnce" block, I initialize every MenuItem, Button, etc.

I hope this helps!

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

Login

Login Page - Create Account