Авторы: 159 А Б В Г Д Е З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я

Книги:  184 А Б В Г Д Е З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я

Any Last Words

This concludes your introduction to the MetaStock formula language and the power tools. You

should have a grasp of all the basics and be able to apply that to any of the power tools.

Additional information is contained in the MetaStock manual and segregated by topic. Together,

these advanced features take up most of the last half of the manual.

Specific questions on what a function does, how to use it, or why something may not be working

as expected, should be addressed to Equis customer support. They are very willing to help others

learn how to use the MetaStock formula language.

Unfortunately, the support technicians cannot write formulas over the phone for you. If you do

not know how to write a desired formula, try the following steps. After each step, try to write the

formula. If you are still unable to, proceed to the next step.

1. Write in English what you want the formula to do.

2. Try writing out the logic the formula should follow. Use pseudo-formula commands if

necessary (similar to what this text used in discussing the If() function’s conditions).

3. Examine the text you wrote for the first two steps and make sure you did not gloss over any

details. If you can add detail to any part, re-write it with the extra details.

4. Call Equis technical support. They will not be able to write it for you, but may suggest

something you have not thought of.

5. Send in a custom formula request to Equis technical support. Be sure to include your work

so far. This last option does have fee involved based on the time required to write the

formula. The more detail provided, the less time may be required.

Use your imagination and good luck with your trading.

 

Formula Reference

Absolute Value

SYNTAX abs( DATA ARRAY )

This function returns the absolute value of the specified data array. The absolute value is

equal to the value of the number without any positive or negative sign. Therefore the absolute

value of 10 is equal to the absolute value of -10.

This function is most useful if you are looking for a value that does not exceed a certain

range, either up or down. For example, to look for securities whose price has changed by more

than 15%, you could type in the following function.

Abs( Roc( C, 1, %) ) > 15

Accumulation/Distribution

SYNTAX ad()

This calculates the value of the Accumulation/Distribution indicator. It is not normally used in

formulas except to compare the value of this indicator with some other value.

Accumulation Swing Index

SYNTAX aswing( LIMIT MOVE )

This calculates the value of the Accumulation Swing Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

This indicator requires the base security to have data on the opening prices or it cannot be

calculated.

Addition

SYNTAX add( DATA ARRAY, DATA ARRAY )

This function is nothing more than a long way to add two values together. Writing:

add( 10, 20 )

is exactly the same as writing

10 + 20

The MetaStock formula language will treat them exactly the same. Feel free to use whichever

you are most comfortable with.

Alert

SYNTAX alert( EXPRESSION, PERIODS )

The Alert() function checks to see if a given condition has occurred at any time within a

specified length of time. The condition is specified in the expression and the time frame is

denoted in the PERIODS part of the function. If the condition occurs, the Alert() returns the

value of 1. Otherwise, it returns a 0.

For more information on this, look in chapter 4.

Arc Tangent

SYNTAX atan( Y DATA ARRAY, X DATA ARRAY )

This is a trigonometric function dealing with the ratio between angles and the legs of a right

triangle. The value is returned in degrees from 0 to 359.9. The degrees are returned as shown

below:

EXAMPLE The formula "atan( 10, 0 )" returns 90.

This will probably never be used but is included should a formula require it.

Aroon Down

SYNTAX aroondown( PERIODS )

This calculates the value of the Aroon Down component of the predefined Aroon indicator. It is

not normally used in formulas except to compare the value of this indicator with some other

value.

Aroon Up

SYNTAX aroonup( PERIODS )

This calculates the value of the Aroon Up component of the predefined Aroon indicator. It is not

normally used in formulas except to compare the value of this indicator with some other value.

Average Directional Movement

SYNTAX adx( PERIODS )

This calculates the value of the Average Directional Movement indicator. It is not normally used

in formulas except to compare the value of this indicator with some other value.

Average True Range

SYNTAX atr( PERIODS )

