AmiBroker Formula Language (AFL)

AFL 1.1 Reference Manual

Document history:
(Revision 1.2 - Jan 17th, 2000 - re-edited )
(Revision 1.1 - Feb 28th, 1999 - added AFL 1.1 functions)
(Revision 1.0 - Jan, 1999 - created)

Note: AFL 1.1 specification is fully supported by AmiBroker 3.0, 3.1 and 3.2. Previous specifiaction (AFL 1.0) applies to AmiBroker 2.9beta.

Introduction

AFL is a special programming language used to define and create custom indicators, analyses and simulation tests and guru commentaries. Unfortunatelly it is not compatible with previous Rule Definition Language used by pre-2.9 releases of AmiBroker. However it is very easy to port all formulas to a new language.

Basics

Lexical elements

This chapter describes the different categories of word-like units (tokens) recognized by the AFL language interpreter.

Whitespace

Whitespace is the collective name given to spaces (blanks), tabs, newline characters and comments. Whitespace can serve to indicate where tokens start and end, but beyond this function, any surplus whitespace is discarded.

Comments

Comments are pieces of text used to annotate a program. Comments are for the programmer's use only; they are stripped from the source code before parsing. The are two ways to delineate comments: C-like comments and C++ like comments. A C-like comment is any sequence of characters placed after the symbol pair /*. The comment terminates at the first occurence of the pair */ following the initial /*. The entire sequence, including the four comment-delimiter symbols, is replaced by one space. A C++ like comments are single-line comments that start by using two adjacent slashes (//) in any position within the line and extend until the next new line.

AFL does not allow nested comments.

Tokens

AFL recognizes five classes of tokens:

Identifiers are arbitrary names of any length given to functions and variables. Identifiers can contain the letters (a-z, A-Z), the underscore character ("_"), and the digits (0-9). The first character must be a letter.
AFL identifiers are NOT case sensitive.

Constants are tokens representing fixed numeric or character values. Numeric constants consist of decimal integer and optionally: decimal point and decimal fraction part. Negative numeric constants have unary minus (-) prefixed.
String constants, aslo known as string literals, form a special category of constants used to handle fixed sequences of characters and are written as a sequence of any number of characters surrounded by double quotes:

"This is literally a string"

The null (empty) string is written "". The characters inside the double quotes can include escape sequences ("\n" - a new line escape sequence).

A Constant expression is an expression that always evaluates to a constant. They are evaluated just as regular expressions are.

Punctator (also known as separator) in AFL is one of the following characters:
( ) , ; =

Parentheses (open ( and close ) ) group expressions, isolate conditional expressions and indicate function calls and function parameters:
d = c * ( a + b ) /* overrider normal precedence */
a= (b AND c) OR (d AND e) /* conditional expression */
func() /* function call no arguments */

The comma (,) separates the elements of a function argument list

The semicolon (;) is a statement terminator. Any legal AFL expression followed by a semicolon is interpreted as a statement, known as expression statement. The expression is evaluated and its value
is discarded (except Guru Commentaries where string values are written to output window)

The equal sign (=) separates variable declarations from initialization lists:
x = 5;
It also indicates the default value for a parameter (see built-in function description):
macd( fast = 12; slow = 26 ) /* default values for fast and slow arguments)

Language structure

Each formula in AFL contains of one or more expression statements. Each statement MUST be terminated by semicolon (;). In this way you are able to break long expressions into several physical lines (in order to gain clarity) and AmiBroker will still treat it like a single statement until terminating semicolon. Examples:

x = ( y + 3 );            /* x is assigned the value of y + 3  */
x = y = 0;                /* Both x and y are initialized to 0 */
proc( arg1, arg2 );       /* Function call, return value discarded */
y = z = ( f( x ) + 3 );   /* A function-call expression        */
my_indicator = 	iif( macd() > 0,
            	close - ma(close,9),
            	ma( close, 9 ) - close );  /* one statement in several lines */
