Making calculations performance-optimised in EasyLanguage

if you regularly run scripts on a large chart, then you should always care of performance in TradeStation, as EasyLanguage calculations take much time if they are complex and run on large charts.
One of the tricks is that, if you have a code (inside function/indicator/strategy) that sets a variable (that’s calculation is static and doesn’t change across bars- like Chartname, Bartype, etc…) then you should better to call that only once. So, if you have:

if (GetAppInfo(..) and barType = 1) then MyAppName =  SomeFunction() +"Minute";

Of course, there is no mistake, however it’s better to calculate that only once, using:

1st variant

2nd variant

The first approach has one disadvantage:  for example, if you try call this example GetWindowType function (simple type, not series):

Vars:  string name("");
Once If GetAppInfo(aiApplicationType)= 1 then name = "Chart";
GetWindowType = name;

after chart is fully loaded (like in a form or invoking it other ways), then it will give you the empty result. The reason is that the variable (set inside once) will not keep it’s value after chart is loaded, and the next calls will just return the initial-variable value.  If you call that without once, then it’s performance-ugly, to call that same calculation on each bar.

So, the second approach has an advantage – it executes like once in a scope, and after chart-load ( if it is called again) it will return it’s initial value again (as if it was executed newly). Now, look at this optimised version of same function (which will not fail in FORM too):

Vars: string name( iffstring( GetAppInfo(aiApplicationType) = 1 , "Chart", "") );
GetWindowType = name;

Hope that might help you. Let me know your thoughts. (Btw, you might also read : Optimising slow EasyLanguage calculations )

Leave a Reply

Your email address will not be published. Required fields are marked *