You are on page 1of 57

Metastock Formula Language

What is the MetaStock Formula Language?


The MetaStock formula language is a special programming language used to define and create custom indicators,
system tests, explorations, and experts. It is patterned after popular spreadsheet languages.
In its simplest form, the MetaStock formula language is comprised of high-level functions (e.g., mov(), rsi(), as() ),
mathematical operators (e.g., !, -, ", #), and parameters (open, high, lo$, close, etc.). %ach of these asic components
can e comined to create your o$n indicators $ith the Indicator &uilder, acktest your trading ideas $ith the
%nhanced System Tester, rank and filter your securities $ith The %xplorer, and generate chart-specific feedack $ith
the %xpert 'dvisor.
In order to effectively use the Indicator &uilder, %nhanced System Tester, %xplorer, or %xpert 'dvisor, you need to e
familiar $ith the MetaStock formula language. The MetaStock formula language is the foundation and common link
for each of these four tools.
The Indicator &uilder $ill e used in this chapter to teach the MetaStock formula language. (or specific tutorials on
each of the four formula-ased tools, refer to their specific chapters.
(or information on the %)uis Solution *rovider program and the MetaStock +evelopers ,it, go to
http-""$$$.e)uis.com.
Price Array Identifiers:
.ne of the most asic uilding locks of a formula is called a price array identifier. ' price array identifier
/identifies/ specific price fields that the formula should operate on. The valid price array identifiers are open, high,
lo$, close, volume, open interest, and indicator.
*rice array identifiers can e areviated as sho$n in the follo$ing tale. 0ote that these are not case-specific.
1ong 0ame 'reviation 2
.pen .
3igh 3
1o$ 1
4lose 4
5olume 5
.pen Interest .I
Indicator *
*revious 5alue *6%5
Trang 1 Ngun: XLanh11
Metastock Formula Language
%xamples of the use of price array identifiers in formulas are sho$n elo$. The actual price array identifier
component of the formulas are in old for these examples.
mov( close,78, simple )
if (h 9 ref(h,-7), mov(h,:8,s), mov(c,:8,s) )
stdev( volume, :8 )
Mathematical Operators:
Mathematical operators are the /glue/ that inds formulas. (ormulas can contain the follo$ing mathematical
operators. (They also can contain advanced operators such as s)uare root, as explained later.)
! 'ddition
- Sutraction (or negative)
# Multiplication
" +ivision
The follo$ing formulas illustrate the use of operators (olded) in a formula-
( 3 ! 1 ) " :
mov(c,78,s)-mov(c,:8,s) " (h ! l ! c)
close ! ((7.8: # high)-high)
Operator Precedence:
*arentheses $ere used in manyof the preceding formulas in this chapter to control the operation precedence (the order
in $hich the operators are calculated). MetaStock al$ays does operations $ithin the innermost parentheses first.
;hen parentheses are not used, the precedence is as follo$s-
- 0egative values
# Multiplication
Trang 2 Ngun: XLanh11
Metastock Formula Language
" +ivision
! 'ddition
- Sutraction
< 1ess than
9 =reater than
<> 1ess than or e)ual to
9> =reater than or e)ual to
> %)ual to
<9 0ot e)ual to
'nd 1ogical /'nd/
.r 1ogical /.r/
-> 5ariale assignment operator - ph?p t@nh ABCc gDn cho iEn.
The expression /3 ! 1 " :/ ($ithout parenthesis) $ould e calculated y MetaStock as /1 " :/ plus /3,/ since
division has a higher precedence. This $ould result in a much different value than /(3 ! 1) " :./
(or ease of reading, $e recommend that you al$ays use parenthesis to control precedence.
Formula Functions
In addition to the four mathematical operators, MetaStock contains over :88 /functions/ that perform mathematical
operations. See (unctions for a complete listing of all uilt-in functions.
The follo$ing formula consists of a single function that plots the s)uare roots of the closing prices. The names of the
actual functions in the follo$ing examples are in old.
s)rt( 41.S% )
The follo$ing formula consists of a single function that plots a 7F-period 6SI indicator.
rsi(7F)
The follo$ing formula consists of a single function that plots a 78-period simple moving average.
Trang 3 Ngun: XLanh11
Metastock Formula Language
mov(c,78,s)
The follo$ing formula consists of t$o functions. The result is the difference et$een the M'4+ indicator and a G-
period exponential moving average of the M'4+.
macd()- mov(macd(),G,exponential)
's youHve proaly noticed, this syntax is very similar to the syntax used to enter formulas in spreadsheets.
'll functions must e follo$ed y a pair of parentheses. If an opening parenthesis is not the first character after a
function name, an error message $ill e displayed.
Function Parameters
*arameters provide a function the necessary information re)uired to calculate. (or example, the s)rt() function
re)uires a single /parameter/ $ithin the parentheses. .ther functions, such as macd(), do not re)uire any parameters.
.thers, like the 5olume .scillator re)uire four parameters.
The follo$ing formula calculates a 7F-period Money (lo$ Index. The actual parameters are in old in the follo$ing
examples.
mfi(7F)
Some functions re)uire multiple parameters $ithin the parentheses. (or example, the moving average function
(sho$n elo$) re)uires three parameters.
mov(rsi(7F),I8,simple)
In the aove formula, the parameters instruct MetaStock to calculate a I8-period simple moving average of a 7F-
period 6SI. 0ote that another function (i.e., rsi(7F) ) serves as one of the parameters.
If you forget to insert the proper parameter, MetaStock $ill display a $indo$ reminding you of the expected
parameter.
M(I(7F).
M.5(rsi(7F),I8,simple)
Locating rrors in Formulas:
MetaStock does an excellent Jo of reporting errors in formulas. In fact, it is impossile to enter an invalid formula.
This doesnHt mean your formulas $ill al$ays $ork as you expect them to, ecause MetaStock does not kno$ $hat
you are trying to create. 3o$ever, it does mean that the syntax of the formula (e.g., function names, parameters,
operators, parentheses, etc.) $ill al$ays e valid.
;hen you enter a formula, MetaStock tests the formulaHs syntax. If an error is found, the formula $ill e redisplayed,
the cursor $ill e positioned at the error location, and a message explaining the error $ill e displayed.
Trang 4 Ngun: XLanh11
Metastock Formula Language
The effect of this error-reporting techni)ue is that MetaStock helps you enter valid formulas. This is illustrated in the
follo$ing example.
Suppose you $ant to plot a formula containing a 78-period exponential moving average of the closing price and all
you can rememer is that the moving average function is /mov/.
7. %nter $hat you do kno$ in the (ormula ox of the Indicator %ditor dialog-
mov
and click the ., utton.
The cursor $ill e positioned after the /mov/ function name and the message /' H(H must immediately follo$ a
function name/ $ill e displayed.
:. 0o$ add an opening parenthesis
mov(
and click .,.
This time, the cursor $ill e positioned after the /(/ and the message /*rice array (e.g., 3I=3, 1.;, 41.S%, etc.) or
function expected/ $ill e displayed.
I. %nter the price array identifier /41.S%./
mov(41.S%
and click .,.
If you continue this process (i.e., enter partial formulas and then respond to the error message), MetaStock $ill
prompt you through the formula entry process until the formulaHs syntax is correct (sho$n elo$).
Trang 5 Ngun: XLanh11
Metastock Formula Language
mov(41.S%,78,%K*.0%0TI'1)
This is a valuale techni)ueL 'ny time you are not sure of the syntax of a formula or function, click .,.
Inserting Functions
The preceding section explained ho$ MetaStock helps you correct syntax errors $ithin formulas. This section
explains ho$ MetaStock can help you rememer (and enter) the :88! functions.
4licking the (unctions utton $hile editing a formula displays the *aste (unctions dialog. This dialog lists the
categories of the availale functions on the left-hand side and the function names $ithin the category on the right-
hand side.
4licking ., $hen the Paste Functions dialog is displayed $ill insert the function that is currently highlighted into
your formula (at the location of the cursor). The function can e inserted $ith a description of the re)uired arguments
(if re)uired) y checking the *aste 'rguments checkox. The list on the right side of the dialog can display the actual
function names or the %nglish names of the functions y checking"unchecking the Sho$ %nglish 0ames checkox.
See Pasting Functions Into Formulas for more information on pasting functions into formulas.
.
Writing !omments
;hen $riting long, complex formulas, it is helpful to make comments throughout the formula to descrie $hat is
going on. %xperienced programmers $ill attest to the fact that the prudent use of comments makes programming
code much easier to deug and $ork $ith.
4omments can e entered in a formula y surrounding them $ith /M/ and /N/ races. The follo$ing formula contains
t$o comments (sho$n in old).
macd() Mthe M'4+ timesN # ((3!1!4) " I) Mthe average priceN
0ote that comments $ithin comments $ill cause an error message to e displayed.
"esting Functions
's has een eluded to in earlier examples, a function can e /nested/ $ithin a function. The nested function can
serve as the main functionHs data array parameter. The follo$ing examples sho$ functions nested $ithin functions.
The nested functions are in old.
Trang 6 Ngun: XLanh11
%xploring the *aste (uctions dialog is an excellent $ay to learn more aout formulas
Kem %nhaced System Testor
Metastock Formula Language
stdev( stoch(O,I), 78 )
mov( rsi(7O), 78, SIM*1%)
mov( mov( rsi(7O), :8, ;), 78, SIM*1%)
The first example calculates a stochastic oscillator and then calculates a 78-period standard deviation of the stochastic
oscillator.
The second example calculates a 78-period simple moving average of a 7O-period 6elative Strength Index (6SI).
The third example calculates a :8-period $eighted moving average of a 7O-period 6SI, and then calculates a 78-
period simple moving average of this moving average.
This techni)ue (placing functions $ithin functions) is referred to as the /nesting of functions./
#he if$% function:
The if() function is used to create conditional (i.e., /if-then/) statements. It is perhaps the most used function in the
MetaStock formula language. It contains three parameters as sho$n in the follo$ing example.
if( close 9 mov(c,78,s), rsi(G), rsi(7F) )
The aove /if/ statement reads (in %nglish) as follo$s- If todayHs close is greater than todayHs 78-day simple moving
average of the close, then plot a G-day 6SI, other$ise, plot a 7F-day 6SI.
The next formula plots /positive volume/ if the close is greater than the median price. .ther$ise, /negative volume/
is plotted.
if( 41.S% 9 (3I=3!1.;)":, !5, -5 )
' good example of the if() function can e found in the .n &alance 5olume example (see .n &alance 5olume).
If you simply $ant an expression to e evaluated as either true or false, it can e done $ithout the use of the if()
function. The follo$ing formula $ill result in either a 7 (true) or a 8 (false).
rsi(7F) 9 P8
If the 7F-period 6SI is greater than P8, then this formula $ill evaluate to /true/ and return the numer 7. If it is
elo$ P8, the formula $ill evaluate to /false/ and return the numer 8. This is done $ithout the if() function eing
used. The formula elo$ uses the if() function and $ill return the same results, ut it is longer.
if(rsi(7F) 9 P8, 7, 8 ).
&sing 'And' and 'Or' Operators
Trang 7 Ngun: XLanh11
Metastock Formula Language
If a formula re)uires multiple conditions, you can comine the conditions $ith /and/ and /or/ operators. (or
example, maye youHd like to plot a !7 $hen the M'4+ is greater than Qero and the 6SI is greater than P8. The
formula could e $ritten t$o $ays-
macd() 9 8 '0+ rsi(7F) 9 P8
or
if(macd() 9 8 and rsi(7F) 9 P8, !7, 8)
Rou can add as many conditions $ithin a formula as space allo$s. (or example-
If(macd() 9 8 '0+ rsi(7F) 9 P8 '0+ 44I(7F) 9 788 '0+ close 9 mov(close,78,e), !7, 8)
Rou can even comine '0+ and .6 operators $ithin the same formula as follo$s-
If((macd() 9 8 .6 close 9 mov(close,78,e)) '0+ rsi(7F) 9 P8, !7, 8)
The formula aove says to plot a /!7/ if either the M'4+ is greater than Qero or the close is aove its moving
average, and the 6SI is greater than P8.
0ote that parentheses $ere placed around the .6 condition ecause precedence specifies that the '0+ condition e
evaluated first (see .perator *recedence). If the parentheses $ere not placed around the .6 condition, the moving
average and the 6SI $ould have een grouped together $ith the '0+ condition, $hich is not ho$ $e $ant the
formula evaluated.
(eferencing )isting !ustom Indicators
Rou can reference other custom indicators using the fml() function. (or example, the function /fml( /My M'4+/)/
is the value of the formula that contains the text /My M'4+/ in its name. The entire name is not re)uired--only
enough of the name to make it uni)ue. 3o$ever, preference is given to the formula name that exactly matches. So if
another formula named /MyM'4+:/ existed, /MyM'4+/ $ould e used since it matches exactly.
The follo$ing formula plots the value of the formula named /+o$n +ay/ if the close is less-than-or-e)ual-to a 78-
period exponential moving average of the closing prices. .ther$ise, it plots the value of the formula named /Sp
+ay./
if( close <> mov(close, 78, %), fml(/+o$n +ay/), fml(/Sp +ay/) )
This techni)ue (referencing formulas from $ithin formulas) is referred to as the /nesting of formulas./ Ssing nested
formulas is an excellent $ay to simplify long and"or complex formulas.
'lso note, that nested formulas may reference nested formulas that reference nested formulas (etc.). 3o$ever,
circular references (e.g., formula /My M'4+/ calls formula /My 6SI/ that calls formula /My M'4+/) $ill cause
an error message to e displayed $hen the formula is plotted.
If a multiplot formula is referenced, only the value of last plot in the multiplot formula is returned.
Trang 8 Ngun: XLanh11
Metastock Formula Language
If you need to reference the value of a specific variale in a custom indicator rather than the value of the custom
indicator itself, use the fmlvar() function (see 6eferencing 5ariales $ithin 4ustom Indicators).
(eferencing *aria+les ,ithin !ustom Indicators
Since custom indicators can contain variales, you can reference a specific variale $ithin a custom indicator rather
than the entire custom indicator. The fmlvar() function is used to do this.
(or example, if the custom indicator named /MyM'4+/ contains a variale named /Signal1ine,/ and you only $ant
to reference the Signal1ine variale, it could e done as follo$s using the fmlvar() function-
fmlvar(/MyM'4+/, /Signal1ine/ )
If the variale does not exist $ithin the custom indicator, you $ill receive an error message.
(eferencing Securities ,ith the Security -ata Function
The Security +ata function allo$s a formula to access price data for any online or local security. This function can e
used in any of MetaStockHs formula tools.
.nline securities are referenced y including /.01I0%-/ efore the symol. 1ocal securities are referenced y
including the full path to the security file. If the security exists in the same folder as the ase security, the path does
not need to e included. The symol, including the path or online reference, is enclosed in )uotation marks.
To reference MicrosoftHs close as an online security-
Security(/.01I0%-MS(T/,4)
To reference MicrosoftHs close as a local security using the full path-
Security(/4-TMetastock +ataTSampleTMS(T/,4)
To reference MicrosoftHs close as a local security in the same folder as the ase security-
Security(/MS(T/,4)
The last type of reference is particularly useful if you use local data exclusively (AUc nhVt), and store all of your
securities in the same local data folder.
(or example, the follo$ing indicator displays a I8-day moving average of MicrosoftHs close on any chart, if your
online data vendor (cung cVp tW AUng) is active.
Mov(Security(/.01I0%-MS(T/,4),I8,S)
The same formula could e $ritten as-
Trang Ngun: XLanh11
Metastock Formula Language
Security(/.01I0%-MS(T/,Mov(4,I8,S))
Performance #ips
Sse Tick ()or 7-minute data for optimum() results $hen plotting an indicator on a chart $hich references online
intraday securities. Intervals higher than 7-minute must e compressed efore the indicator can e recalculated, $hich
slo$s calculation time.
X The 1ive &ars option found on the 6eal-time page of 'pplication *roperties (see 6eal-time *age) causes all
indicators on a chart to recalculate $ith each incoming tick. The Security +ata function is particularly slo$ $hen this
option is enaled. +isaling this option $ill cause all indicators, including the Security +ata function, to recalculate
only $hen the full ar has een completed.
X 6etrieving data from an online source is slo$er than referencing data in a local data file. 'ny formula using
the Security +ata function to access online data $ill take longer to calculate than $hen accessing only local data.
&sing *aria+les to nhance and Simplify
In order to shorten, simplify, enhance, and make the maintenance (duy trY) of complex formulas easier, you may $ant
to use variales. ' variale is an alphanumeric ame (up to :8 characters) that is assigned to an expression( iZu th[c)
or a single value. Sp to :8 variales can e used in a formula. 5ariales must e assigned efore the variale is used
in the formula. ' semi-colon must e used at the end of the variale assignment line. 5ariales cannot e assigned
$ithin a function.
"aming of *aria+les
The follo$ing rules apply to the naming of variales-
X 5ariale names cannot contain commas, parenthesis, spaces, underscores, etc.
X 5ariale names cannot duplicate names already used y functions (e.g., mov, rsi, cci, if, etc.).
X ' variale cannot e assigned a name that matches the parameters(tham s\) reserved for use in formulas (e.g.,
open, high, lo$, close, simple, o, c, l, h, s, e, $, etc.).
The follo$ing $ould produce an error, since the letter /s/ is reserved for the moving average function, mov(), to
mean /simple./
s:. $h/l/c%012
X 5ariale names must contain at least one alpha letter (e.g., T7:IF ).
X 5ariale names are not case sensitive (e.g., /*%6I.+S/ is the same as /periods/).
Trang 1! Ngun: XLanh11
Metastock Formula Language
&sing *aria+les to (epresent "um+ers
Suppose you $ould like to e ale to )uickly adJust the time periods throughout a formula $ithout having to edit
each use of the time periods individually. This could e accomplished y assigning the time periods to a variale]
in this case, a variale named /periods/.
periods :. 342
c 9 mov(c,periods, s) and ref(c,-7) 9 ref(mov(c,periods,s),-7) and h 9 mov(h,periods,s) and ref(h,-7) 9
ref(mov(h,periods,s),-7)
In the aove formula, the numer /78/ $ill e sustituted $herever the variale named /periods/ appears in the
formula. ;hen you $ant to adJust the time periods in this formula, simply edit the numer assigned to the /periods/
variale. If you change /78/ to /:8,/ the numer /:8/ $ill e sustituted throughout the formula.
.f course, you could also assign multiple variales to represent multiple numers as follo$s-
periods7 -> 78^
periods: -> :8^
c 9 mov(c,periods7, s) and ref(c,-7) 9 ref(mov(c,periods7,s),-7) and h 9 mov(h,periods:,s) and ref(h,-7) 9
ref(mov(h,periods:,s),-7)
In this case, the variales /periods7/ and /periods:/ represent t$o different values that can e used as many times as
desired throughout the formula.
&sing *aria+les to (epresent$mi5u t6% Mathematical )pressions
5ariales can e assigned to represent a mathematical expression (i.e., formula). *erhaps this is the most useful
enefit of variales. 'ssigning variales to represent formulas (especially long, complex ones) makes formulas easier
to read, easier to modify, and faster to calculate.
(or example, the follo$ing formula (designed to spot securities locked et$een support and resistance levels), is
)uite complex and difficult to read. It can e simplified y using variales. It $as originally $ritten efore variale
support $as added to MetaStockHs formula language.
(If('s((Trough(7,1,7)-Trough(:,1,7))"Trough(:,1,7))<.87O '0+ 's((Trough(:,1,7)-
Trough(I,1,7))"Trough(I,1,7))<.87O,MthenN (Trough(7,1,7)!Trough(:,1,7)!Trough(I,1,7))"I,8))<98
and
(If('s((*eak(7,3,7)-*eak(:,3,7))"*eak(:,3,7))<.87O '0+ 's((*eak(:,3,7)-*eak(I,3,7))"*eak(I,3,7))<.87O,
MthenN (*eak(7,3,7)!*eak(:,3,7)!*eak(I,3,7))"I,8))<98
and
Trang 11 Ngun: XLanh11
Metastock Formula Language
c9>(If('s((Trough(7,1,7)-Trough(:,1,7))"Trough(:,1,7))<.87O '0+ 's((Trough(:,1,7)-
trough(I,1,7))"Trough(I,1,7))<.87O,MthenN (Trough(7,1,7)!Trough(:,1,7)!Trough(I,1,7))"I,8)) and
c<>(If('s((*eak(7,3,7)-*eak(:,3,7))"*eak(:,3,7))<.87O '0+ 's((*eak(:,3,7)-*eak(I,3,7))"*eak(I,3,7))<.87O,
MthenN (*eak(7,3,7)!*eak(:,3,7)!*eak(I,3,7))"I,8)
&y defining t$o variales (in old) to represent the t$o expressions that are used repeatedly, you can simplify the
formula sustantially. In addition to eing easier to read, the simplified formula also calculates )uicker since the
support and resistance expressions no$ only need to calculate once.
Support-> (If('s((Trough(7,1,7)-trough(:,1,7))"Trough(:,1,7))<.87O '0+ 's((Trough(:,1,7)-
trough(I,1,7))"Trough(I,1,7))<.87O,MthenN (Trough(7,1,7)!Trough(:,1,7)!Trough(I,1,7))"I,8))^
6esistance-> (If('s((*eak(7,3,7)-*eak(:,3,7))"*eak(:,3,7))<.87O '0+ 's((*eak(:,3,7)-
*eak(I,3,7))"*eak(I,3,7))<.87O, MthenN(*eak(7,3,7)!*eak(:,3,7)!*eak(I,3,7))"I,8))^
Support <9 8 and 6esistance <9 8 and close 9> Support and close <> 6esistance
0ote that you could also create individual custom indicators named /support/ and /resistance/ to do the calculations.
(See 6eferencing %xisting 4ustom Indicators for more information on using the fml() function).The custom
indicators could then e called using the fml() function as follo$s-
fml(/support/) <9 8 and fml(/resistance/) <9 8 and close 9> fml(/support/) and close <> fml(/resistance/)
3o$ever, using variales is generally more desirale than using the fml() function for several reasons]the most
important eing calculation speed and self-containment (i.e., the entire function can e read and edited in one place).
(eferencing *aria+les ,ithin !ustom Indicators7
Since custom indicators can contain variales, you can reference a specific variale $ithin a custom indicator rather
than the entire custom indicator. The fmlvar() function is used to do this.
(or example, if the custom indicator named /MyM'4+/ contains a variale named /Signal1ine,/ and you only $ant
to reference the Signal1ine variale, it could e done as follo$s using the fmlvar() function-
fmlvar(/MyM'4+/, /Signal1ine/ )
If the variale does not exist $ithin the custom indicator, you $ill receive an error message.
Self (eferencing Formulas &sing P(*
The *6%5 constant allo$s you to create self-referencing formulas. ' self referencing formula is one that is ale to
reference the /previous/ periodHs value of itself.
(or example, the follo$ing is an example of a self referencing formula-
Trang 12 Ngun: XLanh11
Metastock Formula Language
((3!1!4)"I) ! *6%5
This simple formula divides the high, lo$, and closing prices y I and then adds this value to yesterdayHs value of the
((3!1!4)"I).
The calculation of the popular indicator .n &alance 5olume illustrates the use of the *6%5 function.
(if(c9ref(c,-7),7,-7)#volume)!*6%5
'lthough .n &alance 5olume can e calculated $ithout the use of the *6%5 function, an exponential moving
average cannot (other than using the mov() function). The follo$ing formula sho$s ho$ a 7_` exponential moving
average (approximately 78-periods) is calculated using the *6%5 function.
(close#8.7_)!(*6%5#8._:)
Self8(eferencing Formula !alculations
Rou are using the *6%5 variale in a location $ithin a custom indicator that $ill cause the calculation to e very
slo$. Rou should normally try to avoid using the *6%5 variale as a +'T' '66'R $hen there is also a *%6I.+S
specified (e.g., mov(prev, :8, s), hhv(prev, I8), etc.). 'lthough use of the *6%5 function in this $ay is allo$ale, it
$ill take a long time to calculate, particularly if a lot of data is loaded in the chart.
#he 'P' -ata Array Identifier
' special data array identifier (i.e., /*/ variale) is used to reference any indicator or price plot. ;ith custom
indicators, the /*/ variale represents the plot the custom indicator is dropped on.
;ith system tests and explorations, the /*/ variale represents the selected plot( Aanh dVu trbn cn Ad,veng gia trf
nhg). This may e useful if you $ant an indicator, exploration, system test, or expert to calculate on a plot other than
the chartHs ase security.
If you drop a custom indicator containing the /*/ variale on high"lo$"close price ars, the close is used for the /*/
variale. (or example, the follo$ing custom indicator plots an /M'4+-type/ indicator (i.e., the difference et$een
7:- and :h-period exponential moving averages) of the plot it is dropped on.
mov( *, 7:, %) - mov( *, :h, %)
If you plot the predefined 'ccumulation"+istriution indicator and then drop the aove custom indicator on it from
the iuick1ist, the result $ill e an M'4+ of the 'ccumulation"+istriution indicator.
.f course, you could $rite the preceding formula $ithout using the /*/ identifier as sho$n elo$, ut you $ould
have to modify it if you $anted an M'4+ of an indicator other than the 'ccumulation" +istriution. &y using the
/*/ identifier, the formula ecomes more versatile.
mov( ad(), 7:, %) - mov( ad(), :h, %)
Trang 13 Ngun: XLanh11
Metastock Formula Language
In a custom indicator, the values for 3I=3, 1.;, 41.S%, 5.1SM%, .*%0, and .*%0 I0T%6%ST al$ays come
from the ase security. (or example, if you drop the custom indicator /3I=3 - 1.; " */ on a price plot that is not
the chartHs ase security, the 3I=3 and 1.; values $ill still come from the ase security. The /*/ value $ill
represent the 41.S% of the security it $as dropped on.
More-
#o plot a custom indicator ,ith the 'P' 9aria+le
7. ;rite a custom indicator using the /*/ variale in place of the data array identifier (e.g., mov(p,78,e),
sum(p,:O), stdev(p,7:), etc.).
:. +rag ( k?o) the custom indicator from the iuick1ist and drop it on the plot you $ant the /*/ variale to
calculate on.
#o run a system test: e)ploration: or e)pert that contains a 'P' 9aria+le
7. ;rite a system test, exploration, or expert using the /*/ variale in place of the data array identifier (e.g.,
mov(p,78,e), sum(p,:O), stdev(p,7:), etc.).
:. Select the plot (i.e., indicator or price plot) to use for the /*/ variale y clicking directly on the plot. The
plot is selected $hen small s)uare /handles/ appear on the plot.
I. 6un the system test or exploration.
Formula #ips
=eneral
The t$o most important /formula tips/ have already een mentioned- (7) use the *aste (ormula dialog (see Inserting
(unctions) and (:) click ., $hen entering a formula to check its syntax (see 1ocating %rrors in (ormulas).
Multiple Indented (ljm, thkt ) 1ines
;hen $riting long custom indicators, you should try to use multiple lines and consistent indentation (xEp thkt chl
vmo) for ease of reading. Rou can indent a line of the formula y typing 4T61!T'&. (or example, the formulan
cum(if(close 9 ref(close,-7),!5, if(close < ref(close,-7),-5,8)))
is easier to read on multiple indented lines as follo$s-
cum(
if(close 9 ref(close,-7),
!v,
if(close < ref(close,-7),
Trang 14 Ngun: XLanh11
Metastock Formula Language
-v,
8))
)
Spper versus 1o$er-case 4haracters
The case used $hen entering formulas does not matter (e.g., /c/ and /4/ are treated the same). ;hen MetaStock
checks for syntax errors, it automatically modifies the case to make the formula easier to read. The case $ithin
comments is not altered.
4omments
The prudent use of comments makes formulas easier to read. (6ememer, comments are any text enclosed in races,
i.e., MN.)
Rou can use comments $hile developing formulas to /comment out/ sections of the formula. (or example, the
second half of the follo$ing formula has een commented out so the first half can e tested. 'fter the first half of the
formula has een tested, you can remove the comments and test the entire formula.
( mov(fml(/M'7/),78,S) " fml(/M':/) ) M # stoch(O,I) N
Spacing
&lank spaces $ithin formulas are optional. 3o$ever, the prudent use of spaces can make formulas easier to read.
4lipoard 4ommands
Rou can use the standard clipoard command accelerator keys $hile editing custom indicators to transfer formulas
from one custom indicator to another. To copy the highlighted text, press 4T61!4^ to cut, press 4T61!K^ to paste,
press 4T61!5.
5ariales
Sse variales to speed up the calculation of formulas. 6ather than repeating an expression or formula over and over,
assign it to a variale and then reference the variale.
&sing the Formula Organi;er to Import and )port
The (ormula .rganiQer is a $iQard that allo$s you to import and export any MetaStock formula-ased files including
custom indicators, system tests, explorations, and experts. (or example, you can use the (ormula .rganiQer to import
a set of add-on custom indicators, experts, etc. purchasedfrom a third party. Rou could also create a set of add-on
indicators, explorations, etc. to distriute to your colleagues, and even protect your formulas $ith a pass$ord.
Trang 15 Ngun: XLanh11
Metastock Formula Language
Starting $ith your custom indicators, the (ormula .rganiQer $iQard $ill $alk you through the steps necessary to
import and"or export your files. To protect your formulas $ith a pass$ord, choose the export option, then enter a
pass$ord $hen prompted.
More-
#o import0e)port custom indicators: system tests: e)plorations: and0or e)perts
7. 6un MetaStock.
:. 4hoose Indicator &uilder from the Tools menu.
I. 4lick the .rganiQe utton to launch the (ormula .rganiQer ;iQard.
F. (ollo$ the on-screen instructions.
<lossary
This glossary defines the terms used $ith the MetaStock formula language. Snderstanding (or rememering) these
terms is not re)uired, ho$ever, adding these terms to your vocaulary $ill make discussion easier $ith other
MetaStock analysts.
4.MM%0T- Text $ithin a formula that is not part of the formula. ' comment must e surrounded y the characters
M and N.
4.0ST'0T- ' specific type of parameter that is re)uired y a function. 4onstants can e sudivided ( ABCc chia
nhg ra) into the follo$ing groups-
4'14S1'TI.0 M%T3.+ 4.0ST'0T- Ssed to define the mode of calculation. +efined as *%64%0T or
*.I0TS. (*%64%0T and *.I0TS can e areviated to ` or o.)
4.M*'6IS.0 4.0ST'0T- Ssed in the if() function to define the comparison operation. +efined y 9, 9>, <, <>,
<9, or >.
(.6MS1' 4.0ST'0T- Ssed $ithin the fml() function to reference another formula. ' formula constant is
specified as the name of another formula enclosed in )uotation marks (e.g., fml( /My (ormula/ ) ).
M.5I0= '5%6'=% TR*% 4.0ST'0T- Ssed to define the moving average calculation method. +efined as
%K*.0%0TI'1, SIM*1%, TIM% S%6I%S, T6I'0=S1'6, 5'6I'&1%, or ;%I=3T%+. (These can e
areviated as %, S, T, T6I, 5'6, and ;.)
0SM%6I4 4.0ST'0T- ' single numeric value. ' function re)uiring a numeric constant cannot accept a data
array since a data array may contain multiple, rather than single, numeric values. 'n example of a numeric constant
is the /78/ in the formula /mov(4,78,%)./
+'T' '66'R- ' data array defines a specific set of information (data) that is used $ithin a formula. +ata arrays
can e sudivided into more specific definitions-
Trang 16 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 6%SS1T '66'R- ' data array that is created as the result of the execution of a function.
1IT%6'1 '66'R- ' data array defined using a single numeric constant.
*6I4% '66'R- 'n array containing the information stored in the high, lo$, close, etc., data arrays.
(.6MS1'- ' comination of comments, constants, functions, mathematical operators and"or price array identifiers.
(S04TI.0- ' pre-defined mathematical operation that can e performed on a set of parameters to produce a
desired data array.
.*%6'T.6, M'T3%M'TI4'1- The !, -, #, and " operators.
.*%6'T.6, 1.=I4'1- The <, 9, <>, 9>, >, <9, '0+, and .6 operators.
*'6'M%T%6- 'n item contained $ithin a function. ;hen a function has multiple parameters, they are separated
y commas.
*6%4%+%04%- The order in $hich a formula is evaluated (see .perator *recedence).
*6I4% '66'R I+%0TI(I%6S- The letters or $ords used to reference price arrays (.pen, 3igh, 1o$, 4lose,
5olume, .pen Interest, *6%5, and the selected *lot).
rror Messages
Most of the error messages that are displayed $hen you enter and plot custom indicators are self-explanatory. This
section clarifies some of the more common error messages.
' reference to a formula name is no longer valid.
This error occurs $hen a formula is plotted containing a reference (i.e., /fml()/) to a non-existent formula name.
+oes not contain an executale formula.
'n attempt $as made to execute a custom indicator that does not contain a valid formula.
(ormula too complex.
This error is caused y functions (not formulas) eing nested too deeply or y a complex mathematical expression
that uses numerous mathematical operators that are not grouped using parentheses.
=rouping operators $ith parentheses may fix this prolem. 3o$ever, a etter solution is to split the too-complex
formula into smaller formulas and then nest the smaller formulas using the fml() function (see (ormula 4all).
Insufficient memory to continue formula execution.
Trang 17 Ngun: XLanh11
Metastock Formula Language
MetaStock ran out of memory to store temporary values.
This can e alleviated y reducing the numer of periods of data currently loaded or y reducing references to nested
formulas.
.verflo$ in function.
The result of a formula calculation generated a value that $as too large to store.
The formula must e modified to produce results $ith smaller values (e.g., divide certain data arrays or function
results y 788).
Too many numeric constants defined in formula.
' maximum of :8 different numeric constants (see =lossary) may e used in each formula.
This error can e eliminated y splitting the formula that received the error into smaller formulas and then nesting the
smaller formulas using the fml() function (see (ormula 4all).
5alue out of valid range in function.
' parameter in a function is invalid.
%xamples-
The formula /mov(4, -O, %)/ $ill al$ays generate this message, ecause -O is not a valid moving average time
period.
The formula /mov(4, :88, %)/ $ill generate this message if fe$er than :88 time periods of data are loaded.
The formula /mov(macd(), PF, %)/ $ill generate this message if fe$er than 788 time periods are loaded. This is
ecause the M'4+ does not plot until the :hth day, $hich leaves fe$er than PF periods to calculate a PF-day moving
average.
Rou should edit the formula and change the invalid parameter, or load more time periods.
Standard Functions:
37 A+solute *alue:
SR0T'K as( +'T' '66'R )
(S04TI.0 4alculates the asolute value of the +'T' '66'R.
Trang 18 Ngun: XLanh11
Metastock Formula Language
%K'M*1% The formula /as( -78 )/ $ill return !78^ the formula /as( 78 )/ also returns !78.
=7 Accumulation0-istri+ution:
SR0T'K ad()
(S04TI.0 4alculates the predefined 'ccumulation" +istriution indicator.
17 Accumulation S,ing Inde):
SR0T'K as$ing( 1IMIT M.5% )
(S04TI.0 4alculates the predefined 'ccumulation S$ing Index. The S$ing Index re)uires opening prices.
%K'M*1% as$ing( I.8 )
S%% '1S. The s$ing() function (see S$ing Index).
>7 Addition
SR0T'K add( +'T' '66'R, +'T' '66'R )
(S04TI.0 'dds the t$o parameters together.
%K'M*1% The formula /add( 3, 78.P )/ adds 78.P to the high prices (this formula also could e $ritten as /3 !
78.P/).
S%% '1S. The su() function (see Sutraction).
?7 Alert
SR0T'K alert( %K*6%SSI.0, *%6I.+S )
(S04TI.0 %xtends a /true/ result of %K*6%SSI.0 for the specified numer of periods. This true result is held
true over the numer of periods specified even if a /false/ result is generated.
%K'M*1% alert( cross(rsi(7F),P8),O )
S%% '1S. See Ssing the Alert$% Function for information on using the 'lert function $ithin a system test.
#he alert$% function is used in conJunction $ith other functions to extend a true signal for a specified numer of
periods. The signal is held true over the specified numer of periods even if another trade is generated.
The follo$ing example illustrates the use of the alert() function-
Trang 1 Ngun: XLanh11
Metastock Formula Language
&uy- 6SI(7F) < I8 '0+ alert(5.1SM% 9 O88,I)
If this $ere entered as the %nter 1ong rule, the system $ould enter a long position $hen the 6SI $as less than I8 and
the volume had een greater than O88 at any time over the previous three time periods. The /5.1SM% 9 O88/
condition holds true over the entire three time periods even if the volume drops elo$ O88 during that three period
time span.
If you removed the alert() function in the aove example, oth conditions (i.e., 6SI(7F) < I8 and 5.1SM% 9 O88)
$ould have to e true simultaneously in order for the %nter 1ong signal to e generated. &y using the alert()
function, a true condition generated y the /5.1SM% 9 O88/ condition is extended over a three period time span.
@7 Arc #angent
SR0T'K atan( R +'T' '66'R, K +'T' '66'R )
(S04TI.0 6eturns the arc tangent of R"K. The value is returned in degrees from 8 to IOG.G. The degrees are
returned as sho$n elo$-
%K'M*1% The formula /atan( 78, 8 )/ returns G8.
S%% '1S. The cos() function (see 4osine) ^ the sin() function (see Sine).
!osine
SR0T'K cos( +'T' '66'R )
(S04TI.0 6eturns the cosine of +'T' '66'R. 'ssumes that the +'T' '66'R values are in degrees.
%K'M*1% cos( 4 )
S%% '1S. The atan() function (see 'rc Tangent)^ the sin() function (see Sine).
Sine
SR0T'K sin( +'T' '66'R )
(S04TI.0 6eturns the sine of +'T' '66'R. This function assumes that the +'T' '66'R values are in
degrees.
%K'M*1% Rou can plot a sine $ave using the formula /sin(cum(O))./ Increasing the value in this formula (i.e.,
/O/) $ill increase the fre)uency of the sine $ave.
S%% '1S. The atan() function (see 'rc Tangent)^ the cos() function (see 4osine).
Trang 2! Ngun: XLanh11
Metastock Formula Language
A7 Aroon -o,n
SR0T'K aroondo$n( *%6I.+S )
(S04TI.0 4alculates the 'roon +o$n component ( hCp thmnh) of the 'roon indicator.
%K'M*1% aroondo$n( 7F )
B7 Aroon &p
SR0T'K aroonup( *%6I.+S )
(S04TI.0 4alculates the 'roon Sp component of the 'roon indicator.
%K'M*1% aroonup( 7F )
C7 A9erage -irectional Mo9ement
SR0T'K adx( *%6I.+S )
(S04TI.0 4alculates the predefined 'verage +irectional Movement indicator.
%K'M*1% adx( 7F )
S%% '1S. The adxr() function (see +irectional Movement 6ating) ^ the csi() function (see 4ommodity Selection
Index)^ the dx() function (see +irectional Movement Index)^ the mdi() function (see Minus +irectional Movement) ^
the pdi() function (see *lus +irectional Movement) .
347A9erage #rue (ange:
SR0T'K atr( *%6I.+S )
(S04TI.0 4alculates the predefined 'verage True 6ange indicator.
%K'M*1% atr( :8 )
337 Dars Since:
SR0T'K arssince( +'T' '66'R )
(S04TI.0 4alculates the numer of ars (time periods) that have passed since +'T' '66'R $as true.
Trang 21 Ngun: XLanh11
Metastock Formula Language
Important- ;hen using the arssince() function in an exploration, you must choose the /1oad ppp 6ecords/ utton in
the %xplorer .ptions dialog (see %xplorer .ptions) and specify a value e)ual to the numer of ars loaded in your
chart^ other$ise, the exploration results may not e accurate.
%K'M*1% arssince( macd() < 8 )
3=7Dollinger Dand Dottom:
SR0T'K andot( +'T' '66'R, *%6I.+S, M%T3.+, +%5I'TI.0S )
(S04TI.0 4alculates the ottom (dBqi ceng) &ollinger &and of +'T' '66'R using M%T3.+ calculation
method and shifted do$n$ard +%5I'TI.0 standard deviations. 5alid methods are SIM*1%, %K*.0%0TI'1,
;%I=3T%+, TIM%S%6I%S, T6I'0=S1'6, and 5'6I'&1% (these can e areviated as S, %, ;, T, T6I, and
5'6).
%K'M*1% andot( close, 78, S, : )
317Dollinger Dand #op:
SR0T'K andtop( +'T' '66'R, *%6I.+S, M%T3.+, +%5I'TI.0S )
(S04TI.0 4alculates the top &ollinger &and of +'T' '66'R using M%T3.+ calculation method and shifted
up$ard +%5I'TI.0 standard deviations. 5alid methods are SIM*1%, %K*.0%0TI'1, ;%I=3T%+,
TIM%S%6I%S, T6I'0=S1'6, and 5'6I'&1% (these can e areviated as S, %, ;, T, T6I, and 5'6).
%K'M*1% andtop( close, 78, S, : ).
3>7Duying Pressure:
SR0T'K uyp()
(S04TI.0 4alculates the uying pressure component of the +emand Index (see +emand Index). &uying
pressure is a measurement of the amount of volume related to uying.
3?7!eiling:
SR0T'K ceiling( +'T' '66'R )
(S04TI.0 4alculates the lo$est integer that is greater than +'T' '66'R.
%K'M*1% The formula /ceiling( P.: )/ returns _^ the formula /ceiling(-P.:)/ returns -P.
S%% '1S. The floor() function (see (loor)^ the int() function (see Integer).
Trang 22 Ngun: XLanh11
Metastock Formula Language
3@7!haikin A0- Oscillator:
SR0T'K co()
(S04TI.0 4alculates the predefined 4haikin .scillator.
3A7!haikinEs Money Flo,:
SR0T'K cmf( *%6I.+S )
(S04TI.0 4alculates the predefined 4haikin Money (lo$ indicator over the last *%6I.+ numer of periods.
%K'M*1% cmf(7F)
3B7!hande Momentum Oscillator:
SR0T'K cmo( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined 4hande Momentum .scillator of +'T' '66'R over the last *%6I.+
numer of periods.
%K'M*1% cmo( c,7F ).
3C7!ommodity !hannel Inde) $F&IS%:
SR0T'K ccie( *%6I.+S )
(S04TI.0 4alculates the predefined 4ommodity 4hannel Index (%iSIS).
%K'M*1% ccie( 7F )
=47!ommodity !hannel Inde) $Standard%
SR0T'K cci( *%6I.+S )
(S04TI.0 4alculates the predefined 4ommodity 4hannel Index (Standard).
%K'M*1% cci( 7F )
=37!ommodity Selection Inde)
SR0T'K csi( *%6I.+S, 5'1S%, M'6=I0, 4.MMISSI.0 )
(S04TI.0 4alculates the predefined 4ommodity Selection Index.
%K'M*1% csi(7F, O8, :O88,:O)
Trang 23 Ngun: XLanh11
Metastock Formula Language
S%% '1S. The adx() function (see 'verage +irectional Movement)^ the adxr() functi+irectional Movement
6ating)^ the dx() function (see +irectional Movement Index)^ the mdi() function (see Minus +irectional Movement)^
the pdi() function (see *lus +irectional Movement).
==7!orrelation Analysis
SR0T'K correl( I0+%*%0+%0T, +%*%0+%0T,*%6I.+S, S3I(T)
(S04TI.0 4alculates the predefined 4orrelation indicator. 4ompares the correlation of +%*%0+%0T to
I0+%*%0+%0T over *%6I.+S time periods, after shifting +%*%0+%0T to the right S3I(T-periods.
%K'M*1% The formula /correl( macd(), 41.S%, O, 78 )/ compares the M'4+ indicator to the closing
price 78-periods in the future, after statistically averaging each data array over the preceding O-periods.
S%% '1S. The tsf() function (see Time Series (orecast)^ the stdev() function (see Standard +eviation).
=17!osine
SR0T'K cos( +'T' '66'R )
(S04TI.0 6eturns the cosine of +'T' '66'R. 'ssumes that the +'T' '66'R values are in degrees.
%K'M*1% cos( 4 )
S%% '1S. The atan() function (see 'rc Tangent)^ the sin() function (see Sine).
=>7!ross
SR0T'K cross( +'T' '66'R 7, +'T' '66'R : )
(S04TI.0 *lots a /!7/ on the day that +'T' '66'R 7 crosses aove +'T' '66'R :. .ther$ise, /8/ is
plotted.
If you $ant to kno$ $hen +'T' '66'R 7 crosses elo$ +'T' '66'R :, use the formula /cross( +'T' '66'R
:, +'T' '66'R 7)/
%K'M*1% cross( close, mov(close,G,e) )
=?7!umulate
SR0T'K cum( +'T' '66'R )
(S04TI.0 4alculates a cumulative sum of the +'T' '66'R from the first period in the chart.
Trang 24 Ngun: XLanh11
Metastock Formula Language
%K'M*1% The formula /cum( 7 )/ calculates an indicator that rises one point for each day since the
eginning of the chart^ the formula /cum( 4 )/ calculates the cumulative total of all closing prices from the
eginning of the chart.
S%% '1S. The sum() function (see Summation).
=@7-ay Of Month
SR0T'K dayofmonth()
(S04TI.0 *lots the day of the month. If today $as ruly 7Oth, /7O/ $ould e plotted.
=A7-ay Of Week
SR0T'K dayof$eek()
(S04TI.0 *lots the day of the $eek. 7>Monday, :>Tuesday, I>;ednesday, F>Thursday, O>(riday, h>Saturday,
P>Sunday.
=B7-elta
SR0T'K delta( TR*%, +'T%, *6I4%, I0T%6%ST, +I5I+%0+ )
(S04TI.0 4alculates the predefined +elta indicator. See the option() function (*ut"4all *rice) for a description
of the parameters used in the delta() function.
%K'M*1% delta( %4, Gh7::8, 7:O, P.O8, F.PO )
S%% '1S. The gamma() function (see =amma)^ the life() function (see .ption 1ife) ^ the option() function (see
*ut"4all *rice)^ the theta() function (see Theta)^ the vega() function (see 5ega)^ and the volo() function (see 5olatility,
.ption).
=C7-ema
SR0T'K dema( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined +%M' indicator
%K'M*1% dema( c,7F )
S%% '1S. The tema() function (see Tema).
147-emand Inde)
SR0T'K di()
Trang 25 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the predefined +emand Index.
137-etrended Price Oscillator
SR0T'K dpo( *%6I.+S )
(S04TI.0 4alculates the predefined +etrended *rice .scillator.
%K'M*1% dpo( :O )
1=7-irectional Mo9ement Inde)
SR0T'K dx( *%6I.+S )
(S04TI.0 4alculates the predefined +irectional Movement Index.
%K'M*1% dx( 7F )
S%% '1S. The adx() function (see 'verage +irectional Movement)^ the adxr() functi+irectional
Movement 6ating)^ the csi() function (see 4ommodity Selection Index)^ the mdi() function (see Minus
+irectional Movement)^ the pdi() function (see *lus +irectional Movement)
117-irectional Mo9ement (ating
SR0T'K adxr( *%6I.+S )
(S04TI.0 4alculates the predefined +irectional Movement 6ating.
%K'M*1% adxr( 7F )
S%% '1S. The adx() function (see 'verage +irectional Movement)^ the dx() function (see +irectional
Movement Index)^ the csi() function (see 4ommodity Selection Index)^ the mdi() function (see Minus +irectional
Movement)^ the pdi() function (see *lus +irectional Movement)
1>7-i9ergence
SR0T'K divergence( +'T' '66'R 7, +'T' '66'R :, ` MI0IMSM 43'0=% )
(S04TI.0 *lots a !7 if +'T' '66'R 7 diverges from +'T' '66'R : (i.e., +'T' '66'R 7 is
increasing and +'T' '66'R : is decreasing). *lots a -7 if +'T' '66'R 7 converges from +'T' '66'R :
(i.e., +'T' '66'R 7 is decreasing and +'T' '66'R : is increasing). ' Qero is plotted if they are moving in
the same direction. Movements in +'T' '66'R 7 less than ` MI0IMSM 43'0=% are ignored.
Trang 26 Ngun: XLanh11
Metastock Formula Language
The +ivergence function is ased on the sig sag formula. (irst, a ` MI0IMSM 43'0=% sig sag is calculated
for +'T' '66'R 7. 0ext, a sig sag is calculated for +'T' '66'R : using the ` MI0IMSM 43'0=%
re)uired to match the numer of sig sag segments in +'T' '66'R 7 over the data range loaded. The t$o sig
sags are then compared for divergence and convergence.
%K'M*1% The formula /divergence( close, rsi(:7), I )/ looks for divergences et$een the close and a :7-
period 6SI. Movements in the close less than I` are ignored.
1?7-i9ision
SR0T'K div( +'T' '66'R, +'T' '66'R )
(S04TI.0 +ivides the first parameter y the second. +ivision y Qero produces a result of Qero.
%K'M*1% The formula /div( 78, : )/ returns O (this formula also could e $ritten as /78 " :/).
S%% '1S. The mul() function (see Multiplication).
1@7-ynamic Momentum Inde)
SR0T'K dmi( +'T' '66'R )
(S04TI.0 4alculates the predefined +ynamic Momentum Index.
%K'M*1% dmi( 41.S% )
1A7ase of Mo9ement
SR0T'K emv(*%6I.+S, M%T3.+)
(S04TI.0 4alculates a *%6I.+S moving average of the %ase of Movement value using M%T3.+
calculation method. 5alid methods are SIM*1%, %K*.0%0TI'1, ;%I=3T%+, TIM%S%6I%S,
T6I'0=S1'6, and 5'6I'&1%. (These can e areviated as S, %, ;, T, T6I, and 5'6.)
%K'M*1% The formula /emv(7F,S)/ returns the value of the %ase of Movement indicator smoothed $ith a
7F-period simple moving average.
1B7)ponent
SR0T'K exp( +'T' '66'R )
(S04TI.0 4alculates e raised to the +'T' '66'R po$er.
S%% '1S. The log() function (see 1ogarithm (natural)).
1C7)ternal Formula
Trang 27 Ngun: XLanh11
Metastock Formula Language
SR0T'K %xt(ml(/+11 0'M%.(S04TI.0 0'M%/,argument 7,n,argument n)
(S04TI.0 6eturns the values of the function contained in an MSK +11. This is only availale if an
MSK +11 is present.
%K'M*1% %xt(ml(/My+11.My(unction/,close) $ould reference a function called My(unction
contained in the MSK +11 called My+11, and use the closing price of the security in its calculation.
(or more information on the %)uis Solution *rovider program and the MetaStock +evelopers ,it go to
http-""$$$.e)uis.com.
>47Fast Fourier #ransform
SR0T'K fft( +'T' '66'R, *%6I.+S, 1%0=T3, +%T6%0+ or M%'0, 'M*1ITS+% or *.;%6 )
(S04TI.0 4alculates the *%6I.+S time period (ourier indicator of the +'T' '66'R, given sample
1%0=T3 using the +%T6%0+ or M%'0 method, and displays the 'M*1ITS+% or *.;%6 spectrum.
%K'M*1% The formula /fft( 41.S%, 788, 7, +%T6%0+, *.;%6 )/ returns the default (ast (ourier
indicator.
>37Floor
SR0T'K floor( +'T' '66'R )
(S04TI.0 4alculates the highest integer that is less than +'T' '66'R.
%K'M*1% The function /floor( 7I.G )/ returns 7I. The formula /floor( -7I.G )/ returns -7F.
S%% '1S. The ceiling() function (see 4eiling)^ the int() function (see Integer).
>=7Forecast Oscillator
SR0T'K forecastosc( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined (orecast .scillator.
%K'M*1% forecastosc( close, 7F )
>17Formula !all
SR0T'K fml(/(.6MS1'p0'M%/ )
Trang 28 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the value of another formula. The formula can e referenced using the
(.6MS1'p0'M% in )uotes.
;hen referencing a formulaHs name, the name must e contained in )uotation marks (e.g., fml( /Secret '/)).
If you change a formulaHs name, you must also change any fml() calls that reference that formula.
%K'M*1% The formula /fml(/Secret '/) # fml(/MyM'4+/)/ calculates the value of the formula named
/Secret '/ multiplied y /MyM'4+./
S%% '1S. See 6eferencing %xisting 4ustom Indicators for more details on using the fml() function.
>>7Formula *aria+le !all
SR0T'K fmlvar( /(.6MS1'p0'M%/, /5'6I'&1%p0'M%/)
(S04TI.0 4alls the custom indicator named (.6MS1'p0'M% and returns the value contained in the
custom indicatorHs variale named 5'6I'&1%p0'M%.
&oth the formulaHs name and the varialeHs name must e contained in )uotation marks (e.g., fmlvar( /Secret '/,
/My5ar/)).
If you change a formula or variale name, you must also change any fmvarl() calls that reference that formula and
variale.
%K'M*1% fmlvar(/MyIndicator/, /My5ariale'/ )
S%% '1S. See 6eferencing 5ariales $ithin 4ustom Indicators for more details on using the fmlvar()
function.
>?7Fraction
SR0T'K frac( +'T' '66'R )
(S04TI.0 %liminates the integer portion of +'T' '66'R and returns the fractional part.
%K'M*1% The formula /frac( 78.P )/ returns 8.P^ the formula /frac(-7G._ )/ returns -8._.
>@7<amma
Trang 2 Ngun: XLanh11
Metastock Formula Language
SR0T'K gamma( TR*%, +'T%, *6I4%, I0T%6%ST, +I5I+%0+ )
(S04TI.0 4alculates the predefined =amma indicator. See the option() function (*ut"4all *rice) for a
description of the parameters used in the gamma() function.
%K'M*1% gamma( %4, Gh7::8, 7:O, P.O8, F.PO )
S%% '1S. The delta() function (see +elta)^ the life() function (see .ption 1ife) ^ the option() function (see
*ut"4all *rice)^ the theta() function (see Theta)^ the vega() function (see 5ega)^ and the volo() function (see
5olatility, .ption).
>A7<ap -o,n
SR0T'K gapdo$n()
(S04TI.0 *lots a /!7/ on the day a securityHs prices gap do$n. .ther$ise a /8/ is plotted. ' gap do$n
occurs if yesterdayHs lo$ is greater than todayHs high.
>B7<ap &p
SR0T'K gapup()
(S04TI.0 *lots a /!7/ on the day a securityHs prices gap up. .ther$ise a /8/ is plotted. ' gap up occurs
if yesterdayHs high is less than todayHs lo$.
>C7Gerrick Payoff Inde)
SR0T'K hpi( 4%0TS, MS1TI*1RI0= ('4T.6 )
(S04TI.0 4alculates the predefined 3errick *ayoff Index.
%K'M*1% hpi(788, 78)
?47Gighest
SR0T'K highest( +'T' '66'R )
(S04TI.0 4alculates the highest value in the +'T' '66'R since the first day loaded in the chart.
%K'M*1% The formula /highest( rsi(7F) )/ returns the highest 6elative Strength Index value since the first
day loaded in the chart ^ /highest ( close )/ returns the highest closing price since the first day loaded in the chart.
S%% '1S. The hhv() function 3ighest 3igh 5alue ^ the llv() function (see 1o$est 1o$ 5alue)^ the
lo$est() function (see 1o$est).
?37Gighest Dars Ago
Trang 3! Ngun: XLanh11
Metastock Formula Language
SR0T'K highestars( +'T' '66'R )
(S04TI.0 4alculates the numer of periods that have passed since the +'T' '66'RHs highest value.
This includes all data loaded in the chart.
%K'M*1% The formula /highestars( close )/ returns the numer of periods that have passed since the
closing price reached its highest peak.
?=7Gighest Gigh *alue
SR0T'K hhv( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the highest value in the +'T' '66'R over the preceding *%6I.+S (*%6I.+S
includes the current day).
%K'M*1% The formula /hhv( 41.S%, O )/ returns the highest closing price over the preceding five
periods^ /hhv(3,P)/ returns the highest high price over the preceding seven periods.
S%% '1S. The Stochastic .scillator example (see Stochastic .scillator)^ the llv() function (see 1o$est
1o$ 5alue).
?17Gighest Gigh *alue Dars Ago
SR0T'K hhvars( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the numer of periods that have passed since the +'T' '66'R reached its
*%6I.+S period peak.
%K'M*1% The formula /hhvars( close,O8 )/ returns the numer of periods that have passed since the
closing price reached its O8-period peak.
?>7Gighest Since
SR0T'K highestsince ( 0th, %K*6%SSI.0, +'T' '66'R )
(S04TI.0 6eturns the highest value of +'T' '66'R since the 0th most recent occurrence of
%K*6%SSI.0 $as true. This includes all data loaded in the chart.
%K'M*1% The formula /highestsince( :, cross(c,mov(c,78,s), close )/ returns highest value of the close
since the second most recent occurrence of the close crossing aove its 78-day moving average.
??7Gighest Since Dars Ago
SR0T'K highestsincears( 0th, %K*6%SSI.0, +'T' '66'R )
Trang 31 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the numer of periods that have passed from the highest value of +'T' '66'R
(after the 0th most recent occurrence of %K*6%SSI.0 $as true). This includes all data loaded in the chart.
*ut another $ay, this function returns the numer of periods that have passed since the highestsince() function
returned its value.
%K'M*1% The formula /highestsincears( :, cross(c,mov(c,78,s), close )/ returns the numer of periods
that have passed since the highest value of the close (after the second most recent occurrence of the close crossing
aove its 78-day moving average).
?@7If
SR0T'K if( +'T' '66'R 9 9> < <> <9 > +'T' '66'R, T3%0 +'T' '66'R, %1S% +'T' '66'R )
(S04TI.0 ' conditional function that returns the second parameter (T3%0) if the conditional expression
defined y the first parameter is true^ other$ise, the third parameter is returned (%1S%).
%K'M*1% The formula /if(7<:,I,F)/ $ill al$ays return the value three.
S%% '1S. The .n &alance 5olume example (see .n &alance 5olume)^ The Indicator &uilder Tutorial
(see Indicator &uilder Tutorial). (or more details on using the if() function, see The if() function.
?A7Inertia
SR0T'K inertia( 6%=6%SSI.0 *%6I.+S, 65I *%6I.+S)
(S04TI.0 4alculates the predefined Inertia indicator. The 65I *%6I.+S is the numer of periods used
for the 6elative 5olatility Index component of the indicator.
%K'M*1% inertia(:8,7F)
?B7Input
SR0T'K input( /*6.M*T T%KT/, MI0IMSM 5'1S%, M'KIMSM 5'1S%, +%('S1T 5'1S%)
(S04TI.0 This function instructs MetaStock to prompt for input $hen a custom indicator is plotted. This
function is only supported y the 4ustom Indicator &uilder.
prompt text. This defines the text displayed next to the input ox. This is used to descrie $hat should e
entered.
Trang 32 Ngun: XLanh11
Metastock Formula Language
minimum value. This argument is the smallest value that can e entered. If you attempt to enter a value smaller
than this value, MetaStock displays a message.
maximum value. This argument is the largest value that can e entered. If you attempt to enter a value larger
than this value, MetaStock displays a message.
default value. This argument defines the default value (i.e., the value that $ill appear in the ox $hen the dialog
is initially displayed.) . 0ote that the default value is used if another formula using the fml() function calls the
custom indicator.
%K'M*1% input(/%nter the numer of periods/,7,O8,G)
?C7Inside
SR0T'K inside()
(S04TI.0 *lots a /!7/ $hen an inside day occurs. 'n inside day occurs $hen todayHs high is less than or
e)ual to the high for the previous rally or reaction day and todayHs lo$ is greater than or e)ual to the previous
rally or reaction dayHs lo$. ' range is determined y the first Inside +ay and is only roken y a 6ally, 6eaction,
or .utside day.
@47Integer
SR0T'K int( +'T' '66'R )
(S04TI.0 6emoves the fractional portion of +'T' '66'R and returns the integer part.
%K'M*1% The formula /int( 78.P )/ returns 78^ the formula /int(-7G._ )/ returns -7G.
S%% '1S. The ceiling() function (see 4eiling)^ the floor() function (see (loor)^ the frac() function (see
(raction).
@37Intraday Momentum Inde)
SR0T'K imi( *%6I.+S )
(S04TI.0 4alculates the predefined Intraday Momentum Index.
%K'M*1% imi( 7F )
@=7Is-efined$%
SR0T'K isdefined(+'T' '66'R)
(S04TI.0 6eturns 7 if all data necessary to calculate the formula is availale, 8 if not.
Trang 33 Ngun: XLanh11
Metastock Formula Language
%K'M*1% The formula /isdefined(mov(c,:8,s))/
$ill return a 8 if there are less than :8 periods of data loaded in the chart.
@17Is&ndefined$%
SR0T'K isundefined(+'T' '66'R)
(S04TI.0 6eturns 8 if all data necessary to calculate the formula is availale, 7 if not.
%K'M*1% The formula /isundefined(mov(c,:8,s))/
$ill return a 7 if there are less than :8 periods of data loaded in the chart.
@>7Hlinger Oscillator
SR0T'K kvo()
(S04TI.0 4alculates the predefined ,linger .scillator.
%K'M*1% The formula /kvo()/ returns the value of the ,linger .scillator (i.e., the solid line). The
formula /mov(kvo(),7I,%)/ returns the value of the ,5.Hs trigger line (i.e., the dotted line).
@?7Last *alue in -ata Array
SR0T'K lastvalue(+'T' '66'R)
(S04TI.0 This function loads an entire data array $ith the last calculated value of the specified +'T'
'66'R. The result of this function can e used in place of a constant in any function argument.
If +'T' '66'R is undefined (e.g., only 788-days loaded and you re)uest the last value of a :88-day moving
average) then the lastvalue function returns Qero.
Since this function loads an entire data array $ith the last value of another array, it allo$s a formula to look into
the future. This is unacceptale for most indicators, ut is very eneficial for things like pattern recognition.
%K'M*1% The formula /mov(close,lastvalue(fml(/+etermine *eriods/)),s)/ calculates a moving average
using the numer of periods returned y the indicator named /+etermine *eriods/.
@@7Linear (egression Indicator
Trang 34 Ngun: XLanh11
Metastock Formula Language
SR0T'K linearreg( +'T' '66'R, *%6I.+S, SM..T3 M%T3.+, SM..T3 *%6I.+S )
(S04TI.0 4alculates the predefined 1inear 6egression indicator.
%K'M*1% linearreg( 4 , O8, simple, 78 )
The Smooth Method and Smooth *eriods are optional, therefore the follo$ing example is also valid
linearreg(4, O8)
The Smooth Method may e any of the Moving 'verage types used in the Moving 'verage function.
@A7Linear (egression Slope
SR0T'K linregslope( +'T' '66'R, *%6I.+S
(S04TI.0 4alculates the predefined 1inear 6egression Slope indicator.
%K'M*1% linregslope(c, O8 )
@B7Logarithm $natural%
SR0T'K log( +'T' '66'R )
(S04TI.0 4alculates the natural logarithm of +'T' '66'R.
S%% '1S. The exp() function (see %xponent).
@C7Lo,est
SR0T'K lo$est( +'T' '66'R )
(S04TI.0 4alculates the lo$est value in the +'T' '66'R since the first day loaded in the chart.
%K'M*1% The formula /lo$est( rsi(7F) )/ returns the lo$est 6elative Strength Index value since the first
day loaded in the chart^ /lo$est ( close )/ returns the lo$est closing price since the first day loaded in the chart.
S%% '1S. The hhv() function (see 3ighest 3igh 5alue )^ the llv() function (see 1o$est 1o$ 5alue)^ the
highest() function (see 3ighest).
A47Lo,est Dars Ago
SR0T'K lo$estars( +'T' '66'R )
Trang 35 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the numer of periods that have passed since the +'T' '66'RHs lo$est value.
This includes all data loaded in the chart.
%K'M*1% The formula /lo$estars( close )/ returns the numer of periods that have passed since the
closing price reached its lo$est point.
A37Lo,est Lo, *alue
SR0T'K llv( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the lo$est value in the +'T' '66'R over the preceding *%6I.+S (*%6I.+S
includes the current day).
%K'M*1% The formula /llv( 41.S%, 7F )/ returns the lo$est closing price over the preceding 7F periods.
S%% '1S. The Stochastic .scillator example (see Stochastic .scillator)^ the hhv() function (see 3ighest
3igh 5alue ).
A=7Lo,est Lo, *alue Dars Ago
SR0T'K llvars( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the numer of periods that have passed since the +'T' '66'R reached its
*%6I.+S period trough.
%K'M*1% The formula /llvars( close,O8 )/ returns the numer of periods that have passed since the
closing price reached its O8 period trough.
A17Lo,est Since
SR0T'K lo$estsince ( 0th, %K*6%SSI.0, +'T' '66'R )
(S04TI.0 6eturns the lo$est value of +'T' '66'R since the 0th most recent occurrence of
%K*6%SSI.0 $as true. This includes all data loaded in the chart.
%K'M*1% The formula /lo$estsince( :, cross(c,mov(c,78,s), close )/ returns lo$est value of the close
since the second most recent occurrence of the close crossing aove its 78-day moving average.
A>7Lo,est Since Dars Ago
SR0T'K lo$estsincears( 0th, %K*6%SSI.0, +'T' '66'R )
(S04TI.0 4alculates the numer of periods that have passed from the lo$est value of +'T' '66'R
(after the 0th most recent occurrence of %K*6%SSI.0 $as true). This includes all data loaded in the chart.
Trang 36 Ngun: XLanh11
Metastock Formula Language
*ut another $ay, this function returns the numer of periods that have passed since the lo$estsince() function
returned its value.
%K'M*1% The formula /lo$estsincears( :, cross(c,mov(c,78,s), close )/ returns the numer of periods
that have passed since the lo$est value of the close (after the second most recent occurrence of the close crossing
aove its 78-day moving average).
A?7MA!-
SR0T'K macd()
(S04TI.0 4alculates the predefined M'4+ indicator.
%K'M*1% The formula /macd()/ returns the value of the M'4+ indicator (i.e., the solid line). The
formula /mov(macd(),G,%)/ returns the value of the M'4+Hs signal line (i.e., the dotted line).
A@7Market Facilitation Inde)
SR0T'K marketfacindex()
(S04TI.0 4alculates the predefined Market (acilitation Index.
%K'M*1% marketfacindex()
AA7Mass Inde)
SR0T'K mass( *%6I.+S )
(S04TI.0 4alculates the predefined Mass Index.
%K'M*1% mass( :O )
AB7Ma)imum
SR0T'K max( +'T' '66'R, +'T' '66'R )
(S04TI.0 6eturns the largest of the t$o parameters.
%K'M*1% The formula /max( 41.S%, 78 )/ returns either the closing price or 78, $hichever is greater.
The formula /max(-7F, 7I)/ al$ays returns 7I.
AC7Median Price
Trang 37 Ngun: XLanh11
Metastock Formula Language
SR0T'K mp()
(S04TI.0 4alculates the predefined Median *rice indicator.
S%% '1S. The typ() function (see Typical *rice).
B47MSA Lead Sine
SR0T'K mesaleadsine( 4R41% 1%0=T3 )
(S04TI.0 4alculates the predefined M%S' 1ead Sine indicator that plots along $ith M%S' Sine ;ave
indicator (see M%S' Sine ;ave).
%K'M*1% mesaleadsine( :8 )
S%% '1S. The mesasine$ave() function (see M%S' Sine ;ave).
B37MSA Sine Wa9e
SR0T'K mesasine$ave( 4R41% 1%0=T3 )
(S04TI.0 4alculates the predefined M%S' Sine ;ave indicator (see M%S' Sine ;ave).
%K'M*1% mesasine$ave( :8 )
S%% '1S. The mesaleadsine() function (see M%S' 1ead Sine).
B=7Midpoint
SR0T'K mid( +'T' '66'R, *%6I.+S )
(S04TI.0 6eturns the midpoint of the +'T' '66'R over the specified time *%6I.+. The midpoint is
the value half$ay et$een the highest and lo$est +'T' '66'R values during the specified *%6I.+.
%K'M*1% The formula /mid( 41.S%, P )/ is e)uivalent to /llv(4,P) ! ((hhv(4,P) - llv(4,P)) " :)./
S%% '1S. The hhv() function (see 3ighest 3igh 5alue )^ the llv() function (see 1o$est 1o$ 5alue).
B17Minimum
SR0T'K min( +'T' '66'R, +'T' '66'R )
(S04TI.0 6eturns the smallest of the t$o parameters.
%K'M*1% The formula /min( 41.S%, 78 )/ returns the closing price or 78, $hichever is less. The
formula /min(-7F, 7I)/ al$ays returns -7F.
Trang 38 Ngun: XLanh11
Metastock Formula Language
S%% '1S. The max() function (see Maximum).
B>7Minus -irectional Mo9ement
SR0T'K mdi( *%6I.+S )
(S04TI.0 4alculates the predefined Minus +irectional Movement indicator.
%K'M*1% mdi( 7F )
S%% '1S. The adx() function 'verage +irectional Movement^ the adxr() function +irectional Movement
6ating^ the csi() function 4ommodity Selection Index^ the dx() function +irectional Movement Index^ the pdi()
function *lus +irectional Movement .
B?7Modulus
SR0T'K mod( +'T' '66'R, +'T' '66'R )
(S04TI.0 4alculates the remainder (i.e., the fractional portion) of +'T' '66'R divided y +'T'
'66'R. ' division y Qero produces a Qero result.
%K'M*1% The formula /mod( 78, I )/ returns 7.8^ the formula /mod( -78.P, I )/ returns -7.P. Rou could
$rite an e)uivalent formula as /-78.P - (int(-78.P " I) # I)./
B@7Momentum
SR0T'K mo( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined Momentum indicator.
%K'M*1% mo( 4, 7: )
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
BA7Money Flo, Inde)
SR0T'K mfi( *%6I.+S )
(S04TI.0 4alculates the predefined Money (lo$ Index.
%K'M*1% mfi( 7F )
S%% '1S. The rsi() function (see 6elative Strength Index (6SI)).
Trang 3 Ngun: XLanh11
Metastock Formula Language
BB7Month
SR0T'K month()
(S04TI.0 *lots the month of the year for the price. If a ar $as plotted on 78"7O"Gh, /78/ $ould e
plotted.
BC7Mo9ing A9erage
SR0T'K mov( +'T' '66'R, *%6I.+S, M%T3.+)
(S04TI.0 4alculates a *%6I.+S moving average of +'T' '66'R using M%T3.+ calculation
method.
5alid methods are %K*.0%0TI'1, SIM*1%, TIM%S%6I%S, T6I'0=S1'6, ;%I=3T%+, 5'6I'&1%, '0+
5.1SM%'+rSST%+ (these can e areviated as %, S, T, T6I, ;, 5'6, and 5.1).
%K'M*1% The formula /mov( 41.S%, :O, %K*.0%0TI'1 )/ returns the value of a :O-period
exponential moving average of the closing prices.
C47Multiplication
SR0T'K mul( +'T' '66'R, +'T' '66'R )
(S04TI.0 4alculates +'T' '66'R multiplied y +'T' '66'R.
%K'M*1% The function /mul( 41.S%, :)/ returns the closing price multiplied y t$o. (This function
also could e $ritten as /4 # :./)
S%% '1S. The div() function (see +ivision).
C37"egati9e
SR0T'K neg( +'T' '66'R )
(S04TI.0 4alculates the negative of +'T' '66'R.
%K'M*1% The formula /neg( 78 )/ returns -78^ the formula /neg( -7: )/ returns !7:. This formula also
could e $ritten /-(-7:)./
C=7"egati9e *olume Inde)
SR0T'K nvi(+'T' '66'R)
Trang 4! Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the predefined 0egative 5olume Index.
S%% '1S. The pvi() function (see *ositive 5olume Index).
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
C17On Dalance *olume
SR0T'K ov(+'T' '66'R)
(S04TI.0 4alculates the predefined .n &alance 5olume indicator.
S%% '1S. The example formula (see .n &alance 5olume).
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
C>7Option )piration
SR0T'K optionexp()
(S04TI.0 4alculates the predefined 0ext .ption %xpiration indicator.
S%% '1S. The .ption 1ife function (see .ption 1ife).
C?7Option Life
SR0T'K life( %K*I6'TI.0 +'T% )
(S04TI.0 4alculates the predefined .ption 1ife indicator.
%K'M*1% life( GP87:7 ) displays the numer of days until ranuary :7, 7GGP.
S%% '1S. The delta() function (see +elta)^ the gamma() function (see =amma)^ the option() function (see
*ut"4all *rice)^ the theta() function (see Theta)^ the vega() function (see 5ega)^ and the volo() function (see
5olatility, .ption).
C@7Outside
SR0T'K outside()
(S04TI.0 *lots a /!7/ $hen an outside day occurs. 'n outside day occurs $hen todayHs high is greater
than the high for the previous rally or reaction day and todayHs lo$ is less than the previous rally or reaction dayHs
lo$. ' range is determined y the first .utside +ay and is only roken y a 6ally, 6eaction, or Inside day.
CA7Para+olic SA(
Trang 41 Ngun: XLanh11
Metastock Formula Language
SR0T'K sar( ST%*, M'KIMSM )
(S04TI.0 4alculates the predefined *araolic S'6 indicator.
%K'M*1% sar( 8.8:, 8.:8 )
CB7Peak Dars Ago
SR0T'K peakars( 0th, +'T' '66'R, ` MI0IMSM 43'0=%)
(S04TI.0 *lots the numer of ars that have passed from the 0th peak. This uses the sig sag function
(see sig sag) to determine the peaks. 0>7 $ould return the numer of ars that have passed since the most
recent peak. 0>: $ould return the numer of ars that have passed since the :nd most recent peak. %tc.
%K'M*1% peakars(7,close,O)
CC7Peak *alue
SR0T'K peak( 0th, +'T' '66'R, ` MI0IMSM 43'0=% )
(S04TI.0 *lots the value of +'T' '66'R 0th peak(s) ago. This uses the sig sag function (see sig
sag) to determine the peaks. 0>7 $ould return the value of the most recent peak. 0>: $ould return the value of
the :nd most recent peak. %tc.
%K'M*1% peak(7,close,O)
3447 Performance
SR0T'K per(+'T' '66'R)
(S04TI.0 4alculates the predefined *erformance indicator.
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
3437 Plus -irectional Mo9ement
SR0T'K pdi( *%6I.+S )
(S04TI.0 4alculates the predefined *lus +irectional Movement indicator.
%K'M*1% pdi( 7F )
Trang 42 Ngun: XLanh11
Metastock Formula Language
S%% '1S. The adx() function 'verage +irectional Movement^ the adxr() function +irectional Movement
6ating^ the csi() function 4ommodity Selection Index^ the dx() function +irectional Movement Index^ the mdi()
function Minus +irectional Movement.
34=7 Polari;ed Fractal fficiency
SR0T'K pfe( +'T' '66'R, *%6I.+S, SM..T3I0= *%6I.+S)
(S04TI.0 4alculates the predefined *olariQed (ractal %fficiency indicator.
%K'M*1% pfe( c,78,O )
3417 Positi9e *olume Inde)
SR0T'K pvi(+'T' '66'R)
(S04TI.0 4alculates the predefined *ositive 5olume Index.
S%% '1S. The nvi() function (see 0egative 5olume Index).
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included
34>7 Po,er
SR0T'K po$er( +'T' '66'R, *.;%6 )
(S04TI.0 4alculates +'T' '66'R raised to the *.;%6 po$er. ' negative +'T' '66'R value
raised to a non-integer *.;%6 causes an error message to e displayed.
%K'M*1% The formula /po$er( 78, I )/ returns 7,888.
34?7 Precision
SR0T'K prec( +'T' '66'R, *6%4ISI.0 )
(S04TI.0 Truncates +'T' '66'R to *6%4ISI.0 decimal places.
%K'M*1% The formula /prec( 78.7:G_7, : )/ returns 78.7:8. The formula /prec( 78.7:G_7, F )/ returns
78.7:G_8. Small inary rounding errors may cause some minor distortion in the decimal portion of any numer
stored in a computer.
34@7 Price !hannel Gigh
SR0T'K pricechannelhigh( *%6I.+S )
Trang 43 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the top channel line of the *rice 4hannel indicator.
%K'M*1% pricechannelhigh( 7F )
34A7 Price !hannel Lo,
SR0T'K pricechannello$( *%6I.+S )
(S04TI.0 4alculates the ottom channel line of the *rice 4hannel indicator.
%K'M*1% pricechannello$( 7F )
34B7 Price Oscillator
SR0T'K oscp( *%6I.+S, *%6I.+S, M'pM%T3.+, +I((pM%T3.+ )
(S04TI.0 4alculates the *%6I.+S"*%6I.+S predefined *rice .scillator indicator calculated using the
M'pM%T3.+ moving average method expressed in +I((pM%T3.+.
5alid M'pM%T3.+s are SIM*1%, %K*.0%0TI'1, ;%I=3T%+, TIM%S%6I%S, T6I'0=S1'6, and
5'6I'&1% (these can e areviated as S, %, ;, T, T6I, 5'6).
5alid +I((pM%T3.+s are *%64%0T and *.I0TS (these can e areviated as ` and o).
%K'M*1% The formula /oscp(7, :O, %, o)/ returns a 7-period":O-period exponential price oscillator
expressed in points.
S%% '1S. The oscv() function (see 5olume .scillator).
34C7 Price *olume #rend
SR0T'K pvt(+'T' '66'R)
(S04TI.0 4alculates the predefined *rice 5olume Trend indicator.
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
3347 ProIection Dand Dottom
SR0T'K *roJandot( *%6I.+S )
(S04TI.0 4alculates the ottom *roJection &and.
%K'M*1% proJandot( :7 )
Trang 44 Ngun: XLanh11
Metastock Formula Language
3337 ProIection Dand #op
SR0T'K *roJandtop( *%6I.+S )
(S04TI.0 4alculates the top *roJection &and.
%K'M*1% proJandtop( :7 )
33=7 ProIection Oscillator
SR0T'K *roJosc( 6%=6%SSI.0 *%6I.+S, S1.;I0= *%6I.+S )
(S04TI.0 4alculates the predefined *roJection .scillator.
%K'M*1% proJosc( :7,I )
3317 Put0!all Price
SR0T'K option( TR*%, +'T%, *6I4%, I0T%6%ST, +I5I+%0+ )
(S04TI.0 4alculates the predefined *ut"4all *rice indicator.
%K'M*1% The formula /option( %4, Gh7:I7, 7:O, _.O, h.I7 )/ calculates the fair market value of an
e)uity call that matures on +ecemer I7, 7GGh, at a strike price of o7:O. The current market interest rates are
_.O` and the security paid an annual dividend of oh.I7.
TR*% specifies $hether the security is an %)uity or a (uture (i.e., % or () and if a *ut or 4all price (i.e., * or 4)
should e calculated. 5alid TR*%s are %4, %*, (4, and (*. (These types also can e spelled out as 4'11, *ST,
(STS6%4'11, and (STS6%*ST.)
The +'T% is the date that the option expires. The +'T% must e entered as a numer in the RRMM++ format.
(or example, +ecemer I7, 7GGh, should e entered as Gh7:I7. This date format is used regardless of the date
format specified in the 4onfiguration section.
The *6I4% parameter specifies the optionHs strike price.
Trang 45 Ngun: XLanh11
Metastock Formula Language
The I0T%6%ST parameter specifies a /risk free/ market interest rate (e.g., _.PO).
The +I5I+%0+ parameter specifies the total dividends received over the last 7: months.
S%% '1S. The delta() function (see +elta)^ the gamma() function (see =amma)^ the life() function (see
.ption 1ife)^ the theta() function (see Theta)^ the vega() function (see 5ega)^ and the volo() function (see
5olatility, .ption).
33>7 Fstick
SR0T'K )stick( *%6I.+S )
(S04TI.0 4alculates the predefined istick indicator.
%K'M*1% )stick( :7 )
33?7 r8sJuared
SR0T'K rs)uared( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined 6s)uared indicator.
%K'M*1% rs)uared( c, :7 )
33@7 (ally
SR0T'K rally()
(S04TI.0 *lots a /!7/ $hen a rally day occurs. .ther$ise, a /8/ is plotted. ' rally day occurs $hen
todayHs high is greater than the previous rally or reaction dayHs high and todayHs lo$ is greater than or e)ual to the
previous rally or reaction dayHs lo$.
33A7 (ally With *olume
SR0T'K rally$ithvol()
(S04TI.0 *lots a /!7/ $hen a rally $ith volume day occurs. .ther$ise, a /8/ is plotted. ' rally $ith
volume occurs $hen todayHs high is greater than the previous rally or reaction dayHs high and todayHs lo$ is
greater than or e)ual to the previous rally or reaction dayHs lo$. TodayHs volume must e greater than the previous
rally or reaction dayHs volume.
33B7 (andom Walk Inde) of Gighs
SR0T'K r$ih( MI0ISMSM *%6I.+S, M'KIMSM *%6I.+S )
Trang 46 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the predefined 6andom ;alk Index of the highs indicator.
%K'M*1% r$ih( h,IG )
33C7 (andom Walk Inde) of Lo,s
SR0T'K r$il(MI0ISMSM *%6I.+S, M'KIMSM *%6I.+S )
(S04TI.0 4alculates the predefined 6andom ;alk Index of the lo$s indicator.
%K'M*1% r$il( h,IG )
3=47 (ange Indicator
SR0T'K rangeindicator( *%6I.+S, SM..T3I0= *%6I.+S )
(S04TI.0 4alculates the predefined 6ange Indicator.
%K'M*1% rangeindicator( 78,I )
3=37 (ate of !hange
SR0T'K roc( +'T' '66'R, *%6I.+S, +I((pM%T3.+ )
(S04TI.0 4alculates the *%6I.+S rate-of-change of +'T' '66'R expressed as +I((pM%T3.+.
5alid +I((pM%T3.+s are *%64%0T and *.I0TS (these can e areviated as ` and o).
%K'M*1% The formula /roc( 41.S%, 7:, *%64%0T )/ returns the 7:-period percent rate-of-change of the
closing prices.
3==7 (eaction
SR0T'K reaction()
(S04TI.0 *lots a /!7/ $hen a reaction day occurs. .ther$ise, a /8/ is plotted. ' reaction day occurs
$hen todayHs high is less than or e)ual to the previous rally or reaction dayHs high and todayHs lo$ is less than the
previous rally or reaction dayHs lo$.
3=17 (eaction With *olume
SR0T'K reaction$ithvol()
Trang 47 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 *lots a /!7/ $hen a reaction day occurs. .ther$ise, a /8/ is plotted. ' reaction day occurs
$hen todayHs high is less than or e)ual to the previous rally or reaction dayHs high and todayHs lo$ is less than the
previous rally or reaction dayHs lo$. TodayHs volume must e greater than the previous rally or reaction dayHs
volume.
3=>7 (eference
SR0T'K ref( +'T' '66'R, *%6I.+S )
(S04TI.0 6eferences a previous or suse)uent element in a +'T' '66'R. ' positive *%6I.+ references /n/
periods in the future^ a negative *%6I.+ references /n/ periods ago.
%K'M*1% The formula /ref( 41.S%, -7: )/ returns the closing price 7: periods ago. Thus, you could $rite the
7:-day price rate-of-change (expressed in points) as /4 - ref( 4, -7: )./ The formula /ref( 4, !7: )/ returns the
closing price 7: periods ahead.
3=?7 (elati9e Momentum Inde)
SR0T'K rmi( +'T' '66'R, *%6I.+S, M.M%0TSM *'6'M%T%6 )
(S04TI.0 4alculates the predefined 6elative Momentum Index.
%K'M*1% rmi( c,:8,:8 )
3=@7 (elati9e Strength Inde) $(SI%
SR0T'K rsi( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined 6SI indicator.
%K'M*1% rsi( 7F )
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
3=A7 (elati9e *olatility Inde)
SR0T'K rvi( *%6I.+S )
(S04TI.0 4alculates the predefined 6elative 5olatility Index.
%K'M*1% rvi( :7 )
3=B7 (ound
Trang 48 Ngun: XLanh11
Metastock Formula Language
SR0T'K round( +'T' '66'R )
(S04TI.0 6ounds +'T' '66'R to the nearest integer.
%K'M*1% The formula /round( !78.O )/ returns !77. The formula /round( -78.F )/ returns -78.
S%% '1S. The ceiling() function 4eiling^ the floor() function (loor^ the int() function Integer.
3=C7 Selling Pressure
SR0T'K sellp()
(S04TI.0 4alculates the selling pressure component of the +emand Index (see +emand Index). Selling
pressure is a measurement of the amount of volume related to selling.
3147 Sine
SR0T'K sin( +'T' '66'R )
(S04TI.0 6eturns the sine of +'T' '66'R. This function assumes that the +'T' '66'R values are
in degrees.
%K'M*1% Rou can plot a sine $ave using the formula /sin(cum(O))./ Increasing the value in this formula
(i.e., /O/) $ill increase the fre)uency of the sine $ave.
S%% '1S. The atan() function (see 'rc Tangent)^ the cos() function (see 4osine).
3137 SJuare (oot
SR0T'K s)rt( +'T' '66'R )
(S04TI.0 4alculates the s)uare root of +'T' '66'R. The s)uare root of a negative numer al$ays
returns a Qero result.
%K'M*1% The formula /s)rt( 7h )/ returns F.
S%% '1S. The Standard +eviation example formula (see Standard +eviation).
31=7 Standard -e9iation
SR0T'K stdev( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined Standard +eviation indicator.
%K'M*1% stdev( 41.S%, :7 )
Trang 4 Ngun: XLanh11
Metastock Formula Language
3117 Standard rror
SR0T'K ste( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined Standard %rror indicator.
%K'M*1% ste( 41.S%, :7 )
31>7 Standard rror Dand Dottom
SR0T'K steandot( +'T' '66'R, *%6I.+S, %66.6S, SM..T3 M%T3.+, SM..T3 *%6I.+S )
(S04TI.0 4alculates the ottom Standard %rror &and of +'T' '66'R shifted do$n$ard %66.6S
standard errors.
%K'M*1% steandot( close, :7, :, simple, 78 )
The Smooth Method and Smooth *eriods are optional, therefore the follo$ing example is also valid
steandot(close, :7, :)
The Smooth Method may e any of the Moving 'verage types used in the Moving 'verage function.
31?7 Standard rror Dand #op
SR0T'K steandtop( +'T' '66'R, *%6I.+S, %66.6S, SM..T3 M%T3.+, SM..T3 *%6I.+S )
(S04TI.0 4alculates the ottom Standard %rror &and of +'T' '66'R shifted up$ard %66.6S
standard errors.
%K'M*1% steandtop( close, :7, :, simple, 78 )
The Smooth Method and Smooth *eriods are optional, therefore the follo$ing example is also valid
steandtop(close, :7, :)
The Smooth Method may e any of the Moving 'verage types used in the Moving 'verage function.
31@7 Stochastic Momentum Inde)
SR0T'K stochmomentum( *%6I.+S, SM..T3I0=, +.S&1% SM..T3I0= )
(S04TI.0 4alculates the predefined Stochastic Momentum Index.
%K'M*1% stochmomentum( 78,F8,I )
Trang 5! Ngun: XLanh11
Metastock Formula Language
31A7 Stochastic Oscillator
SR0T'K stoch( `, *%6I.+S, `, S1.;I0= )
(S04TI.0 4alculates the predefined Stochastic .scillator.
%K'M*1% The formula /stoch( O, I )/ returns the value of a O-period `, slo$ed I-periods.
S%% '1S. The Stochastic example formula (see Stochastic .scillator).
31B7 Su+traction
SR0T'K su( +'T' '66'R, +'T' '66'R )
(S04TI.0 4alculates +'T' '66'R minus +'T' '66'R.
%K'M*1% The formula /su( 78, : )/ returns eight. (This formula also could e $ritten as /78 - :./)
S%% '1S. The add() function (see 'ddition).
31C7 Summation
SR0T'K sum( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates a cumulative sum of the +'T' '66'R for the specified numer of lookack
*%6I.+s (including today).
%K'M*1% The formula /sum( 41.S%, 7: )/ returns the sum of the preceding 7: closing prices. ' 7:-
period simple moving average could e $ritten /sum(4,7:) " 7:./
S%% '1S. The cum() function (see 4umulate).
3>47 S,ing Inde)
SR0T'K s$ing( 1IMIT M.5% )
(S04TI.0 4alculates the predefined S$ing Index indicator. The S$ing Index re)uires opening prices.
%K'M*1% s$ing( I.8 )
S%% '1S. The as$ing() function (see 'ccumulation S$ing Index).
3>37 #ema
Trang 51 Ngun: XLanh11
Metastock Formula Language
SR0T'K tema( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined T%M' indicator
%K'M*1% tema( c,7F )
S%% '1S. The dema() function (see +ema).
3>=7 #heta
SR0T'K theta( TR*%, +'T%, *6I4%, I0T%6%ST, +I5I+%0+ )
(S04TI.0 4alculates the predefined Theta indicator. See the option() function (*ut"4all *rice) for a
description of the parameters used in the theta() function.
%K'M*1% theta( %4, Gh7::8, 7:O, P.O8, F.PO )
S%% '1S. The delta() function (see +elta)^ the gamma() function (see =amma)^ the life() function (see
.ption 1ife)^ the option() function (see *ut"4all *rice)^ the vega() function (see 5ega)^ and the volo() function
(see 5olatility, .ption).
3>17 #ime Series Forecast
SR0T'K tsf( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined *%6I.+S Time Series (orecast indicator of +'T' '66'R.
%K'M*1% The formula /tsf( 41.S%, 78 )/ returns a 78-period Time Series (orecast of the closing prices.
S%% '1S. The correl() function (see 4orrelation 'nalysis).
3>>7 #rade *olume Inde)
SR0T'K tvi( +'T' '66'R, MI0IMSM TI4, )
(S04TI.0 4alculates the predefined Trade 5olume Index.
%K'M*1% tvi( 8.7:O )
S%% '1S. The ov() function (see .n &alance 5olume) .
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
3>?7 #(IK
Trang 52 Ngun: XLanh11
Metastock Formula Language
SR0T'K trix( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined T6IK indicator.
%K'M*1% trix( 7: )
The +'T' '66'R argument is optional and $ill use 41.S% as the default if it is not included.
3>@7 #rough Dars Ago
SR0T'K troughars( 0th, +'T' '66'R, ` MI0IMSM 43'0=%)
(S04TI.0 *lots the numer of ars that have passed from the 0th trough. This uses the sig sag function
(see sig sag) to determine the troughs. If 0th is 7, then this $ill return the numer of ars that have passed since
the most recent trough. If 0th is :, this $ill return the numer of ars that have passed since the :nd most recent
trough. %tc.
%K'M*1% troughars(7,close,O)
3>A7 #rough *alue
SR0T'K trough( 0th, +'T' '66'R, ` MI0IMSM 43'0=% )
(S04TI.0 *lots the value of +'T' '66'R 0th trough(s) ago. This uses the sig sag function (see sig
sag
) to determine the troughs. 0>7 $ould return the value of the most recent trough. 0>: $ould return the value of
the :nd most recent trough. %tc.
%K'M*1% trough( 7,close,O )
3>B7 #ypical Price
SR0T'K typical()
(S04TI.0 4alculates the predefined Typical *rice indicator.
3>C7 &ltimate Oscillator
SR0T'K ult( 4R41%7, 4R41%:, 4R41%I )
(S04TI.0 4alculates the predefined Sltimate .scillator indicator using the three cycle lengths supplied
as parameters. 0ote that each of the three parameters must e greater than the preceding parameter or an error
message $ill e displayed (e.g., /ult( O, O, O)/ is not valid).
%K'M*1% The formula /ult( P, 7F, :7 )/ returns the default Sltimate .scillator.
Trang 53 Ngun: XLanh11
Metastock Formula Language
3?47 *alue When
SR0T'K value$hen ( 0th, %K*6%SSI.0, +'T' '66'R )
(S04TI.0 6eturns the value of the +'T' '66'R $hen the %K*6%SSI.0 $as true on the 0th most
recent occurrence. This includes all data loaded in the chart.
%K'M*1% The formula /value$hen ( :, cross(c,mov(c,78,s), rsi(:8) )/ returns the value of the 6SI on the
:nd most recent occurrence of the closing price crossing aove its 78-day moving average.
3?37 *ariance
SR0T'K var( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the statistical variance of +'T' '66'R over the specified time *%6I.+.
%K'M*1% var( 41.S%, :8 )
S%% '1S. The stdev() function (see Standard +eviation) ^ the Standard +eviation example (see Standard
+eviation).
3?=7 *ega
SR0T'K vega( TR*%, +'T%, *6I4%, I0T%6%ST, +I5I+%0+ )
(S04TI.0 4alculates the predefined 5ega indicator. See the option() function (*ut"4all *rice) for a
description of the parameters used in the vega() function.
%K'M*1% vega( %4, Gh7::8, 7:O, P.O8, F.PO )
S%% '1S. The delta() function (see +elta)^ the gamma() function (see =amma)^ the life() function (see
.ption 1ife)^ the option() function (see *ut"4all *rice)^ the theta() function (see Theta)^ and the volo() function
(see 5olatility, .ption).
3?17 *ertical Gori;ontal Filter
SR0T'K vhf( +'T' '66'R, *%6I.+S )
(S04TI.0 4alculates the predefined 5ertical 3oriQontal (ilter of +'T' '66'R over the specified time
*%6I.+.
%K'M*1% vhf( 4, :_ )
3?>7 *olatility: !haikinEs
SR0T'K vol( M' *%6I.+S, 6.4 *%6I.+S )
Trang 54 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the predefined 4haikinHs 5olatility indicator.
%K'M*1% vol( 78, 78 )
3??7 *olatility: Option
SR0T'K volo()
(S04TI.0 4alculates the predefined .ption 5olatility indicator.
%K'M*1% volo()
S%% '1S. The delta() function (see +elta)^ the gamma() function (see =amma)^ the life() function (see
.ption 1ife)^ the option() function (see *ut"4all *rice)^ the theta() function (see Theta)^ and the vega() function
(see 5ega).
3?@7 *olume Oscillator
SR0T'K oscv( *%6I.+S, *%6I.+S, M'pM%T3.+, +I((pM%T3.+)
(S04TI.0 4alculates the *%6I.+S"*%6I.+S predefined 5olume .scillator indicator calculated using
the M'pM%T3.+ moving average method expressed in +I((pM%T3.+.
5alid M'pM%T3.+s are SIM*1%, %K*.0%0TI'1, ;%I=3T%+, TIM%S%6I%S, T6I'0=S1'6, and
5'6I'&1% (these can e areviated as S, %, ;, T, T6I, and 5'6).
5alid +I((pM%T3.+s are *%64%0T and *.I0TS (these can e areviated as ` and o).
%K'M*1% oscv( 7, :O, SIM*1%, o )
S%% '1S. The oscp() function (see *rice .scillator).
3?A7 Weighted !lose
SR0T'K $c()
(S04TI.0 4alculates the predefined ;eighted 4lose indicator.
3?B7 WilderEs Smoothing
SR0T'K $ilders( +'T' '66'R, *%6I.+S )
Trang 55 Ngun: XLanh11
Metastock Formula Language
(S04TI.0 4alculates the predefined ;ilderHs Smoothing indicator.
%K'M*1% $ilders( 41.S%, 7F )
S%% '1S. The mov() function (see Moving 'verage).
3?C7 WilliamsE L(
SR0T'K $illr( `6 *%6I.+S )
(S04TI.0 4alculates the predefined ;illiamsH `6 indicator.
%K'M*1% $illr( 7F )
3@47 WilliamsE A0-
SR0T'K $illa()
(S04TI.0 4alculates the predefined ;illiams '"+ indicator.
3@37 Writeif
SR0T'K $riteif( %K*6%SSI.0, /T6S% T%KT/, /('1S% T%KT/ )
(S04TI.0 This function can only e used $ithin an expert commentary. If %K*6%SSI.0 evaluates to
/true/, then the T6S% T%KT string is displayed $ithin the commentary. If %K*6%SSI.0 evaluates to /false/,
then the ('1S% T%KT string is displayed.
%K'M*1% $riteif( c 9 mov(c,:88,s), /The close is aove the :88-period moving average./,/The close is
elo$ the :88-period moving average./ )
S%% '1S. (or more detailed Information on using the $riteif() function $ithin an expert commentary, see
+isplaying 4onditional Text $ith ;riteif().
3@=7 Write9al
SR0T'K $riteval( +'T' '66'R )
or
$riteval( +'T' '66'R , (.6M'T )
(S04TI.0 This function can only e used $ithin an expert commentary. It is used to display the numeric
value and decimal format of +'T' '66'R. The decimal format is K.R $here K is the total numer of digits,
and R is the numer of digits to the right of the decimal point.
Trang 56 Ngun: XLanh11
Metastock Formula Language
%K'M*1% $riteval( stoch(IG,I) - stoch(7:,I) ,O.:)
S%% '1S. (or more detailed Information on using the $riteval() function $ithin an expert commentary,
see +isplaying 0umeric 5alues $ith ;riteval().
3@17 Mear
SR0T'K year()
(S04TI.0 *lots the year. If a ar $as plotted on 78"7O"Gh, the function $ill return /7GGh./
3@>7 Nig Nag
SR0T'K Qig( +'T' '66'R, MI0IMSM 43'0=%, +I((pM%T3.+ )
(S04TI.0 4alculates the MI0IMSM 43'0=% predefined sig sag indicator of +'T' '66'R using the
+I((pM%T3.+ method of calculation.
5alid +I((pM%T3.+s are *%64%0T and *.I0TS (these can e areviated as ` and o).
%K'M*1% Qig( 41.S%, O, *%64%0T )
Trang 57 Ngun: XLanh11

You might also like