This calculates the value of the Average True Range indicator. This is an average over a

specified number of periods of the True Range as calculated by Wilder.

This is normally not used in formulas except to compare the value of this indicator to some other

value. However, the True Range has been used as a volatility gauge. As such, other uses are

possible. This would most likely involve using he volatility as a smoothing value for some other

calculation, the theories of which are not for this document to discuss.

Bars Since

SYNTAX barssince( DATA ARRAY )

This function counts how much time has passed since an event occurred. For example:

BarsSince( C > 40 )

This returns the number of periods that have passed since the closing price was greater than 40.

If this is currently true, it will return a 0.

Warning. Until this event is true, any formula using it will not be calculable. This will cause

custom indicators to not plot and other formula based tools to do nothing or reject the security.

Important: When using the barssince() function in an exploration, you must choose the

"Load ___ Records" button in the Explorer Options dialog and specify a value equal to the

number of bars loaded in your chart; otherwise, the exploration results may not be

accurate.

Bollinger Band Bottom

SYNTAX bbandbot( DATA ARRAY, PERIODS, METHOD, DEVIATIONS )

This calculates the value of the bottom Bollinger Band of DATA ARRAY. METHOD refers to

the type of moving average to use. Valid methods are SIMPLE, EXPONENTIAL, WEIGHTED,

TIMESERIES, TRIANGULAR, and VARIABLE (these can be abbreviated as S, E, W, T, TRI,

and VAR). DEVIATIONS refers to the number of standard deviations the band is shifted

downward.

Bollinger Band Top

SYNTAX bbandtop( DATA ARRAY, PERIODS, METHOD, DEVIATIONS )

This calculates the value of the top Bollinger Band of DATA ARRAY. METHOD refers to the

type of moving average to use. Valid methods are SIMPLE, EXPONENTIAL, WEIGHTED,

TIMESERIES, TRIANGULAR, and VARIABLE (these can be abbreviated as S, E, W, T, TRI,

and VAR). DEVIATIONS refers to the number of standard deviations the band is shifted

upward.

Buying Pressure

SYNTAX buyp()

This calculates the value of the buying pressure component of the predefined Demand Index.

Buying pressure is a measurement of the amount of volume related to buying.

This function is not normally used in formulas except to compare the value of this indicator with

some other value.

Ceiling

SYNTAX ceiling( DATA ARRAY )

The Ceiling() function returns the lowest integer that is greater that the largest value in the data

array. For example:

Ceiling ( High )

This would return the lowest integer that is larger than the highest high value loaded. For

example if you had three years of data loaded and the highest value ever reached by the High

during that time was 103 5/8ths, the formula will return 104.

This function is probably more useful in system tests and explorations, but can help you

plot and calculate the new highs of securities.

Chaikin A/D Oscillator

SYNTAX co()

This calculates the value of the Chaikin A/D Oscillator. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Chaikin's Money Flow

SYNTAX cmf( PERIODS )

This calculates the value of the Chaikin’s Money Flow indicator. It is not normally used in

formulas except to compare the value of this indicator with some other value.

Chande Momentum Oscillator

SYNTAX cmo( DATA ARRAY, PERIODS )

This calculates the value of the Chande Momentum Oscillator. It is not normally used in

formulas except to compare the value of this indicator with some other value.

Commodity Channel Index (EQUIS)

SYNTAX ccie( PERIODS )

This calculates the value of the Commodity Channel Index. This is done using the Equis variant

calculation. It is not normally used in formulas except to compare the value of this indicator

with some other value.

Commodity Channel Index (Standard)

SYNTAX cci( PERIODS )

This calculates the value of the Commodity Channel Index. This is done using the standard

method of calculation. It is not normally used in formulas except to compare the value of this

indicator with some other value.

Commodity Selection Index

SYNTAX csi( PERIODS, VALUE, MARGIN, COMMISSION )

This calculates the value of the Commodity Selection Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Correlation Analysis