Identifiers

Identifiers in AFL are used to identify variables and functions.
There are some predefined identifiers referencing built-in arrays and functions.
The most important are price array identifiers. They identify specific price fields that the formula should operate on. The valid price array identifiers are open, high, low, close, volume, sales, average. Price array identifiers can be abbreviated as shown in the following table. Note that these are not case-specific.

Long name Abbreviation Comment
Open O  
High H  
Low L  
Close C  
Volume V  
Sales S  
Average A (High+Low+Close)/3

Examples of the use of price array identifiers in formulas are shown below.

ma( close, 10 ); iif( h > ref(h,-1), ma(h,20), ma(c,20) ); 
Operators

Formulas can contain the following mathematical operators:

Symbol Meaning
+ Addition
- Subtraction (or negative value)
* Multiplication
/ Division
^ Exponentiation (raising to a power)

The following formulas illustrate the use of operators in a formula:

( H + L ) / 2;
ma(c,10)-ma(c,20) / (h + l + c);
close + ((1.02 * high)-high); 
Logical operators

If a formula requires multiple conditions, you can combine the conditions with AND and OR operators. For example, maybe you'd like to plot a +1 when the MACD is greater than zero and the RSI is greater than 70:

macd() > 0 AND rsi(14) > 70; 

You can add as many conditions within a formula as you like.

Parentheses

AFL supports parentheses in formulas.

Parentheses can be used to control the operation precedence (the order in which the operators are calculated). AmiBroker always does operations within the innermost parentheses first. When parentheses are not used, the precedence is as follows (higher precedence listed first):

No Symbol Meaning
1 ^ Exponentiation
2 - Negation - Unary minus
3 * Multiplication
4 / Division
5 + Addition
6 - Subtraction
7 < Less than
8 > Greater than
9 <= Less than or equal to
10 >= Greater than or equal to
11 = = Equal to
12 != Not equal to
13 NOT Logical "Not"
14 AND Logical "And"
15 OR Logical "Or"
16 = Variable assignment operator

The expression

H + L / 2; 

(without parenthesis) would be calculated by AmiBroker as "L / 2" plus "H", since division has a higher precedence. This would result in a much different value than

(H + L)/2; 
Functions

In addition to mathematical operators, AmiBroker contains over 60 built-in functions that perform mathematical operations.

The following formula consists of a single function that gives the square roots of the closing prices:

sqrt( CLOSE ); 

The following formula consists of a single function that gives a 14-period RSI indicator:

rsi(14); 

The following formula consists of two functions. The result is the difference between the MACD indicator and a 9-period exponential moving average of the MACD:

macd() - ema(macd(),9); 

All function calls must consist of function identifier (name) followed by a pair of parentheses.

As has been eluded to in earlier examples, a function can be "nested" within a function. The nested function can serve as the main function's data array parameter. The following examples show functions nested within functions:

ma( rsi(15), 10 ); 
ma( ema( rsi(15), 20), 10 ); 

The first example calculates a 10-period simple moving average of a 15-period Relative Strength Index (RSI). The second example calculates a 20-period exponential moving average of a 15-period RSI, and then calculates a 10-period simple moving average of this moving average.

Conditional function IIF()

The iif() function is used to create conditional (i.e., "if-then") statements. It contains three parameters as shown in the following example.

iif( close > ma(c,10), rsi(9), rsi(14) ); 

The above "iif" statement reads (in English) as follows: If today's close is greater than today's 10-day simple moving average of the close, then plot a 9-day RSI, otherwise, plot a 14-day RSI. The next formula plots “positive volume” if the close is greater than the median price. Otherwise, "negative volume" is plotted.

iif( CLOSE > (HIGH+LOW)/2, Volume, -Volume ); 

If you simply want an expression to be evaluated as either true or false, it can be done without the use of the iif() function. The following formula will result in either a 1 (true) or a 0 (false):

