From the Trading Desk
On Balance Volume keeps a running total of volume: added on up closes, subtracted on down closes. When OBV rises with price, volume is confirming the move; when they disagree, pay attention.
MetaStock ships On Balance Volume as a built-in indicator, and it makes a useful case study for one of MetaSpeak's handiest features: the Input() function. When the original study guide introduced inputs, the worked example was the input dialog on the On Balance Volume indicator, because it shows all four components of the function in one line: the prompt text, the minimum value, the maximum value and the default value.
Look at any Input() call and see if you can identify each component. The astute reader will notice that inputs are most effective when used in conjunction with variables that hold a single value.
A formula can carry more than one input: up to 6, in fact. Remember the triple moving average example from the variables lesson? We can rewrite it so every period length is asked for at plot time:
x:=Input("Enter the short-term moving average value",2,9,5);
y:=Input("Enter the medium-term moving average value",10,19,10);
z:=Input("Enter the long-term moving average value",20,29,20);
C > Mov(C, x, E) AND
Mov(C, x, E) > Mov(C, y, E) AND
Mov(C, y, E) > Mov(C, z, E) Now, each time we plot this as an indicator, a dialog appears asking for all three values before anything is drawn. And when it is drawn, a '1' is displayed whenever every condition is true: the close above the short-term average, the short-term average above the medium, and the medium above the long. Otherwise the indicator sits at '0'.
Two rules to follow. Firstly, since an input by its nature requires someone to type something, it can only be used in the Indicator Builder. It can't be used in explorations, system tests or experts.
Secondly, and more importantly, in most cases you must assign the Input() function to a variable, because Input() cannot be embedded within other functions. This, for example, is not valid:
mov(close, input("Enter the short-term moving average value",1,21,7), s); Pull the input out into a variable and it works:
periods:=Input("Enter the moving average value",1,21,7);
Mov(CLOSE,periods,SIMPLE) As you can see, inputs allow great versatility in your coding: one formula, endlessly adjustable, no editing required. This page sits alongside the free MetaStock Formula Language course; if you're ready to test yourself, the exercises on price array identifiers and arithmetic operators are the natural next step.
Everything in these lessons works in the free 30-day MetaStock trial: full software, live data, your own watchlist.
Start Your Free 30-Day Trial →30-DAY TRIAL · FULL VERSION · CANCEL ANYTIME · AFFILIATE LINK, SAME PRICE FOR YOU
The Formula Language Course: Course home · 1. First formulas · 2. Operators · 3. Precedence & periodicity · 4. Built-in functions · 5. Nesting · 6. Variables · 7. Comments · 8. Pasting functions · 9. Exercises