SYNTAX correl( INDEPENDENT, DEPENDENT,PERIODS, SHIFT)

This calculates the value of the Correlation Analysis indicator. It compares the correlation of the

DEPENDENT data array to the INDEPENDENT data array. This is statistically averaged over

PERIOD time periods after shifting the DEPENDENT data array to the right by SHIFT periods.

For example:

correl( macd(), CLOSE, 5, 10 )

This compares the MACD indicator to the closing price 10-periods in the future, after

statistically averaging each data array over the preceding 5-periods.

Cosine

SYNTAX cos( DATA ARRAY )

Calculates the geometric function Cosine. This is a cyclic line alternating between 0 and

1 base on the angle value used for the DATA ARRAY. Any number larger that 360 has 360

subtracted from it until it is between 1 and 360 and then the function is calculated.

Normally this function is not used in formulas but it is useful to plot or watch a cycle on a

chart. For example:

Cos( Cum( 1 ) )

With this function, 1 will be added constantly and each period the Sine() plot will

continue in its cycle. After 360 periods, it will be back to it’s original value, thus marking a 360

period cycle on your chart or in your formula.

To work with smaller time periods, increase the number in the Cum() function so it

reaches 360 sooner. The exact number to use can be found by the equation:

360 / number of periods in cycle

You could even put it in your formula that way. For example, if the security had a 17

period cycle, you could write:

Cos( Cum( 360 / 17 ) )

Cross

SYNTAX cross( DATA ARRAY 1, DATA ARRAY 2 )

This function returns a 1 on the period that DATA ARRAY 1 rises above DATA ARRAY 2. At

all other times, a 0 is returned. For more information, refer to chapter 4.

Cumulate

SYNTAX cum( DATA ARRAY )

This function keeps a running total of the DATA ARRAY. Each period it is calculated, it adds

the current value of DATA ARRAY to the previous total. For example:

cum( 1 )

This will keep adding 1 for each period of time loaded in the chart. In effect, it counts how many

records are currently loaded.

Day Of Month

SYNTAX dayofmonth()

This returns the day of the month. If today was July 15, 1998, this function would return 15.

Normally the date functions are used in Expert Advisors to display the actual date of the

commentary. Below is an unusual use:

Posit:=Input("How many Positions",1,10000,100);

Days:=Input("What Day of the month",1,31,1);

Months:=Input("Which month",1,12,1);

years:=Input("Which year",1955,1999,1997);

commis:=Input("dollar amount of commission",0,1000,0)*-

1;

If(Year()>years,

((ROC(C,1,$)*posit)+PREV),

If(Year()=years,

If(Month()>months,

((ROC(C,1,$)*posit)+PREV),

If(Month()=months,

If(DayOfMonth()>days,

((ROC(C,1,$)*posit)+PREV),

commis),

commis)),

commis))

This formula will plot the profits from a position taken in a given security. First, all the

information required for the calculation are gathered through input() prompts. A series of If()’s

then check to see if the specified date has occurred or not. If it has not, the commission’s

expense is displayed.

One the date has past, it multiples the change in price times the number of positions and

adds the result to the value from the previous period. That is what the PREV stands for.

PREV is a special value the refers to the current formulas’ value for the previous period.

It makes a formula slower to calculate and increases the discrepancies if there is an error in the

formula. However, PREV is the only way to create self-referencing formulas in MetaStock

Day Of Week

SYNTAX dayofweek()

This returns an number equal to the day of the week. Monday is assigned the value of 1 and the

other days follow sequentially:

1=Monday

2=Tuesday

3=Wednesday

4=Thursday

5=Friday

6=Saturday

7=Sunday.

Delta

SYNTAX delta( TYPE, DATE, PRICE, INTEREST, DIVIDEND )

This calculates the value of the Delta indicator. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Dema

SYNTAX dema( DATA ARRAY, PERIODS )

This calculates the value of the Dema indicator. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Demand Index

SYNTAX di()