rsi(14) > 70; 

The same done with iif() gives the same results, but the formula is longer.

iif(rsi(14) > 70, 1, 0 ); 
Variables

In order to shorten, simplify, enhance, and make the maintenance of complex formulas easier, you may want to use variables. In fact using variables you can significantly improve formula calculation speed. So it is strongly recommended to use variables.

A variable is an identifier that is assigned to an expression or a constant. The number of variables used in a formula is not limited. Variables must be assigned before the variable is used in the formula. Variables cannot be assigned within a function call.

AmiBroker uses some reserved variable names in its formulas, for example in Auto-Analysis window you have to assign values to 2 variables named 'buy' or 'sell' to specify the conditions where "buy" and "sell" conditions occur. For example (system that buys when MACD rises above 0 line, and sells when MACD falls below 0 line)

buy  = cross( macd(), 0 );
sell = cross( 0, macd() ); 

User-defined variable names (identifiers) cannot duplicate names already used by functions (e.g., ma, rsi, cci, iif, etc.) or pre-defined array identifiers (e.g., open, high, low, close, simple, o, c, l, h, s, a).

Function Reference (AFL 1.0)

  1. ABS
    SYNTAX abs( NUMBER )
    abs( ARRAY )
    RETURNS NUMBER
    ARRAY
    FUNCTION Calculates the absolute value of the NUMBER or ARRAY.
    EXAMPLE The formula "abs( -10 )" will return +10; the formula "abs( 10 )" also returns +10.
  2. ACCDIST
    SYNTAX accdist()
    RETURNS ARRAY
    FUNCTION Calculates the predefined Accumulation/ Distribution indicator.
    EXAMPLE
  3. ATAN
    SYNTAX atan( NUMBER ),
    atan( ARRAY )
    RETURNS NUMBER
    ARRAY
    FUNCTION Returns the arc tangent of NUMBER or ARRAY. The value is returned in radians
    EXAMPLE The formula "atan( 1.00 )" returns PI/2
    SEE ALSO The cos() function (see Cosine) ; the sin() function (see Sine)
  4. BARSSINCE
    SYNTAX barssince( ARRAY )
    RETURNS ARRAY
    FUNCTION Calculates the number of bars (time periods) that have passed since DATA ARRAY was true.
    EXAMPLE barssince( macd() < 0 )
  5. BBANDBOT
    SYNTAX bbandbot( ARRAY, periods = 15, width = 2 )
    RETURNS ARRAY
    FUNCTION Calculates the bottom Bollinger Band of ARRAY shifted downward width standard deviations (using periods averaging range ).
    EXAMPLE bbandbot( close, 10, 2 )
    SEE ALSO  
  6. BBANDTOP
    SYNTAX bbandtop( ARRAY, periods = 15, width = 2 )
    RETURNS ARRAY
    FUNCTION Calculates the bottom Bollinger Band of ARRAY shifted upward width standard deviations (using periods averaging range ).
    EXAMPLE bbandtop( close, 10, 2 )
    SEE ALSO  
  7. CEIL
    SYNTAX ceil( number )
    ceil( array )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Calculates the lowest integer that is greater than NUMBER or ARRAY.
    EXAMPLE The formula ceil( 6.2 ) returns 7; the formula ceil(-6.2) returns -6.
    SEE ALSO The floor() function; the int().
  8. CHAIKIN
    SYNTAX chaikin( fast = 9, slow = 14 )
    RETURNS ARRAY
    FUNCTION Calculates the Chaikin Oscillator with averaging parameters: fast, slow
    EXAMPLE  
    SEE ALSO  
  9. CCI
    SYNTAX cci( periods = 14 )
    RETURNS ARRAY
    FUNCTION Calculates the Commodity Channel Index (using periods averaging range ).
    EXAMPLE cci( 14 )
    SEE ALSO  
  10. COS
    SYNTAX cos( NUMBER )
    cos( ARRAY )
    RETURNS NUMBER
    ARRAY
    FUNCTION Returns the cosine of NUMBER or ARRAY. Assumes that the NUMBER or ARRAY values are in radians.
    EXAMPLE cos( C )
    SEE ALSO The atan() function; the sin() function.
  11. CROSS
    SYNTAX cross( ARRAY1, ARRAY2 )
    RETURNS ARRAY
    FUNCTION Gives a "+1" on the day that ARRAY1 crosses above ARRAY2. Otherwise the result is "0".
    If you want to know when ARRAY1 crosses below ARRAY2, use the formula cross(ARRAY2, ARRAY1)
    EXAMPLE cross( close, ema(close,9) )
    SEE ALSO  
  12. CUM
    SYNTAX cum( ARRAY )
    RETURNS ARRAY
    FUNCTION Calculates a cumulative sum of the ARRAY from the first period in the chart.
    EXAMPLE The formula cum( 2 ) calculates an indicator that rises two points for each day since the beginning of the chart; the formula cum( C ) calculates the cumulative total of all closing prices from the beginning of the chart.
    SEE ALSO The sum() function.
  13. EMA
    SYNTAX ema( ARRAY, periods )
    RETURNS ARRAY
    FUNCTION Calculates a periods exponential moving average of ARRAY
    EXAMPLE ema( close, 5 )
    SEE ALSO ma() Simple Moving Average function
  14. EXP
    SYNTAX exp( NUMBER )
    exp( ARRAY )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Calculates e raised to the NUMBER or ARRAY power.
    EXAMPLE  
    SEE ALSO The log() function
  15. FLOOR
    SYNTAX floor( NUMBER )
    floor( ARRAY )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Calculates the highest integer that is less than NUMBER or ARRAY.
    EXAMPLE The function "floor( 17.9 )" returns 17. The formula "floor( -17.9 )" returns -18.
    SEE ALSO The ceil() function; the int() function.
  16. FRAC
    SYNTAX frac( NUMBER )
    frac( ARRAY )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Eliminates the integer portion of NUMBER or ARRAY and returns the fractional part.
    EXAMPLE The formula "frac( 10.7 )" returns 0.7; the formula "frac(-19.8 )" returns -0.8.
    SEE ALSO The int() function
  17. GAPDOWN
    SYNTAX gapdown()
    RETURNS ARRAY
    FUNCTION Gives a "+1" on the day a security's prices gap down. Otherwise the result is "0". A gap down occurs if yesterday's low is greater than today's high.
    EXAMPLE  
    SEE ALSO  
  18. GAPUP
    SYNTAX gapup()
    RETURNS ARRAY
    FUNCTION Gives a "+1" on the day a security's prices gap up. Otherwise the result is "0". A gap up occurs if yesterday's high is less than today's low.
    EXAMPLE  
    SEE ALSO  
  19. HIGHEST
    SYNTAX highest( ARRAY )
    RETURNS NUMBER
    FUNCTION Calculates the highest value in the ARRAY since the first day loaded in the chart.
    EXAMPLE The formula highest( rsi(14) ) returns the highest Relative Strength Index value; highest ( close ) returns the highest closing price.
    SEE ALSO The hhv() function Highest High Value ; the llv() function (Lowest Low Value); the lowest() function (Lowest).
  20. HIGHESTBARS
    SYNTAX highestbars( ARRAY )
    RETURNS ARRAY
    FUNCTION Calculates the number of periods that have passed since the ARRAY’s highest value.
    EXAMPLE The formula "highestbars( close )" returns the number of periods that have passed since the closing price reached its highest peak.
    SEE ALSO  
  21. HHV
    SYNTAX hhv( ARRAY, periods )
    RETURNS ARRAY
    FUNCTION Calculates the highest value in the ARRAY over the preceding periods (periods includes the current day).
    EXAMPLE The formula "hhv( close, 5 )" returns the highest closing price over the preceding five periods; "hhv( high, 7)" returns the highest high price over the preceding seven periods.
    SEE ALSO the llv() function (see Lowest Low Value).
  22. HHVBARS
    SYNTAX hhvbars( ARRAY, periods )
    RETURNS ARRAY
    FUNCTION Calculates the number of periods that have passed since the ARRAY reached its periods period peak.
    EXAMPLE The formula "hhvbars( close,50 )" returns the number of periods that have passed since the closing price reached its 50-period peak.
    SEE ALSO  
  23. HOLD
    SYNTAX hold( EXPRESSION, periods )
    RETURNS ARRAY
    FUNCTION Extends a "true" result of EXPRESSION for the specified number of periods. This true result is held true over the number of periods specified even if a "false" result is generated.
    EXAMPLE hold( cross(rsi(14),70),5 )
  24. IIF
    SYNTAX iif( EXPRESSION, THEN_ARRAY, ELSE_ARRAY )
    RETURNS ARRAY
    FUNCTION A conditional function that returns the value of the second parameter (THEN_ARRAY) if the conditional expression defined by the first parameter (EXPRESSION) is true; otherwise, the value of third parameter is returned (ELSE_ARRAY).
    EXAMPLE The formula "iif( macd()<signal(), Volume, -Volume)" will give positive volume values on days when macd was below its signal line, and negative volume values on the other days.
    SEE ALSO For more details on using the iif() function, see The iif() function.
  25. INSIDE
    SYNTAX inside()
    RETURNS ARRAY
    FUNCTION Gives a "+1" when an inside day occurs.Gives "0" otherwise. An inside day occurs when today's high is less than yesterday's high and today's low is greater than yesterday's low.
    EXAMPLE  
    SEE ALSO  
  26. INT
    SYNTAX int( NUMBER )
    int( ARRAY )
    RETURNS NUMBER
    ARRAY
    FUNCTION Removes the fractional portion of NUMBER or ARRAY and returns the integer part.
    EXAMPLE The formula "int( 10.7 )" returns 10; the formula "int(-19.8 )" returns -19.
    SEE ALSO The ceil() function; the floor() function; the frac() function.
  27. LASTVALUE
    SYNTAX lastvalue(ARRAY)
    RETURNS NUMBER
    FUNCTION Returns last calculated value of the specified ARRAY. The result of this function can be used in place of a constant (NUMBER) in any function argument.
    If ARRAY is undefined (e.g., only 100-days loaded and you request the last value of a 200-day moving average) then the lastvalue function returns zero.
    Since this function loads an entire data array with the last value of another array, it allows a formula to look into the future. This is unacceptable for most indicators, but is very beneficial for things like pattern recognition.
    EXAMPLE  
    SEE ALSO  
  28. LOG
    SYNTAX log( NUMBER )
    log( ARRAY )
    RETURNS NUMBER
    ARRAY
    FUNCTION Calculates the natural logarithm of NUMBER or ARRAY.
    EXAMPLE  
    SEE ALSO exp() Exponential function
  29. LOG10
    SYNTAX log10( NUMBER )
    log10( ARRAY )
    RETURNS NUMBER
    ARRAY
    FUNCTION Calculates the decimal logarithm of NUMBER or ARRAY.
    EXAMPLE  
    SEE ALSO .
  30. LOWEST
    SYNTAX lowest( ARRAY )
    RETURNS NUMBER
    FUNCTION Calculates the lowest value in the ARRAY.
    EXAMPLE The formula "lowest( rsi(14) )" returns the lowest Relative Strength Index value ; "lowest ( close )" returns the lowest closing price.
    SEE ALSO The hhv() function (see Highest High Value ); the llv() function (see Lowest Low Value); the highest() function (see Highest).
  31. LOWESTBARS
    SYNTAX lowestbars( ARRAY )
    RETURNS ARRAY
    FUNCTION Calculates the number of periods that have passed since the ARRAY’s lowest value.
    EXAMPLE The formula"lowestbars( close )" returns the number of periods that have passed since the closing price reached its lowest point.
    SEE ALSO  
  32. LLV
    SYNTAX llv( ARRAY, periods )
    RETURNS ARRAY
    FUNCTION Calculates the lowest value in the ARRAY over the preceding periods (periods includes the current day).
    EXAMPLE The formula "llv( close, 14 )" returns the lowest closing price over the preceding 14 periods.
    SEE ALSO The hhv() function (see Highest High Value ).
  33. LLVBARS
    SYNTAX llvbars( ARRAY, periods )
    RETURNS ARRAY
    FUNCTION Calculates the number of periods that have passed since the ARRAY reached its periods period trough.
    EXAMPLE The formula "llvbars( close,50 )" returns the number of periods that have passed since the closing price reached its 50 period trough.
    SEE ALSO  
  34. MA
    SYNTAX ma( ARRAY, periods)
    RETURNS ARRAY
    FUNCTION Calculates a periods simple moving average of ARRAY
    EXAMPLE ma(CLOSE, 5 )
    SEE ALSO ema() Exponential Moving Average function
  35. MACD
    SYNTAX macd(fast = 12, slow = 26)
    RETURNS ARRAY
    FUNCTION Calculates the MACD indicator using fast and slow averaging periods.
    EXAMPLE The formula "macd()" returns the value of the MACD indicator (i.e., the red line). The formula "signal()" returns the value of the MACD's signal line (i.e., the blue line).
    SEE ALSO The signal() function.
  36. MAX
    SYNTAX max( ARRAY1, ARRAY2 )
    RETURNS ARRAY
    FUNCTION Returns the largest of the two parameters.
    EXAMPLE The formula "max( CLOSE, 10 )" returns either the closing price or 10, whichever is greater. The formula "max(-14, 13)" always returns 13.
    SEE ALSO  
  37. MIN
    SYNTAX min( ARRAY1, ARRAY2 )
    RETURNS ARRAY
    FUNCTION Returns the smallest of the two parameters.
    EXAMPLE The formula "min( CLOSE, 10 )" returns the closing price or 10, whichever is less. The formula "min(-14, 13)" always returns -14.
    SEE ALSO The max() function.
  38. MFI
    SYNTAX mfi( periods = 14 )
    RETURNS ARRAY
    FUNCTION Calculates the Money Flow Index with period range
    EXAMPLE mfi( 16 )
    SEE ALSO The rsi() function (see Relative Strength Index (RSI)).
  39. NVI
    SYNTAX nvi()
    RETURNS ARRAY
    FUNCTION Calculates the Negative Volume Index.
    EXAMPLE  
    SEE ALSO The pvi() function
  40. OBV
    SYNTAX obv()
    RETURNS ARRAY
    FUNCTION Calculates the On Balance Volume indicator.
    EXAMPLE  
    SEE ALSO  
  41. PVI
    SYNTAX pvi()
    RETURNS ARRAY
    FUNCTION Calculates the predefined Positive Volume Index.
    EXAMPLE  
    SEE ALSO The nvi() function
  42. PREC
    SYNTAX prec(ARRAY, precision )
    RETURNS ARRAY
    FUNCTION Truncates ARRAY to precision decimal places.
    EXAMPLE The formula "prec( 10.12981, 2 )" returns 10.120. The formula "prec( 10.12981, 4 )" returns 10.12980.
    SEE ALSO  
  43. ROC
    SYNTAX roc( ARRAY, periods = 12)
    RETURNS ARRAY
    FUNCTION Calculates the periods rate-of-change of ARRAY expressed as percentage.
    EXAMPLE The formula "roc( CLOSE, 14 )" returns the 14-period percent rate-of-change of the closing prices.
    SEE ALSO  
  44. REF
    SYNTAX ref( ARRAY, period )
    RETURNS ARRAY
    FUNCTION References a previous or subsequent element in a ARRAY. A positive period references "n" periods in the future; a negative period references "n" periods ago.
    EXAMPLE The formula "ref( CLOSE, -12 )" returns the closing price 12 periods ago. Thus, you could write the 12-day price rate-of-change (expressed in points) as "C - ref( C, -12 )." The formula "ref( C, +12 )" returns the closing price 12 periods ahead.
    SEE ALSO  
  45. RSI
    SYNTAX rsi( periods = 14 )
    RETURNS ARRAY
    FUNCTION Calculates the RSI indicator using periods range
    EXAMPLE rsi( 12 )
    SEE ALSO  
  46. ROUND
    SYNTAX round( NUMBER )
    round( ARRAY )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Rounds NUMBER or ARRAY to the nearest integer.
    EXAMPLE The formula "round( +10.5 )" returns +11. The formula "round( -10.4 )" returns -10.
    SEE ALSO The ceil() function; the floor() function; the int() function.
  47. SIGNAL
    SYNTAX signal( fast = 12, slow = 26, signal = 9 )
    RETURNS ARRAY
    FUNCTION Calculates the Signal line of MACD indicator.
    EXAMPLE signal( 14, 28, 10 );
    SEE ALSO  
  48. SIN
    SYNTAX sin( NUMBER )
    sin( ARRAY )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Returns the sine of NUMBER or ARRAY. This function assumes that the ARRAY values are in radians.
    EXAMPLE You can plot a sine wave using the formula "sin(cum(0.1))." Increasing the value in this formula (i.e., "0.1") will increase the frequency of the sine wave.
    SEE ALSO The atan() function ; the cos() function.
  49. SQRT
    SYNTAX sqrt( NUMBER )
    sqrt( ARRAY )
    RETURNS NUMBER,
    ARRAY
    FUNCTION Calculates the square root of NUMBER or ARRAY. The square root of a negative number always returns a zero result.
    EXAMPLE The formula "sqrt( 16 )" returns 4
    SEE ALSO  
  50. STOCHK
    SYNTAX stochk( periods = 14 )
    RETURNS ARRAY
    FUNCTION Calculates the %K line of Stochastic Oscillator (with internal slowing 3).
    EXAMPLE The formula "stochk( 5 )" returns the value of a 5-period %K slowed down 3 periods.
    SEE ALSO  
  51. STOCHD
    SYNTAX stochd( periods = 14 )
    RETURNS ARRAY
    FUNCTION Calculates the %D line of Stochastic Oscillator (with internal slowing 3).
    EXAMPLE The formula "stochd( 5 )" returns the value of a 5-period %D slowed down 3 periods.
  52. SUM
    SYNTAX sum( ARRAY, periods )
    RETURNS ARRAY
    FUNCTION Calculates a cumulative sum of the ARRAY for the specified number of lookback periods (including today).
    EXAMPLE The formula "sum( CLOSE, 12 )" returns the sum of the preceding 12 closing prices. A 12-period simple moving average could be written "sum(C,12) / 12."
    SEE ALSO The cum() function.
  53. TRIX
    SYNTAX trix( periods = 9 )
    RETURNS ARRAY
    FUNCTION Calculates the TRIX indicator (with averaging range of periods).
    EXAMPLE trix( 12 )
    SEE ALSO  
  54. ULTIMATE
    SYNTAX ultimate( fast = 7, med = 14, slow = 28 )
    RETURNS ARRAY
    FUNCTION Calculates the Ultimate Oscillator indicator using the three cycle lengths supplied as parameters. Note that each of the three parameters must be greater than the preceding parameter.
    EXAMPLE The formula "ultimate( 7, 14, 21 )" returns the default Ultimate Oscillator.
    SEE ALSO  
  55. WRITEIF
    SYNTAX writeif( EXPRESSION, "TRUE TEXT", "FALSE TEXT" )
    RETURNS STRING
    FUNCTION This function can only be used within an Guru commentary. If EXPRESSION evaluates to "true", then the TRUE TEXT string is displayed within the commentary. If EXPRESSION evaluates to "false", then the FALSE TEXT string is displayed.
    EXAMPLE writeif( c > mov(c,200,s), "The close is above the 200-period moving average.","The close is below the 200-period moving average." )
    SEE ALSO writeval() function
  56. WRITEVAL
    SYNTAX writeval( NUMBER )
    writeval( ARRAY )
    RETURNS STRING
    FUNCTION This function can only be used within an Guru commentary. It is used to display the numeric value of NUMBER or ARRAY.
    EXAMPLE writeval( stoch(39) - stoch(12) )
    SEE ALSO writeif() function

