Aug
19

Formula 101 – #2 Quote Fields & Arithmetic Operators

In this tutorial, we’ll focus on the parts that make up the formula language and how that works together.

The Quote Fields

In last tutorial we’ve worked on the following example formula,

(Open + High + Low + Last) / 4

The quote window accepted this as a valid formula and returns proper calculated values based on the formula.

So it is obvious that the quote window recognizes the words Open, High, Low and Last. It also recognizes the brackets, the addition sign, the division sign, and the number 4.

The four (4) words we have used in the formula are known as quote fields. Every quote field available in NeoTicker can be used in the formulas. NeoTicker will recognize them properly and evaluate them just like the actual quote fields. Quote fields are one of the most basic components in the quote window formulas because you cannot split these quote fields into something simplier.

For example, you can create a new formula column and type in the following formula,

Bid

It will show you exactly the same value as a regular Bid column that you can insert into a quote window.

You can also experiment with other quote fields like BidSize, Ask, AskSize, etc.

There are a few tricky rules though.

For quote fields starting with digits, like 52WeekHigh, you cannot just type the word 52WeekHigh into a formula because it is not recognized. Instead you need to have the letter f placed in front of the quote field’s name to make NeoTicker recognize the quote field. So, to use 52WeekHigh in your formula, you have to type in f52WeekHigh instead.

Another tricky situation is that when a quote field contains characters that may as well be recognized as an operator, like the addition sign + or the percent sign %. When that happen, we replace those special characters with another short form that contains only letters. For the percent sign, replace that with pct. So, to use the quote field Net% within a formula, type NetPct instead.

In short, quote fields can be viewed as words within a sentence in English. The built-in quote fields is your basic vocabulary for writing quote formulas.

Numeric Constants

In the original example, the formula added up the quote fields and then divided that by the number 4. Numeric values are recognized as-is in the formula. They are called Numeric Constants. No change is made to these numeric constants you’ve typed into the formula.

So when you need to express your ideas with numeric constants, just type them
in as you would in your everyday usage in English.

Arithmetic Operators

While quote fields are evaluated as actual values, we need tools to manipulate these items to get the calculated results we want. Thats how operators come into play. NeoTicker’s formula is deisgned to look like mathematic expressions we’ve learned in school. For example, to add 2 numbers we will simply write the following formula,

2 + 3

There are a number of arithmetic operators,

+ sign for addition
- sign for subtraction
* sign for multiplication
/ sign for division

Proper priority is given to operators like multiplication * and division /, as that is the case for general mathematic expressions. The following calculation will result in 16 due to the priority arrangement, as oppose to 22 when the calculation is carried out purely from left to right.

2 * 3 + 5 * 2

Normal usage of the brackets is supported in the quote formulas too. Thus you can force the above formula to evaluate in the order you think that is appropriate, like,

(2 * 3 + 5) * 2

which will then results in 22.

Brackets can be nested as many times as you want so that proper calculation results can be obtained. For example, the following formula is using brackets quite extensively,

((High + Low) / 2 + (High + Low + Last) /3 + (Open + Last) / 2) / 3

What it does is taking the average of 3 very common calculations of the midpoint of the day.

Another Example

We are now ready to create another formula column,

formula101 part2 formula

I have given the column the name MyRngPct.

So what does this formula do?

Add another column to the quote window, this time, the Range% quote column.

Here is how it should look like,

formula101 part2 quote window

Notice the Range% column is exactly the same as the formula column we have just created.

I think it is now obvious that the Range% field is calculated exactly the same way we’ve done in the formula.

Summary

We have covered some of the important concepts of how a formula is written. These concepts are very important as we build on top of that to explore the other parts of the formula language.

Do take some time to practice what you have learned.

Here is a good exercise – can you construct a 52 week range percent column? Answer will be disclosed in the next tutorial.

Discuss this article.

2 Comments on “Formula 101 – #2 Quote Fields & Arithmetic Operators”

  1. Ted Adams Says:

    I think I see the answer to my last question . So, Open – High – Low and Last are recognized,
    but ( H )and( L )would need more info for NT to recognize . Also, the full words above would
    probably refer to daily ,because not otherwise specified .???yes/no .I’m pretty sure I know
    the answer to your “homework”, as range% and range % yesterday are things I like to look at .
    I’m printing out these lessons ,so I can refer back to them easily in the future . Looking
    forward to the next . What about plain old ” close ” ? This is good , laying out the proper
    foundation :like building a house :won’t work very good without it .
    Thanks
    Ted

  2. Lawrence Chan Says:

    Open, High, Low and Last are Quote Fields. Quote fields are current values from your data feed. You can actually find a list of all the quote fields in the Help file. For the Open, High, Low, and Last quote fields, they just happen to be the values of the current day.

Leave a Comment

Blog Developed
By ContentRobot