Using the DEFMACRO Statement from the Command Line

 

The DEFMACRO function can be used to define macros at the command line. DEFMACRO has slightly different syntax than #define:

 

defmacro("name(arg1, arg2, ..., argn)", "expansion", quote_type)

 

where:

name is a string (up to 15 characters long),

argn are arguments (n <= 10),

expansion is an equation incorporating the arguments that is evaluated when the macro is called, and

quote_type is an integer specifying the type of quotes that will be placed around the result. 1=no quotes, 2=single quotes, 3=double quotes.

 

For example, to define a constant value, MyMultiplier:

 

defmacro("MyMultiplier", 15, 1)

 

MyMultiplier is defined as the constant value, 15. Typing W1*MyMultiplier returns a series where each point in the series is the point from W1 multiplied by 15.

You can also define a constant value which is the result of a function:

 

defmacro("MyConstRMS", rms(curr), 1)

 

Type MyConstRMS, and it returns the RMS value of the current window. MyConstRMS is also defined in the macro sheet as that constant value, so if you move to another window and type MyConstRMS, the same value would be echoed at the status line, regardless of the series in the window.

To define a macro that depends upon a window and is evaluated each time it is called, use quotes around the expression:

 

defmacro("MyRMSVal", "rms(curr)", 1)

 

Move to Window 1 and type MyRMSVal, and it returns the RMS value from W1; move to Window 2 and type MyRMSVal, and it returns the RMS value from W2.

The third argument to the DEFMACRO function, quote_type, allows you to define string macros.

For example:

 

defmacro("Dt" , getdate(curr) , 2)

 

Type dt at the command line, and the date when the series was acquired (or generated) is echoed on the status line. In the macro sheet, it is defined as a string surrounded by single quotes, e.g. '1-20-1986'.

If you had defined Dt as follows:

 

defmacro("Dt" , getdate(curr) , 1)

 

and the date acquired was January 20, 1986, then Dt would be defined as: 1-20-1986 (without the quotes). Type dt at the command line, and the value -2005 will be echoed on the status line (1-20-1986 = -2005). The quote_type argument is important; it determines how the macro is defined and interpreted.