ScanExpert is a script-based application. Scripts are used to define the grid layout and scripts are used to create the study formulas whose output is displayed in the grid. For the majority of users, learning the scripting language will not be an issue simply because they will use the Wizard to generate all of their grid layouts, and they will derive any custom study formulas they need from within the Wizard as well. However there will be times when you need a new study formula that just cannot be constructed in the Wizard, and the only way to create a new formula is to write a script.
Overview
Before you delve into creating your first study formula or customizing your first user script, you should have a good understanding of how ScanExpert works and what is going on in the background.
For example, lets say that you create a script using the ScanExpert Wizard that calls 10 or so indicators and you run this script in conjunction with a portfolio of 200 securities. When you hit the "Go" button on the toolbar, ScanExpert reaches out and downloads 300+ bars of historical data for each security (that's 60,000 bars in this example), calculates the values for each of the indicators you have selected for each bar of each symbol (that's 2000 individual indicators in this example), and then updates the price bars several times per second for each symbol (and updates each associated indicator) going forward in realtime. And it does all of this very quickly and with minimal impact on your CPU utilization. To keep things in perspective, try loading 200 charts, each chart with 10 indicators, in your favorite charting package and see how far you get!
ScanExpert can do this because internally it is very efficient. It makes use of a built-in compiler to translate all user scripts and study formulas into machine language units, and it is heavily threaded which means several groups of symbols and indicators can be updating at the same time. Given the large amounts of data it must process (see our example above) it has to be efficient. In order to keep things running smoothly, it is critical that any custom study formulas that you write are also as efficient as possible. Now customizing a user script or creating a new study formula in ScanExpert is not particularly difficult, however it cannot be treated lightly because a poorly written user script or study formula can bring ScanExpert to its knees. The fewer lines of code that you can use to get the job done, the better. Please keep this in mind going forward.
Another point that deserves mentioning is programming style. If you have done any eSignal EFS programming then you are probably accustomed to including any user-defined functions and/or study formulas directly in your EFS script....basically the whole ball of wax is wrapped into that single script. This is perfectly acceptable in the EFS environment since efficiency is not paramount. The EFS script is probably only going to be run in a handful of charts and, because EFS is an interpreted language, offloading user-defined functions and/or formulas to separate processes is not really an option. In ScanExpert, however, the opposite is true. Your user scripts should be as light and trim as possible. Custom calculations should be implemented as separate study formulas whenever possible. The more code you pile into your ScanExpert user script, the greater the speed and performance penalty you will incur.
Scripting Language
The scripting language used in ScanExpert is a subset of Pascal. Pascal was developed in 1970 by Nicholas Wirth and was intended as a language to teach students structured programming. In fact, many of you may have run across the Pascal language while you were in school. It is beyond the scope of this user guide to describe the Pascal language in detail or to teach you how to program. Suffice it to say that there are a number of excellent resources on the web for technical information on the Pascal language as well as tutorials on its use (search on Google™ for the term 'pascal tutorials'). In addition, the subset of the Pascal language used in ScanExpert is relatively tame and straightforward, and by examining the scripts generated by the ScanExpert Wizard as well as the source code files for the study formulas that ship with ScanExpert, you should get up to speed very quickly.
All of the ScanExpert script and study formula files are simple text files containing Pascal source code and saved with a .pas file extension. These files can be opened in any text editor and can be easily printed as well. If you are a programmer and have a favorite editor then you can certainly use that editor when creating or editing study formulas for ScanExpert. However the ScanExpert Editor has a built-in Syntax Check feature that can save you a lot of grey hairs so, at the very least, run any scripts or study formulas through the Editor Syntax Check feature even if you do the actual coding work in another editor. When developing/testing study formulas you should also make use of the debugPrint() function which will send output to the Debug Window in the ScanExpert Viewer module.
Note: Never test anything in the ScanExpert Viewer Grid without first running it though the Syntax Check feature in the Editor.
User Script Development
By "user script" we mean the pascal scripts used to define the layout of the ScanExpert Viewer Grid. These will almost always be created by the ScanExpert Wizard and there will be very few instances, if ever, that you will need to write one of these from scratch. In fact, even if you did decide to create a completely custom user script the best place to start would be to generate a "shell" script using the Wizard and then just fill in the missing pieces using the ScanExpert Editor.
Study Formula Development
By "study formula" we mean the pascal source files that contain the logic for various technical analysis indicators. There is no "Wizard" application available for the purpose of creating new study formulas so you will have to get your hands dirty and delve into the Pascal language if you intend to implement new ones. The good news is that almost any new study that you will need to develop will most likely be very close in style and design to a study formula that already exists in the ScanExpert Studies folder. In most cases you will simply need to find an existing study formula that is close in content and operation to the new study formula that you need to create, save it under a new name, and add in the new logic pieces using the Editor. It is unlikely that you will ever have to write a study formula completely from scratch.
Considerations
As mentioned above, ScanExpert does not make use of an interpreter to process the Pascal script files. Rather it uses an internal compiler to generate object code (machine language) from the Pascal source files and this object code is then executed in memory. This makes for a much faster and more efficient application when compared with the interpreter approach, but it also makes for a somewhat less forgiving programming environment.
Before you run any custom-written study formula or user script through the ScanExpert program, make sure that you check your work thoroughly and, at the very least, run it through the Syntax Check process in the Editor. ScanExpert has a layer of checks and balances in place to protect itself from most scripting errors but, at the same time, there are certain commands and constructs that ScanExpert will accept and these may, in turn, either lock up the ScanExpert application or cause it to generate a lengthy stream of error messages. A couple of examples of these would be while loops that are not incremented correctly (i.e., endless loop) or referencing objects that either don't exist or have been freed.
The bottom line is that you need to be careful when developing and testing any study formulas that you create and always double-check your work. When testing a new study formula in the ScanExpert Viewer Grid, it is advisable to start off with a small portfolio of symbols (at most 2 or 3) and use the Wizard to generate a small script that only calls your new study formula. Once you are comfortable that it is working correctly, you can test it in a larger script that references other study formulas and use a larger portfolio. Also, be sure to test all new study formulas on different bar intervals.
Once you have thoroughly tested your study formula, you can compile it into an object file if you wish (.dgx file extension). The only purpose this serves is to effectively hide the source code from prying eyes. All study formulas are compiled into machine code at runtime anyway so there is no performance gain associated with pre-compiling study formulas. ScanExpert looks for study formulas with either a .dgx or .pas file extension at runtime and will always load the .dgx object file if both versions exist.
Note: Only study formulas can be pre-compiled into .dgx object files. User scripts cannot be pre-compiled. See the ScanExpert User Guide.