Function Reference (functions avaliable in AFL 1.1 and above)

  1. NAME
    SYNTAX name()
    RETURNS STRING
    FUNCTION This function can only be used within an Guru commentary. It is used to display the stock short name (ticker)
    EXAMPLE name()
  2. FULLNAME
    SYNTAX fullname()
    RETURNS STRING
    FUNCTION This function can only be used within an Guru commentary. It is used to display the stock full name
    EXAMPLE fullname()
  3. DATE
    SYNTAX date()
    RETURNS STRING
    FUNCTION This function can only be used within an Guru commentary. It is used to display the selected date
    EXAMPLE date()
  4. OSCP
    SYNTAX oscp( fast , slow )
    RETURNS ARRAY
    FUNCTION Calculates price oscillator based on exponential moving averages
    EXAMPLE oscp(9, 18)
  5. OSCV
    SYNTAX oscv( fast, slow )
    RETURNS ARRAY
    FUNCTION Calculates volume oscillator based on exponential moving averages
    EXAMPLE oscv( 9, 18 )
  6. ZIG
    SYNTAX zig(ARRAY, change )
    RETURNS ARRAY
    FUNCTION Calculates the minimum % change predefined Zig Zag indicator
    EXAMPLE zig(close,5)
  7. PEAK
    SYNTAX peak(ARRAY, change, n = 1)
    RETURNS ARRAY
    FUNCTION Gives the value of ARRAY n-th peak(s) ago. This uses the Zig Zag function (see Zig Zag) to determine the peaks. n =1 would return the value of the most recent peak. n =2 would return the value of the 2nd most recent peak.
    EXAMPLE peak(close,5,1)
  8. PEAKBARS
    SYNTAX peakbars(ARRAY, change, n = 1)
    RETURNS ARRAY
    FUNCTION Gives the number of bars that have passed from the n-th peak. This uses the Zig Zag function (see Zig Zag) to determine the peaks. n =1 would return the number of bars that have passed since the most recent peak. n =2 would return the number of bars that have passed since the 2nd most recent peak
    EXAMPLE peakbars(close,5,1)
  9. TROUGH
    SYNTAX trough(ARRAY, change, n = 1)
    RETURNS ARRAY
    FUNCTION Gives the value of ARRAY n-th trough(s) ago. This uses the Zig Zag function (see Zig Zag) to determine the troughs.
    EXAMPLE trough(close,5,1)
  10. TROUGHBARS
    SYNTAX troughbars(ARRAY, change, n = 1)
    RETURNS ARRAY
    FUNCTION Plots the number of bars that have passed from the n-th trough. This uses the Zig Zag function (see Zig Zag) to determine the troughs.
    EXAMPLE troughbars(close,5,1)
  11. VALUEWHEN
    SYNTAX valuewhen(EXPRESSION, ARRAY, n = 1)
    RETURNS ARRAY
    FUNCTION Returns the value of the ARRAY when the EXPRESSION was true on the n -th most recent occurrence.
    EXAMPLE valuewhen( cross( close, ma(close,5) ) ,macd(), 1)