|
| Using Scripts |
|
This exercise introduces TekView's scripting interface and covers how to create script for the popular TRIX indicator and insert it into an graph. Begin with opening the Script Editor by selecting Tools / Scripting from the menu. At the top of the form are two pull-down boxes. The one on the left displays modules. The one on the right displays procedures in the selected module. The user can create as many modules as they wish but there must always be one "Global" module. Procedures in all other modules can access the variables and procedures of the Global modules but not of each other. Script is entered in the text section of the form and when debugged and saved can be executed in three ways; by issuing a command from the Command Line on the Script Editor, by inserting with a DS Function or by creating a macro that calls the procedure. Each method is demonstrated in this exercise
First, create a new subroutine called SayHi in the Global module by selecting File / New / Subroutine from the menu. Type in MsgBox "Hi" as shown above. Type the name of the subroutine in the command line and press the execute button and a message box displays Hi. This simple example shows how to execute a procedure from the command line. Next, create a new module named MyIndicator by Selecting File / New / Module from the menu. Then create a new subroutine named CallSayHi and enter the subroutine as shown below.
Notice the module containing procedure must be identified in the command since it is not in the Global module (procedures in the Global module can be called without designating the module). However, you can not call MyIndicator.CallSayHi from another module. Next, enter and execute the code below and notice how the Debug Window opens and displays the printed message. The Debug Window, the message box object and the Command Line are valuable when trying to debug script.
Now copy the following script into the MyIndicator module. The code uses the TekView objects exposed to the script engine to create and return a DataSeries object. This data series can be used by TekView like any other data series when added to DSCollection. Pay particular notice to how the formula string is constructed and other properties of the data series set. See TekView Help for a reference to objects, properties and methods.
Function TRIX(pPeriods) One way of inserting this indicator into the current chart view is with the Scripted DSFunction. Simply type the function call into the CommandString property preceded with an equal sign (e.g., "=MyIndicator.TRIX(20)" without the quotation marks). Then drag the function onto an indicator chart. Another way is to write a subroutine that can be executed by a macro that adds the data series by code as in the following example.
Then create a new macro from the menu by selecting File / New / Macro. Give the macro a friendly name and then in the Command property enter "MyIndicator.InsertTRIX 20" without the quotation marks. Notice that unlike a DSFunction the command is not preceded by an equal sign and the command is in the form of a subroutine call rather than a function (i.e., arguments aren't surrounded by parentheses). |
|
|