This calculates the value of the Demand Index. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Detrended Price Oscillator

SYNTAX dpo( PERIODS )

This calculates the value of the Detrended Price Oscillator. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Directional Movement Index

SYNTAX dx( PERIODS )

This calculates the value of the Directional Movement Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Directional Movement Rating

SYNTAX adxr( PERIODS )

This calculates the value of the Directional Movement Rating. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Divergence

SYNTAX divergence( DATA ARRAY 1, DATA ARRAY 2, % MINIMUM CHANGE )

This returns either a +1, a -1, or a 0 depending on how closely the values of DATA ARRAY 1

follows the values of DATA ARRAY 2. If they diverge ( i.e., the first array is increasing and the

second is decreasing), it returns a +1. If the two arrays converge ( i.e., the first is decreasing and

the second increasing ), it returns a -1. In all other cases, it returns a 0. Movements in DATA

ARRAY 1 less than % MINIMUM CHANGE are ignored.

The Divergence function is based on the Zig Zag formula. Refer to Chapter 4 for additional

information on using Zig Zag based function.

Division

SYNTAX div( DATA ARRAY, DATA ARRAY )

This function is nothing more than a long way to divide two values. Writing:

div( 10, 2 )

is exactly the same as writing

10 / 2

The MetaStock formula language will treat them exactly the same. Feel free to use whichever

you are most comfortable with.

Dynamic Momentum Index

SYNTAX dmi( DATA ARRAY )

This calculates the value of the Dynamic Momentum Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Copyright © 2002 Equis International

Ease of Movement

SYNTAX emv(PERIODS, METHOD)

Calculates a moving average the Ease of Movement value. The length of the moving average is

specified in PERIODS and the type of average is defined by METHOD. Valid methods are

SIMPLE, EXPONENTIAL, WEIGHTED, TIMESERIES, TRIANGULAR, and VARIABLE.

(These can be abbreviated as S, E, W, T, TRI, and VAR.)

It function is not normally used in formulas except to compare the value of this indicator with

some other value.

Exponent

SYNTAX exp( DATA ARRAY )

Calculates the mathematical constant e raised to the DATA ARRAY power. Normally this will

only be used in Statistical calculations and curve fitting.

Fast Fourier Transform

SYNTAX fft( DATA ARRAY, PERIODS, LENGTH, DETREND or MEAN, AMPLITUDE

or POWER )

This function calculates the Fast Fourier Transform indicator. The various parameters are all

statistical information required for the calculation. The default fourier transform would be

written as:

fft( CLOSE, 100, 1, DETREND, POWER )

Floor

SYNTAX floor( DATA ARRAY )

The Floor() function returns the highest integer that is lower that the smallest value in the data

array. For example:

Floor ( Low )

This would return the highest integer that is smaller than the lowest low value loaded. I.e. if you

had three years of data loaded and the lowest value ever reached by the low during that time was

83 1/4ths, the formula will return 83.

This function is probably more useful in system tests and explorations, but can help you plot and

calculate the new lows of securities.

Forecast Oscillator

SYNTAX forecastosc( DATA ARRAY, PERIODS )

This calculates the value of the Forecast Oscillator. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Formula Call

SYNTAX fml("FORMULA_NAME" )

This is a request for MetaStock to include the calculated value of another formula in your current

one. When referencing a formula's name, the name must be contained in quotation marks (e.g.,

fml( "Secret A")).

If you change a formula's name, you must also change any fml() calls that reference that formula.

For more information on this command, please refer to chapter 3.

Formula Variable Call

SYNTAX fmlvar( "FORMULA_NAME", "VARIABLE_NAME")

This command retrieves the requested variable form the specified formula and incorporates it

into the current formula. Both the formula's name and the variable's name must be contained in

quotation marks (e.g., fmlvar( "Secret A", "MyVar")).

If you change a formula or variable name, you must also change any fmvarl() calls that reference

that formula and variable.

