Support Board
Date/Time: Wed, 30 Apr 2025 10:47:20 +0000
[Programming Help] - Study won't exit?
View Count: 136
[2025-04-20 18:15:52] |
LTSys2 - Posts: 25 |
For some reason my study won't exit when it hits the section of code with the disconnected message. It just keeps printing that message on a loop. Any ideas? TIA SCSFExport scsf_MainFunction(SCStudyInterfaceRef sc) { if(sc.SetDefaults) { // default settings return; } if(sc.IsFullRecalculation) return; if(sc.Input[0].GetYesNo() == false || sc.LastCallToFunction) { sc.AddMessageToLog("INFO disconnected", 0); return; } } |
[2025-04-21 10:00:06] |
User431178 - Posts: 656 |
What do you mean it won't exit? sc.Input[0].GetYesNo() == false If this evaluates to true and stays that way, the message will print every time the chart updates (and calls the study function). It is exiting the function and being called again and again and again. |
[2025-04-21 14:22:57] |
LTSys2 - Posts: 25 |
If it is false shouldn't the study become disabled and stop? I even added "sc.LastCallToFunction = 1;" into the if statement and it keeps running? I forgot to mention... that input is for the study enabled/disabled setting. if(sc.Input[0].GetYesNo() == false || sc.LastCallToFunction) { sc.AddMessageToLog("INFO disconnected", 0); sc.LastCallToFunction = 1; return; } Date Time Of Last Edit: 2025-04-21 14:26:14
|
[2025-04-21 14:34:14] |
User431178 - Posts: 656 |
If it is false shouldn't the study become disabled and stop?
Not exactly, yes it will return, but not before running the message code. If you place this at the top of the study it would immediately return, i.e. equivalent to disabling it. if(sc.Input[0].GetYesNo() == false) return; But as you have the message code in the same block, that will always run. Maybe consider using a persistent variable/flag that you can set, then only run the message portion if the flag is not set. auto& r_FlagDisabled = sc.GetPersistentInt(0); if(sc.Input[0].GetYesNo() == false || sc.LastCallToFunction) { if (r_FlagDisabled == 0) { sc.AddMessageToLog("INFO disconnected", 0); r_FlagDisabled = 1; } return; } |
[2025-04-21 15:51:46] |
LTSys2 - Posts: 25 |
If you place this at the top of the study it would immediately return, i.e. equivalent to disabling it.
It used to just print the message once and the study stopped. I don't know what changed but now it just keeps calling the main SC function. Even with setting the "sc.LastCallToFunction = 1; " shouldn't it have stopped and exited the code from running? That's what I thought setting that flag would do. |
[2025-04-21 16:35:08] |
User431178 - Posts: 656 |
Even with setting the "sc.LastCallToFunction = 1; " shouldn't it have stopped and exited the code from running? That's what I thought setting that flag would do.
No, do you even bother to read the docs? sc.LastCallToFunction is read-only and set by the study itself. ACSIL Interface Members - Variables and Arrays: sc.LastCallToFunction I don't know what changed but now it just keeps calling the main SC function.
When the study function would be called is also documented: Working with ACSIL Arrays and Understanding Looping: When the Study Function is Called
|
[2025-04-21 16:42:05] |
LTSys2 - Posts: 25 |
My goal is to exit the study and stop the study from running. What's the magical trick that is hidden from all to see. |
[2025-04-21 17:31:10] |
User431178 - Posts: 656 |
My goal is to exit the study and stop the study from running.
You can't, other than returning early, as mentioned above. If the study is on the chart, the study function is called on every chart update, that is just how it is. There's no magical trick. |
[2025-04-21 17:51:08] |
LTSys2 - Posts: 25 |
If the study is on the chart, the study function is called on every chart update
Ok... the enabled or disabled flag (in the examples) doesn't enable or disable anything. All this time I was thinking the study was supposed to be disabled when that flag is set to true. Thanks for the help. |
[2025-04-23 19:59:26] |
ForgivingComputers.com - Posts: 1052 |
You have this: if(sc.Input[0].GetYesNo() == false || sc.LastCallToFunction)
but you don't set sc.Input[0], so it is 0 by default. You need to put this: sc.Input[0].SetYesNo(1);
in the sc.SetDefaults block. |
[2025-04-23 20:06:23] |
LTSys2 - Posts: 25 |
Thanks... I do that. I just commented it out from my example. I copied some SC example that had the input field called 'Enabled' so I just assumed that if you set that to false the study becomes disabled and stops and exits... but I figured out it is just a flag that you can use to skip processing. |
To post a message in this thread, you need to log in with your Sierra Chart account: