Exiting a function

Questions about MultiCharts and user contributed studies.
janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Exiting a function

Postby janus » 08 Mar 2010

Is there by any chance an undocumented command to exit a function from any point within that function?

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 09 Mar 2010

Would be nice, wouldn't it?

Currently, it would be necessary to use regular flow control statements (if, while, etc.) to do this. Other languages usually have a way to do this e.g. in Delphi/Pascal "Exit;" or in C++/C# "return;" or in VB "Exit Function". This behavior is a holdover from EasyLanguage, which doesn't have a way to do it either.

There also are ways to abort e.g. Abort; or RaiseRuntimeError("Your mileage may vary"); but these status disable the calling study, rather than simply exiting the function alone.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 09 Mar 2010

I would also like a command to exit a study. It would be useful in situations where there is some EL code you only want to execute if the study is only being executed during a timer call rather than a tick call. So maybe this exit study command could be included if TSS ever puts in those features for executing a study on changes in bid/ask and timer calls (meaning every 1 second for example). Also if the study can some how in the future have commands to figure out if it is being executed late (meaning it is having trouble keeping up with the rate that the ticks are coming in to MC during very fast markets) then the trader may want to bypass this study (testing for this at the very top of the study if lastbaronchart is true).

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 09 Mar 2010

Thanks, I thought it was just wishful thinking. I already use all those other approaches, plus a few of my own, such as spawn_message, which spawns another process to display a windows message (to avoid hanging the study), alert messages to my own catch-all console app, writing messages to log files for auditing and debugging purposes, an exit handler to cleanup my dll variables and workspace, etc., etc.

For now, I'll just have to resort to indenting large sections of my code and skip over them using appropriate conditional if statements.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 09 Mar 2010

Also if the study can some how in the future have commands to figure out if it is being executed late (meaning it is having trouble keeping up with the rate that the ticks are coming in to MC during very fast markets) then the trader may want to bypass this study (testing for this at the very top of the study if lastbaronchart is true).
Now that would be nice. I already have a use for that feature! At the moment I funnel some of my studies to a master dll to decide the order of execution under certain circumstances. Some of my studies are dependent on others.

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 09 Mar 2010

For now, I'll just have to resort to indenting large sections of my code and skip over them using appropriate conditional if statements.
Just as a stopgap measure, you may also find it useful rather than having many levels of indented ifs in EL and to keep it pretty linear in its execution flow, to do something like:

variables: DoAbort(false);
DoAbort = false;

if (DoAbort = false) then
begin
...
if foo >= bar then DoAbort = true;
end;

if (DoAbort = false) then
begin
...
end;

etc. to avoid too many levels of nested indentation.

I've seen some quite indented EL code in my time, and trust me when I say that when you come across a line that looks like "end; end; end; end; end; end; end; end; end; end; end;" at the tail of it and there's something mismatched somewhere above, it's a mess to figure out who left what out of the mix.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 09 Mar 2010

I've seen some quite indented EL code in my time, and trust me when I say that when you come across a line that looks like "end; end; end; end; end; end; end; end; end; end; end;" at the tail of it and there's something mismatched somewhere above, it's a mess to figure out who left what out of the mix.
Way before I have that many "end;" statements, I would break up the code into functions. The most I would ever have is around 3 levels of indents. beyond that it reminds me of my old days of writing spaghetti code in FORTRAN and C, which leads to other bad practices, which I do not like to recall, which, ..... never mind. :cry:

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 09 Mar 2010

It isn't something I would do either, but not uncommonly it's necessary for me to figure out what someone else has done incorrectly, and exposure to different coding styles gives one a sense of perspective on how wrongly things can go, even just in EL.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 09 Mar 2010

Here is something to consider when you get those large indented if statements. I just started using it about 2 weeks ago. Works well. I also find it handy for copying code from 1 minute bar functions to 10 second bar functions in that I keep the same code number.

http://forum.tssupport.com/viewtopic.php?t=7142


Return to “MultiCharts”