Formula 101 – #10 Special Context Functions

Quote formulas has a very special ability in extending itself under different context. For example, if you are using quote formula within quote window, you are able to use the column names as if they are predefined functions.

We are going to cover the most common context functions in this tutorial.

Quote Window Context Functions

Quote window formula columns can be labelled. By default, NeoTicker simply name them Formula1, Formula2, etc. You can, however, give your formula columns more descriptive names, and then, use those names in the other formula columns within the same quote window.

Here is a good example why you will want to use column names in your formulas.

Say, you like to rank your symbols with RSI, and then combining that with other conditions to filter the symbols. It is then very convenient to name the formula column containing your RSI indicator calculation as something like MyRSI, and then refer to the value in other formula columns using exactly that name.

Another reason why we would like to use column names in our formula is the ability to change component (more formally, that is called abstraction) in a sophisticated quote window. Following our example, if we have the intention of trying multiple indicators, then we can name the column that hold our bullish/bearish ranking with a generic name like BullScore. Then the rest of the quote window formula columns and alerts can be written with this name without worrying about what exactly we put into that column.

A rule of thumb about naming the formula columns is not using the indicator name as is, or naming the formula column with a predefined quote field name. That way, you will confuse yourself and making it very hard for yourself to understand how the calculated results are generated.

Here is an example based on Tutorial 8.

First we define the column MyOsc using Stochastics SlowK indicator,

formula101 part10 formula setup1

Then we modify the original Pullback column to use the MyOsc column instead of directly calculating the slowk indicator value within the formula,

formula101 part10 formula setup2

Now we are able to change the MyOsc column to other oscillator and still be able to utilize the pullback column formula and its coloring rules without modification,

formula101 part10 window

Dynamic Grid Context Functions

Due to the fact that Dynamic Grid are designed to operate on a cell-by-cell level, it works pretty much like a spreadsheet. Thus the context functions in the dynamic grid are designed to make it works like a spreadsheet.

We have extended the Dynamic Grid formulas to be able to reference other cells through the following functions,

cell (r, c) returns the value currently stored in the cell that is located at the absolute position of the r-th row, and c-th column.

For example, the formula cell (1, 1) returns the value stored in the cell at the upper left hand corner.

rcell (r, c) returns the value currently stored in the cell that is located at the relative position of r rows from the cell containing the formula being evaluated, and c columns from the current cell. For example, rcell (-1, 0) is the cell directly above the current cell.

rownum returns the row number of the current cell. The first row is row 1.

colnum returns the column number of the current cell. the first column is column 1.

cellbylabel (cell_label) returns the value of the cell in the dynamic grid that has the label you have provided in the cell label. Remember that the cell label does not require the special double-quote, the name is recognized automatically.

By combining these functions, you will be able to combine values from various cells easily.

Here is an example.

We are interested to watch 3 moving average levels across multiple symbols. Since we have not decided exactly which moving average to use, and would like to experiment with different periods, we are going to build some flexibility into the dynamic table.

First we would like to setup each column to have its first row containing the period for the moving average.

formula101 part10 dynamic table setup1

Then, the remaining cells in the same column will reference to this first cell in the column as the moving average period parameter,

formula101 part10 dynamic table setup2

Of course, you can also use the cellbylabel function to archieve the same goal,

formula101 part10 dynamic table setup3

The resulting dynamic table will look like this,

formlua101 part10 table1

Now, when you want to use 25 period instead of 20 period for the middle column, all you have to do is to replace the value 20 with 25 in the top cell. Then all the moving averages in that column are recalculated automatically.

formula101 part10 dynamic table2


We have covered all the basic topics related to quote window formulas. If you need extra information, you will need to refer to the Help file for more comprehensive reference to the various functions that are available.

In the rest of the Formula 101 tutorials, we will work on a few case studies utilizing quote formulas.

I will also start a new series called Formula 201 that focus on writing indicators with the formula language.


1. In the example on Dynamic Grid Context Functions, the function cell is used to reference to an exact position in the grid. When we need to insert a column, for example, the formula will be affected and we may not get the correct values we need since the row and column positions have changed. Is there a way to make the call to the cell function more generic?

Answers for Previous Exercise

There is no exercise from previous tutorial.

Discuss this article.

Leave a Comment

Blog Developed
By ContentRobot