AFL Function Reference - Categorized list of functions
Basic price pattern detection
Composites
Date/Time
- BarIndex -
get zero-based bar number (AFL 2.3)
- BeginValue -
Value of the array at the begin of the range (AFL 2.3)
- Date -
date (AFL 1.1)
- DateNum -
date number (AFL 1.4)
- DateTime -
retrieves encoded date time (AFL 2.3)
- DateTimeAdd -
adds specified number of seconds/minutes/hours/days to datetime (AFL 3.40)
- DateTimeConvert -
date/time format conversion (AFL 2.90)
- DateTimeDiff -
get difference in seconds between two datetime values (AFL 3.30)
- DateTimeFormat -
converts datetime to string (AFL 4.20)
- DateTimeToStr -
convert datetime to string (AFL 2.8)
- Day -
day of month (AFL 1.4)
- DayOfWeek -
day of week (AFL 1.4)
- DayOfYear -
get ordinal number of day in a year (AFL 2.4)
- DaysSince1900 -
get number of days since January 1st, 1900 (AFL 3.20)
- EndValue -
value of the array at the end of the selected range (AFL 2.3)
- GetPlaybackDateTime -
get bar replay position date/time (AFL 3.0)
- Hour -
get current bar's hour (AFL 2.0)
- Interval -
get bar interval (in seconds) (AFL 2.1)
- Lookup -
search the array for bar with specified date/time (AFL 3.40)
- MicroSec -
get bar's microsecond part of the timestamp
- MilliSec -
get bar's millisecond part of the timestamp
- Minute -
get current bar's minute (AFL 2.0)
- Month -
month (AFL 1.4)
- Now -
gets current system date/time (AFL 2.3)
- Second -
get current bar's second (AFL 2.0)
- TimeNum -
get current bar time (AFL 2.0)
- Year -
year (AFL 1.4)
- _DT -
convert string to datetime (AFL 3.40)
Indicators
- AccDist -
accumulation/distribution
- ADX -
average directional movement index (AFL 1.3)
- ATR -
average true range (AFL 1.3)
- BBandBot -
bottom bollinger band
- BBandTop -
top bollinger band
- CCI -
commodity channel index
- Chaikin -
chaikin oscillator
- ColorBlend -
blends (mixes) two colors (AFL 3.30)
- FirstVisibleValue -
get first visible value of array (AFL 3.40)
- GetChartBkColor -
get the RGB color value of chart background (AFL 3.20)
- GetCursorMouseButtons -
get current state of mouse buttons (AFL 2.80)
- GetCursorXPosition -
get current X position of mouse pointer (AFL 2.80)
- GetCursorYPosition -
get current Y position of mouse pointer (AFL 2.80)
- HighestVisibleValue -
get the highest value within visible chart area (AFL 3.30)
- LastVisibleValue -
get last visible value of array (AFL 3.40)
- LowestVisibleValue -
get the lowest value within visible chart area (AFL 3.30)
- MACD -
moving average convergence/divergence
- MDI -
minus directional movement indicator (-DI) (AFL 1.3)
- MFI -
money flow index
- NVI -
negative volume index
- OBV -
on balance volume
- OscP -
price oscillator
- OscV -
volume oscillator
- PDI -
plus directional movement indicator (AFL 1.3)
- PercentRank -
calculate percent rank (AFL 3.40)
- PlotText -
write text on the chart (AFL 2.80)
- PlotVAPOverlayA -
plot multiple-segment Volume-At-Price chart (AFL 3.20)
- PVI -
positive volume index
- RequestMouseMoveRefresh -
request chart to be refreshed when user moves mouse cursor (AFL 4.30)
- RequestTimedRefresh -
forces periodical refresh of indicator pane (AFL 2.90)
- RMI -
Relative Momentum Index (AFL 2.1)
- ROC -
percentage rate of change
- RSI -
relative strength index
- RWI -
random walk index
- RWIHi -
random walk index of highs
- RWILo -
random walk index of lows
- SAR -
parabolic stop-and-reverse (AFL 1.3)
- SetBarFillColor -
set bar/candlestick/cloud chart fill color (AFL 3.1)
- SetChartBkColor -
set background color of a chart (AFL 2.80)
- SetChartBkGradientFill -
enables background gradient color fill in indicators (AFL 2.90)
- SetGradientFill -
set the colors of a gradient fill plot (AFL 3.60)
- Signal -
macd signal line
- StochD -
stochastic slow %D
- StochK -
stochastic slow %K
- TRIX -
triple exponential smoothed price
- Ultimate -
ultimate oscillator
Information / Categories
- CategoryAddSymbol -
adds a symbol to a category (AFL 2.5)
- CategoryCreate -
add new category (such as watch list) (AFL 3.70)
- CategoryFind -
search for category by name (AFL 3.0)
- CategoryGetName -
get the name of a category (AFL 2.5)
- CategoryGetSymbols -
retrieves comma-separated list of symbols belonging to given category (AFL 2.5)
- CategoryRemoveSymbol -
remove a symbol from a category (AFL 2.5)
- CategorySetName -
set the name of category (group, market, watch list, industry) (AFL 3.20)
- FullName -
full name of the symbol (AFL 1.1)
- GetCategorySymbols -
retrieves comma-separated list of symbols belonging to given category (AFL 2.4)
- GetDatabaseName -
retrieves folder name of current database (AFL 2.3)
- GetFnData -
get fundamental data (AFL 2.90)
- GetFnDataForeign -
get fundamental data for specified symbol (AFL 4.20)
- GicsID -
get GICS category information (AFL 3.40)
- GroupID -
get group ID/name (AFL 1.8)
- IcbID -
get ICB category information (AFL 3.60)
- IndustryID -
get industry ID / name (AFL 1.8)
- InGICS -
test GICS membership (AFL 3.40)
- InICB -
test ICB membership (AFL 3.60)
- InWatchList -
watch list membership test (by ordinal number)
- InWatchListName -
watch list membership test (by name) (AFL 3.0)
- IsContinuous -
checks 'continuous quotations' flag state (AFL 2.60)
- IsFavorite -
check if current symbol belongs to favorites (AFL 2.5)
- IsIndex -
check if current symbol is an index (AFL 2.5)
- MarketID -
market ID / name (AFL 1.8)
- Name -
ticker symbol (AFL 1.1)
- SectorID -
get sector ID / name (AFL 1.8)
Lowest/Highest
Math functions
- abs -
absolute value
- acos -
arccosine function
- AlmostEqual -
rounding error insensitive comparison (AFL 2.80)
- asin -
arcsine function
- atan -
arc tan
- atan2 -
calculates arctangent of y/x (AFL 2.90)
- ceil -
ceil value
- cos -
cosine
- cosh -
hyperbolic cosine function (AFL 2.80)
- erf -
calculates Gauss error function (erf) (AFL 4.40)
- EXP -
exponential function
- floor -
floor value
- frac -
fractional part
- Int -
integer part
- inverf -
inverse Gauss erf function (AFL 4.40)
- Kurtosis -
calculates kurtosis (AFL 4.20)
- log -
natural logarithm
- log10 -
decimal logarithm
- Max -
maximum value of two numbers / arrays
- Min -
minimum value of two numbers / arrays
- Prec -
adjust number of decimal points of floating point number
- Remap -
re-maps one range to another (AFL 4.30)
- Round -
round number to nearest integer
- SafeDivide -
division with divide-by-zero protection (AFL 4.40)
- sign -
returns the sign of the number/array (AFL 2.50)
- sin -
sine function
- sinh -
hyperbolic sine function (AFL 2.80)
- Skewness -
calculate skewness (AFL 4.20)
- sqrt -
square root
- tan -
tangent function (AFL 1.0)
- tanh -
hyperbolic tangent function (AFL 2.80)
Miscellaneous functions
- #include -
preprocessor include command (AFL 2.2)
- #include_once -
preprocessor include (once) command (AFL 2.70)
- #pragma -
sets AFL pre-processor option (AFL 2.4)
- ClipboardGet -
retrieves current contents of Windows clipboard (AFL 2.60)
- ClipboardSet -
copies the text to the Windows clipboard (AFL 2.6)
- ColorHSB -
specify color using Hue-Saturation-Brightness (AFL 2.80)
- ColorRGB -
specify color using Red-Green-Blue components (AFL 2.80)
- CreateObject -
create COM object (AFL 1.8)
- CreateStaticObject -
create static COM object (AFL 1.8)
- EnableScript -
enable scripting engine
- EnableTextOutput -
allows to enable or disable text output (AFL 2.20)
- Error -
displays user-defined error message and stops the execution (AFL 3.7)
- FindIndex -
find index of array item matching specified value (AFL 4.40)
- GetAsyncKeyState -
query the current state of keyboard keys (AFL 3.60)
- GetExtraData -
get extra data from external data source (AFL 1.9)
- GetExtraDataForeign -
get extra data from external data source for specified symbol (AFL 4.20)
- GetFormulaPath -
get file path of current formula (AFL 3.90)
- GetLastOSError -
get text of last operating system (Windows) error (AFL 4.30)
- GetObject -
get handle to already running OLE object (AFL 4.40)
- GetPerformanceCounter -
retrieves the current value of the high-resolution performance counter (AFL 2.90)
- GetRTData -
retrieves the real-time data fields (AFL 2.60)
- GetRTDataForeign -
retrieves the real-time data fields (for specified symbol) (AFL 2.80)
- GetScriptObject -
get access to script COM object (AFL 1.8)
- IsEmpty -
empty value check (AFL 1.5)
- IsFinite -
check if value is not infinite (AFL 2.3)
- IsNan -
checks for NaN (not a number) (AFL 2.3)
- IsNull -
check for Null (empty) value (AFL 2.3)
- IsTrue -
true value (non-empty and non-zero) check (AFL 1.5)
- NoteGet -
retrieves the text of the note (AFL 2.6)
- NoteSet -
sets text of the note (AFL 2.6)
- NullCount -
count consecutive Null values (AFL 3.90)
- Nz -
Null (Null/Nan/Infinity) to zero (AFL 2.3)
- PlaySound -
play back specified .WAV file (AFL 3.40)
- PopupWindow -
display pop-up window (AFL 3.0)
- Prefs -
retrieve preferences settings (AFL 1.4)
- Reverse -
reverse the order of the elements in the array (AFL 3.90)
- SendEmail -
send an e-mail message (AFL 3.90)
- SetBarsRequired -
set number of previous and future bars needed for script/DLL to properly execute (AFL 2.1)
- Sort -
performs a quick sort of the array (AFL 3.90)
- SparseCompress -
compress sparse array (AFL 4.0)
- SparseExpand -
expand compressed array to sparse array (AFL 4.0)
- SparseInterpolate -
interpolate values between sparse points given as input (AFL 4.90)
- StaticVarAdd -
an "atomic" addition for static variables (AFL 4.10)
- StaticVarCompareExchange -
atomic interlocked static variable compare-exchange operation (AFL 3.50)
- StaticVarCount -
get the total number of static variables in memory (AFL 3.30)
- StaticVarGenerateRanks -
generate ranking of multiple symbols and store it to static variables (AFL 3.70)
- StaticVarGet -
gets the value of static variable (AFL 2.60)
- StaticVarGetRankedSymbols -
retrieve a list of ranked symbols from static variables (AFL 3.70)
- StaticVarGetText -
gets the value of static variable as string (AFL 2.60)
- StaticVarInfo -
get the information about static variable(s) (AFL 3.60)
- StaticVarRemove -
remove static variable (AFL 2.80)
- StaticVarSet -
sets the value of static variable (AFL 2.60)
- StaticVarSetText -
Sets the value of static string variable. (AFL 2.60)
- Status -
get run-time AFL status information (AFL 1.65)
- Study -
reference hand-drawn study (AFL 1.5)
- ThreadSleep -
suspend thread for specified number of milliseconds (AFL 3.50)
- VarGet -
gets the value of dynamic variable (AFL 2.60)
- VarGetText -
gets the text value of dynamic variable (AFL 2.80)
- VarSet -
sets the value of dynamic variable (AFL 2.60)
- VarSetText -
sets dynamic variable of string type (AFL 2.80)
- Version -
get version info (AFL 1.9)
- _exit -
terminate the execution of AFL formula (AFL 4.40)
- _TRACE -
print text to system debug viewer (AFL 2.4)
- _TRACEF -
print formatted text to system debug viewer (AFL 4.0)
Moving averages, summation
- AMA -
adaptive moving average (AFL 1.5)
- AMA2 -
adaptive moving average (AFL 1.5)
- Cum -
cumulative sum
- CumProd -
cumulative product of all array elements (AFL 4.20)
- DEMA -
double exponential moving average (AFL 2.0)
- EMA -
exponential moving average
- FIR -
Finite Impulse Response filter (AFL 3.40)
- HMA -
Hull Moving Average (AFL 3.40)
- IIR -
infinite impulse response filter (AFL 4.0)
- MA -
simple moving average
- Prod -
cumulative product of array over specified range (AFL 4.20)
- ProdSince -
cumulative product since condition is met (AFL 4.20)
- Sum -
sum data over specified number of bars
- SumSince -
sum of array elements since condition was tru (AFL 4.10)
- TEMA -
triple exponential moving average (AFL 2.0)
- Wilders -
Wilder's smoothing (AFL 1.4)
- WMA -
weighted moving average (AFL 2.0)
Statistical functions
- Correlation -
correlation (AFL 1.4)
- LinearReg -
linear regression end-point (AFL 2.2)
- LinRegIntercept -
(AFL 2.2)
- LinRegSlope -
linear regression slope (AFL 1.4)
- Median -
calculate median (middle element) (AFL 2.5)
- mtRandom -
Mersene Twister random number generator (AFL 3.0)
- mtRandomA -
Mersene Twister random number generator (array version) (AFL 3.0)
- NormDist -
normal distribution function (AFL 4.20)
- Percentile -
calculate percentile (AFL 2.5)
- Random -
random number (AFL 1.9)
- StdErr -
standard error (AFL 1.4)
- StDev -
standard deviation (AFL 1.4)
- TSF -
time series forecast (AFL 2.2)
String manipulation
- Asc -
get ASCII code of character (AFL 2.80)
- Chr -
get string with given ASCII code (AFL 4.40)
- NumToStr -
convert number to string (AFL 2.5)
- printf -
Print formatted output to the output window. (AFL 2.5)
- StrCount -
count the occurrences of substring within a string (AFL 3.20)
- StrExtract -
extracts given item (substring) from comma-separated string (AFL 2.4)
- StrFind -
find substring in a string (AFL 2.5)
- StrFormat -
Write formatted output to the string (AFL 2.5)
- StrLeft -
extracts the leftmost part (AFL 2.0)
- StrLen -
string length (AFL 1.5)
- StrMatch -
string pattern/wildcard matching (AFL 4.0)
- StrMid -
extracts part of the string (AFL 2.0)
- StrReplace -
string replace (AFL 2.90)
- StrRight -
extracts the rightmost part of the string (AFL 2.0)
- StrSort -
sort comma-separated item list (AFL 3.90)
- StrToDateTime -
convert string to datetime (AFL 2.80)
- StrToLower -
convert to lowercase (AFL 2.80)
- StrToNum -
convert string to number (AFL 2.5)
- StrToUpper -
convert to uppercase (AFL 2.80)
- StrTrim -
trim whitespaces from the string (AFL 3.90)
Trading system toolbox
- AlertIf -
trigger alerts (AFL 2.1)
- ApplyStop -
apply built-in stop (AFL 1.7)
- BarsSince -
bars since
- BarsSinceCompare -
bars since comparision between past and present array values was true (AFL 4.40)
- Cross -
crossover check
- EnableRotationalTrading -
Turns on rotational-trading mode of the backtester (AFL 2.5)
- Equity -
calculate single-symbol equity line (AFL 2.0)
- ExRem -
remove excessive signals (AFL 1.5)
- ExRemSpan -
remove excessive signals spanning given number of bars (AFL 2.0)
- Flip -
(AFL 1.5)
- GetBacktesterObject -
get the access to backtester object (AFL 2.60)
- GetOption -
gets the value of option in automatic analysis settings (AFL 2.60)
- GetTradingInterface -
retrieves OLE automation object to automatic trading interfac (AFL 2.70)
- Hold -
hold the alert signal
- IIf -
immediate IF function
- LastValue -
last value of the array
- Optimize -
define optimization variable (AFL 1.7)
- OptimizerSetEngine -
select external optimization engine (AFL 3.20)
- OptimizerSetOption -
set the value of external optimizer engine parameter (AFL 3.20)
- Ref -
reference past/future values of the array
- SetBacktestMode -
Sets working mode of the backtester (AFL 3.0)
- SetCustomBacktestProc -
define custom backtest procedure formula file (AFL 2.70)
- SetFormulaName -
set the name of the formula (AFL 2.5)
- SetOption -
sets options in automatic analysis settings (AFL 2.3)
- SetPositionSize -
set trade size (AFL 2.70)
- SetStopPrecedence -
set precedence of built-in stops (AFL 4.0)
- SetTradeDelays -
allows to control trade delays applied by the backtester (AFL 2.1)
- ValueWhen -
get value of the array when condition met (AFL 1.1)
Exploration / Indicators
- AddColumn -
add numeric exploration column (AFL 1.8)
- AddMultiTextColumn -
adds exploration text column based on array (AFL 4.20)
- AddRankColumn -
add ranking column(s) according to current sort set by SetSortColumns (AFL 5.70)
- AddRow -
add raw text row to exploration (AFL 4.0)
- AddSummaryRows -
add summary row(s) to the exploration output (AFL 3.2)
- AddTextColumn -
add text exploration column (AFL 1.8)
- EncodeColor -
encodes color for indicator title (AFL 2.2)
- GetChartID -
get current chart ID (AFL 2.3)
- GetPriceStyle -
get current price chart style (AFL 2.70)
- LineArray -
generate trend-line array (AFL 2.5)
- Param -
add user user-definable numeric parameter (AFL 2.3)
- ParamColor -
add user user-definable color parameter (AFL 2.3)
- ParamDate -
add user user-definable date parameter (AFL 2.60)
- ParamField -
creates price field parameter (AFL 2.70)
- ParamList -
creates the parameter that consist of the list of choices (AFL 2.70)
- ParamStr -
add user user-definable string parameter (AFL 2.3)
- ParamStyle -
select styles applied to the plot (AFL 2.70)
- ParamTime -
add user user-definable time parameter (AFL 2.60)
- ParamToggle -
create Yes/No parameter (AFL 2.70)
- ParamTrigger -
creates a trigger (button) in the parameter dialog (AFL 2.70)
- Plot -
plot indicator graph (AFL 1.8)
- PlotGrid -
Plot horizontal grid line (AFL 2.3)
- PlotOHLC -
plot custom OHLC chart (AFL 2.2)
- PlotShapes -
plots arrows and other shapes (AFL 2.3)
- PlotVAPOverlay -
plot Volume-At-Price overlay chart (AFL 2.4)
- SelectedValue -
retrieves value of the array at currently selected date/time point (AFL 2.1)
- SetChartOptions -
set/clear/overwrite defaults for chart pane options (AFL 2.70)
- SetSortColumns -
sets the columns which will be used for sorting in AA window (AFL 2.90)
- TrimResultRows -
trims Analysis result list to specified number of rows (AFL 4.90)
- WriteIf -
commentary conditional text output
- WriteVal -
converts number to string
- XYChartAddPoint -
add point to exploration scatter (XY) chart (AFL 3.60)
- XYChartSetAxis -
set the names of X and Y axes in exploration scatter charts (AFL 3.60)
- _DEFAULT_NAME -
retrive default name of the plot (AFL 2.70)
- _N -
no text output (AFL 2.1)
- _PARAM_VALUES -
retrieve param values string (AFL 2.70)
- _SECTION_BEGIN -
section begin marker (AFL 2.70)
- _SECTION_END -
section end marker (AFL 2.70)
- _SECTION_NAME -
retrieve current section name (AFL 2.70)
File Input/Output functions
- fclose -
close a file (AFL 2.5)
- fdelete -
deletes a file (AFL 2.70)
- fdir -
list directory content (AFL 3.70)
- feof -
test for end-of-file (AFL 2.5)
- fgetcwd -
get current working directory (AFL 4.10)
- fgets -
get a string from a file (AFL 2.5)
- fgetstatus -
retrieves file status/properties (AFL 2.90)
- fmkdir -
creates (makes) a directory (AFL 2.70)
- fopen -
open a file (AFL 2.5)
- fputs -
write a string to a file (AFL 2.5)
- frmdir -
removes a directory (AFL 2.70)
- InternetClose -
close Internet file handle (AFL 4.20)
- InternetGetStatusCode -
returns HTTP status code of last Internet call (AFL 4.40)
- InternetOpenURL -
opens Internet web resource (URL) (AFL 4.20)
- InternetPostRequest -
send HTTP Post request to Internet web resource (URL) (AFL 4.30)
- InternetReadString -
read a string from Internet resource (AFL 4.20)
- InternetSetAgent -
set agent string for Internet function (AFL 4.30)
- InternetSetHeaders -
set custom HTTP headers for subsequent web requests (AFL 4.40)
- InternetSetOption -
set HTTP option for internet session (AFL 4.40)
GUI functions
- GuiButton -
create on-chart button control (AFL 4.30)
- GuiCheckBox -
creates on-chart checkbox control (AFL 4.30)
- GuiDateTime -
creates on-chart date-time picker control (AFL 4.30)
- GuiEdit -
create on-chart edit control (AFL 4.30)
- GuiEnable -
enables or disables on-chart control (AFL 4.30)
- GuiGetCheck -
get checked state of control (AFL 4.30)
- GuiGetEvent -
get GUI event (AFL 4.30)
- GuiGetText -
get text from on-chart control (AFL 4.30)
- GuiGetValue -
get numeric value of on-chart control (AFL 4.30)
- GuiRadio -
creates on-chart radio button control (AFL 4.30)
- GuiSendKeyEvents -
request GUI notifications for specified keys (AFL 4.40)
- GuiSetCheck -
set checked state of on-chart control (AFL 4.30)
- GuiSetColors -
set colors for GUI controls (AFL 2.30)
- GuiSetFont -
set the font for on-chart control (AFL 4.30)
- GuiSetRange -
set slider control range (AFL 4.30)
- GuiSetText -
set text value of on-chart control (AFL 4.30)
- GuiSetValue -
set numeric value of on-chart control (AFL 4.30)
- GuiSetVisible -
shows or hides on-chart control (AFL 4.30)
- GuiSlider -
creates on-chart slider control (AFL 4.30)
Low-level graphics
Map functions
- MapCreate -
creates a map/dictionary object (holding key-value pairs) (AFL 4.90)
Matrix functions
- Matrix -
create a new matrix (AFL 4.0)
- MxCopy -
copy rectangular block from one matrix to another (AFL 4.40)
- MxDet -
calculate determinant of the matrix (AFL 4.10)
- MxFromString -
creates a new matrix out of string (AFL 4.10)
- MxGetBlock -
get rectangular block of items from matrix (AFL 4.10)
- MxGetSize -
get size of the matrix (AFL 4.0)
- MxIdentity -
create an identity matrix (AFL 4.0)
- MxInverse -
calculate inverse matrix (AFL 4.10)
- MxSetBlock -
sets values in the rectangular block of matrix cells (AFL 4.10)
- MxSolve -
solves linear equation system A @ X = B (AFL 4.10)
- MxSort -
sorts the matrix (AFL 4.10)
- MxSortRows -
sort the rows of the matrix (AFL 4.10)
- MxSum -
calculate grand sum of the matrix (AFL 4.20)
- MxToString -
convert matrix to string (AFL 4.10)
- MxTranspose -
creates transpose of an input matrix (AFL 4.0)
- PriceVolDistribution -
general-purpose distribution function (AFL 4.20)
Referencing other symbol data
- Foreign -
access foreign security data (AFL 1.5)
- GetBaseIndex -
retrieves symbol of relative strength base index (AFL 2.1)
- PlotForeign -
plot foreign security data (AFL 2.2)
- RelStrength -
comparative relative strength (AFL 1.3)
- RestorePriceArrays -
restore price arrays to original symbol (AFL 2.5)
- SetForeign -
replace current price arrays with those of foreign security (AFL 2.5)
Text-to-Speech functions
Time Frame functions