23

## Formula 101 – #3 Using Functions

Being able to do calculations based on quote fields is nice. The issue is that the possible combinations are pretty limited. What if we want to know the closest round number to the Last price? Or, we want to display the greater of the current day high and the 52-week high?

When we need to derive information from the basic quote fields, we use **functions**.

**What is a function?**

A function is a tool within the formula language. It can be used to derive information from existing data like quote fields. By having a set of functions available, you will be able to tell NeoTicker to do a lot more for you.

**How does a function look like?**

In general a function can look like this,

` name`

name (param1)

name (param1, param2)

name (param2, param2, param3)

...

The name part is the **function name**. param1, param2, param3, etc. are called the **parameters**.

For example, the following are some valid formulas containing functions,

` log10 (Last)`

round (High)

absvalue (Last - PrevClose)

Some of you may already recognize that the functions are written in a fashion similar to the regular mathematics functions. In fact, thats the reason for the name function.

For each function already defined in NeoTicker, they have their own rules for what you can put into their **parameters**. If a function can take only one parameter and you write that in your formula with two parameters instead, you will get an error.

One interesting form of a function is that it can take no parameters, thus making it easily confused as a quote field. For example, the function **pi** returns the value of 3.1415… does not have any parameters. It is not a quote field because it does not change when different symbol becomes the reference. Comparing to a quote field like High, which will give you a different value when it is associated with a different symbol in the quote window.

**An example – Int() function**

Lets take a look at the function **Int**.

When we apply the int function on the Last price, we strip away the fraction part of the price,

**Another example – MaxList() function**

The MaxList function by its definition will return the greatest value among all the parameters you have put into its parameter list. Notice that MaxList is one of the functions that can take on unlimited number of parameters.

When we put the current day high and 52 week high quote fields into MaxList’s parameters, we will be able to get the higher value of the two prices.

Here is a direct comparison with the High column and 52 Week High column displayed side-by-side to our formula column.

**Nesting the functions**

Since all functions return some values, they can be used as parameters within other functions just like the quote fields. For example, the following formula is perfectly valid,

` MaxList (int (High), int (Low + 1))`

Give it a try in your quote window to see what it shows.

**Where do we find the definition of the functions?**

In order to utilize the functions, you need to know what they do. In the NeoTicker help file, under the section Formula Topics and Tutorials>Understanding Formulas>Functions in Formulas listed all the functions available. The ones that will interest you most for now are the ones listed under the generic categories.

**Summary**

Function is an important concept in the formula language. It enhances the power of the formula language tremendously. By learning to use the built-in functions effectively, you can express your ideas much more easily.

**Exercise**

1. If you want to show the lowest price between the current day close and the previous day close, which function should you use and how will the formula look like?

2. What is the formula for the number of minutes since a particular time that you specified?

**Answer to the question from last tutorial**

There are 2 possible answers,

(Last – f52WeekLow) / (f52WeekHigh – f52WeekLow) * 100

or

(DayClose – f52WeekLow) / (f52WeekHigh – f52WeekLow) * 100

**Interact:**Add a Comment | Trackback Link | Permalink

**Share:**digg | del.icio.us | Technorati | StumbleUpon