For more information on this command, refer to chapter 5.

Fraction

SYNTAX frac( DATA ARRAY )

This is a number manipulation function. It takes any number and removes everything to the left

of the decimal point. This then is the fractional portion of the number.

For example, if the close was 10.75, then:

frac( C )

would return .75.

Gamma

SYNTAX gamma( TYPE, DATE, PRICE, INTEREST, DIVIDEND )

This calculates the value of the Gamma Indicator. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Gap Down

SYNTAX gapdown()

This function looks for a gap down. The gap down is defined as any period in which the

previous period’s low is greater than the current period’s high. When this occurs, this function

returns a 1. At all other times it returns a 0.

Gap Up

SYNTAX gapup()

This function looks for a gap up. The gap up is defined as any period in which the previous

period’s high is less than the current period’s low. When this occurs, this function returns a 1.

At all other times it returns a 0.

Herrick Payoff Index

SYNTAX hpi( CENTS, MULTIPLYING FACTOR )

This calculates the value of the Herrick Payoff Index. It is not normally used in formulas except

to compare the value of this indicator with some other value.

Highest

SYNTAX highest( DATA ARRAY )

This function examines the entire list of values in DATA ARRAY and returns the one with the

greatest value. This will mainly be used to check for new highs though other uses may be

possible. The key point to remember is that this function reads all data available for its

calculation

Highest Bars Ago

SYNTAX highestbars( DATA ARRAY )

This function reads the DATA ARRAY and returns the number of periods that have past since its

highest value. The key point to remember is that this function reads all the data available and

bases its result accordingly.

Highest High Value

SYNTAX hhv( DATA ARRAY, PERIODS )

Calculates the highest value of the DATA ARRAY from the most recent PERIODS number of

records. The calculation includes the current period. For Example:

HHV( C, 5 )

This returns the highest closing price between the current period and the preceding 4 periods. If

you do not want to include the current period in this calculation, then use the Ref() function:

HHV( Ref( C, -1), 5 )

This returns the highest close from the previous five periods, not including the current one.

Highest High Value Bars Ago

SYNTAX hhvbars( DATA ARRAY, PERIODS )

Looks at the last PERIODS number of records in DATA ARRAY. This function then returns

how many periods have passed since the highest value of those records examined. Remember

that this function always includes the current period in its calculations.

Highest Since

SYNTAX highestsince ( Nth, EXPRESSION, DATA ARRAY )

This function looks at all the data available. It then evaluates the condition detailed in

EXPRESSION. Afterwards, it counts back from the most recent point of data till it finds the Nth

number of times the EXPRESSION was true. From that point, it looks forward at DATA

ARRAY and returns the highest value found. For Example:

highestsince( 2, h > 50, close )

This returns highest value of the close since the second most recent occurrence of the high being

above 50.

Highest Since Bars Ago

SYNTAX highestsincebars( Nth, EXPRESSION, DATA ARRAY )

This function looks at all the data available. It then evaluates the condition detailed in

EXPRESSION. Afterwards, it counts back from the most recent point of data till it finds the Nth

number of times the EXPRESSION was true. From that point, it looks forward at DATA

ARRAY and finds the highest value and. The final result of these calculations it the number of

periods that have passed since this highest value. For Example:

highestsincebars( 2, c > 50, close )

This returns the number of periods that have passed since the highest value of the close (after the

second most recent occurrence of the high being greater than 50).

If

SYNTAX if( EXPRESSION, TRUE DATA ARRAY, FALSE DATA ARRAY )

This is the basic decision making function. It evaluates an expression and then returns one of

two values. If EXPRESSION is true, the result is whatever is in the TRUE DATA ARRAY

position. Otherwise it returns what is in the FALSE DATA ARRAY position. This command is

discussed extensively in chapter 2.

Inertia

SYNTAX inertia( REGRESSION PERIODS, RVI PERIODS)

This calculates the value of the Inertia indicator. The RVI PERIODS is the number of periods

used for the Relative Volatility Index component of the indicator. This function is not normally

used in formulas except to compare the value of this indicator with some other value.

Input

SYNTAX input( "PROMPT TEXT", MINIMUM VALUE, MAXIMUM VALUE,

DEFAULT VALUE)

This function allows the building of custom indicators that prompt for information before they

are plotted, like the built in MetaStock functions.

PROMPT TEXT is the actual text to be displayed when the prompt window opens. This should

be short but descriptive of what is being requested.

MINIMUM VALUE is the smallest number the Input() function is to accept

MAXIMUM VALUE is the largest number the Input() function is to accept

DEFAULT VALUE is the number the Input() function will offer when displayed and the value

used if no changes are made.

This function is discussed in more detail in chapter 5.

Inside

SYNTAX inside()

This will return a +1 whenever an inside day occurs. It will continue to return this same value

until either a Rally, Reaction, or an Outside day occur. At any time where Inside() is not equal to

+1, it will be equal to 0.

An inside day is defined as any period where the current high is less than the previous period’s

high and the current low is greater than the previous period’s low.

Integer

SYNTAX int( DATA ARRAY )

This will return only the non-fractional portion of DATA ARRAY. In other words, anything to

the right of the decimal point is dropped.

IntraDay Momentum Index

SYNTAX imi( PERIODS )

This calculates the value of the IntraDay Momentum Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Klinger Volume Oscillator

SYNTAX kvo()

This calculates the value of the Klinger Volume Oscillator. It does not calculate the trigger line.

For that, a moving average of this function is required. This function is not normally used in

formulas except to compare its value with some other value.

Last Value in Data Array

SYNTAX lastvalue(DATA ARRAY)

This function will always return the last value of DATA ARRAY. Put another way, the

function:

lastvalue( close )

returns the closing price for the last day of data available. By the same token, the function:

lastvalue( MACD() )

returns the value the MACD has on the last day of data available.

This same value is returned no matter when the lastvalue() function is calculated. If the DATA

ARRAY is undefined for any reason (i.e., not enough data to calculate ), lastvalue will return a 0.

Since this function, in effect looks into the future, it is not acceptable for most custom indicators.

It is; however; very beneficial for things like pattern recognition.

Linear Regression Indicator

SYNTAX linearreg( DATA ARRAY, PERIODS )

This calculates the value of the Linear Regression Indicator. This function is a good way of

determining the general direction of a series of data is going. Otherwise, it is rarely used except

to compare its value with another number.

Copyright © 2002 Equis International

Linear Regression Slope

SYNTAX linregslope( DATA ARRAY, PERIODS )

This function returns the value of the Linear Regression Slope indicator. This is normally only

used to compare its value to some other number.

Logarithm (natural)

SYNTAX log( DATA ARRAY )

This function calculated the natural logarithm of DATA ARRAY. It will normally only be of

use in curve fitting and exponential calculations. Some other statistical uses are possible but

beyond the scope of this text.

Lowest

SYNTAX lowest( DATA ARRAY )

This function examines the entire list of values in DATA ARRAY and returns the one with the

lowest value. This will mainly be used to check for new lows though other uses may be possible.

The key point to remember is that this function reads all data available for its calculation

Lowest Bars Ago

SYNTAX lowestbars( DATA ARRAY )

This function reads the DATA ARRAY and returns the number of periods that have past since its

lowest value. The key point to remember is that this function reads all the data available and

bases its result accordingly.

Lowest Low Value

SYNTAX llv( DATA ARRAY, PERIODS )

Calculates the lowest value of the DATA ARRAY from the most recent PERIODS number of

records. The calculation includes the current period. For Example:

LLV( C, 5 )

This returns the lowest closing price between the current period and the preceding 4 periods. If

you do not want to include the current period in this calculation, then use the Ref() function:

LLV( Ref( C, -1), 5 )

This returns the lowest close from the previous five periods, not including the current one.

Lowest Low Value Bars Ago

SYNTAX llvbars( DATA ARRAY, PERIODS )

Looks at the last PERIODS number of records in DATA ARRAY. This function then returns

how many periods have passed since the lowest value of those records examined. Remember

that this function always includes the current period in its calculations.

Lowest Since

SYNTAX lowestsince ( Nth, EXPRESSION, DATA ARRAY )

This function looks at all the data available. It then evaluates the condition detailed in

EXPRESSION. Afterwards, it counts back from the most recent point of data till it finds the Nth

number of times the EXPRESSION was true. From that point, it looks forward at DATA

ARRAY and returns the lowest value found. For Example:

lowestsince( 2, h > 50, close )

This returns lowest value of the close since the second most recent occurrence of the high being

above 50.

Lowest Since Bars Ago

SYNTAX lowestsincebars( Nth, EXPRESSION, DATA ARRAY )

This function looks at all the data available. It then evaluates the condition detailed in

EXPRESSION. Afterwards, it counts back from the most recent point of data till it finds the Nth

number of times the EXPRESSION was true. From that point, it looks forward at DATA

ARRAY and finds the lowest value. The final result of these calculations it the number of

periods that have passed since this lowest value. For Example:

lowestsincebars( 2, c > 50, close )

This returns the number of periods that have passed since the lowest value of the close (after the

second most recent occurrence of the high being greater than 50).

MACD

SYNTAX macd()

This calculates the value of the MACD indicator. It is not normally used in formulas except to

compare the value of this indicator with some other value.

This function only deals with the main (solid ) line. To get the signal line, use the Moving

Average function with this as the data array.

Market Facilitation Index

SYNTAX marketfacindex()

This calculates the value of the Market Facilitation Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Mass Index

SYNTAX mass( PERIODS )

This calculates the value of the Mass Index. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Maximum

SYNTAX max( DATA ARRAY, DATA ARRAY )

This examines both values inserted for the DATA ARRAYs and returns which ever of the two

has the largest numerical value. For more information on this command, please refer to chapter

4.

Median Price

SYNTAX mp()

This calculates the value of the Median Price indicator. It is not normally used in formulas

except to compare the value of this indicator with some other value.

MESA Lead Sine

SYNTAX mesaleadsine( CYCLE LENGTH )

This calculates the value of the MESA Lead Sine indicator that plot along with the MESA Sine

Wave indicator. It is not normally used in formulas except to compare the value of this indicator

with some other value.

MESA Sine Wave

SYNTAX mesasinewave( CYCLE LENGTH )

This calculates the value of the MESA Sine Wave indicator. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Midpoint

SYNTAX mid( DATA ARRAY, PERIODS )

This function calculates the midpoint of the DATA ARRAY over a specified period of time.

The midpoint is defined as the point halfway between the highest value and the lowest value.

Minimum

SYNTAX min( DATA ARRAY, DATA ARRAY )

This examines both values inserted for the DATA ARRAYs and returns which ever of the two

has the smallest numerical value. For more information on this command, please refer to chapter

4.

Minus Directional Movement

SYNTAX mdi( PERIODS )

This calculates the value of the Minus Directional Movement indicator. It is not normally used

in formulas except to compare the value of this indicator with some other value.

Modulus

SYNTAX mod( DATA ARRAY, DATA ARRAY )

Calculates the remainder after the first DATA ARRAY is divided by the second DATA

ARRAY. For example:

Mod( 16, 3 )

This will divide 16 by 3. After 3 goes into 16 a total of 5 times, it can not do so anymore and has

a remainder of 1. The above formula will return the value of 1.

This not normally used in functions but is quite useful for timing an event. For example,

suppose a formula was suppose to do something on every fourth period of data array. Consider

the following condition for an If() statement:

If( Mod( cum( 1 ), 4 ) = 0, TRUE, FALSE )

The cum() function counts how many periods have occurred. After every fourth period, it

triggers a true response and the TRUE condition is executed. On all other periods, the FALSE

condition is used.

Momentum

SYNTAX mo( PERIODS )

This calculates the value of the Momentum indicator. It is not normally used in formulas except

to compare the value of this indicator with some other value.

Money Flow Index

SYNTAX mfi( PERIODS )

This calculates the value of the Money Flow Index. It is not normally used in formulas except to

compare the value of this indicator with some other value.

Month

SYNTAX month()

This returns the month of the year. If today was July 15, 1998, this function would return 7.

Normally the date functions are used in Expert Advisors to display the actual date of the

commentary. See DayofMonth in this section for an unusual exception.

Moving Average

SYNTAX mov( DATA ARRAY, PERIODS, METHOD)

This function calculates a moving average of the DATA ARRAY using PERIODS as the length

of time. The moving average is calculated by the METHOD specified.

Valid methods are EXPONENTIAL, SIMPLE, TIMESERIES, TRIANGULAR, WEIGHTED,

VARIABLE, AND VOLUMEADJUSTED (these can be abbreviated as E, S, T, TRI, W, VAR,

and VOL).

This function is used for calculating trigger lines as well as the standard moving averages. It is

also used to smooth data so trends are more easily discernible. For additional information on

this function, please refer to chapter 1.

Multiplication

SYNTAX mul( DATA ARRAY, DATA ARRAY )

This function is nothing more than a long way to multiple two values together. Writing:

mul( 10, 2 )

is exactly the same as writing

10 * 2

The MetaStock formula language will treat them exactly the same. Feel free to use whichever

you are most comfortable with.

Negative

SYNTAX neg( DATA ARRAY )

This function multiplies the value of data array by negative one. Thus any positive number

becomes a negative and a negative number is turned positive. For example:

Neg( 12 )

The above formula could also be written as:

12 * -1

Use which ever is easiest.

Negative Volume Index

SYNTAX nvi()

This calculates the value of the Negative Volume Index. It is not normally used in formulas

except to compare the value of this indicator with some other value.

On Balance Volume

SYNTAX obv()

This calculates the value of the On Balance Volume indicator. It is not normally used in

formulas except to compare the value of this indicator with some other value.

Option Expiration

SYNTAX optionexp()

This function calculates the number of days till the next option expiration date.

Option Life

SYNTAX life( EXPIRATION DATE )

This calculates the value of the Option Life indicator.

It will display the number of days until the date specified. Please note that the expiration data is

written in the format year month day, using two digits for each value and no spaces. For

example, 990121 refers to January 21, 1999.

Outside

SYNTAX outside()

This will return a +1 whenever an outside day occurs. It will continue to return this same value

until either a Rally, Reaction, or an Inside day occur. At any time where Outside() is not equal to

+1, it will be equal to 0.

An outside day is defined as any period where the current high is greater than the previous

period’s high and the current low is less than the previous period’s low

Parabolic SAR

SYNTAX sar( STEP, MAXIMUM )

This calculates the value of the Parabolic SAR indicator. It is not normally used in formulas

except to compare the value of this indicator with some other value.

Peak Bars Ago

SYNTAX peakbars( Nth, DATA ARRAY, % MINIMUM CHANGE)

This function calculates how many periods have passed since a peak in the specified DATA

ARRAY has occurred. The Nth value is the number of peaks back to count. The % MINIMUM

CHANGE is use by the Zig Zag function to calculate when a peak has occurred. For more

information on the Zig Zag, please refer to chapter 5.

Peak Value

SYNTAX peak( Nth, DATA ARRAY, % MINIMUM CHANGE )

Using the Zig Zag function, this calculates the value DATA ARRAY had at a peak. How many

peaks back to reference is contained in the Nth parameter. %MINIMUM CHANGE is used by

the Zig Zag in calculating the peaks and troughs. Form more information on the Zig Zag, please

refer to Chapter 5.