One of the new features added in Personal Stock Streamer 7.1 is the ability to have custom columns in the Active Securities view, including scriptable columns. In this article I will discuss how to create and manage scriptable columns. To learn about custom columns in general, read the section in the Personal Stock Streamer User's Guide as well as this article.
The new script object that controls the custom columns is the ViewManager object.
Set ViewManager = Application.GetObject("ViewManager")
At this point you can create your custom columns. Expression columns are very straightforward. For example, if you wanted to create a column that always showed double the current price:
ViewManager.CreateExpressionColumn "DoublePrice", "Price * 2"
You could have just as easily added this column through the Custom Columns interface in the program preferences.
The way scriptable columns work are a little more complicated, because scriptable columns are actually memo columns that get their value from a custom ticker attribute. (To learn more about custom attributes, see the scripting object model documentation for the Ticker object.) This means that the value of scriptable columns is filled in indirectly, and you must do the work yourself to fill in the custom attribute and update the view. The reason it was done this way is to make the custom column processing more efficient by avoiding having to recalculate the column value every time the ticker was updated, leaving your script in full control over the timing of the updates.
So to start, let's create a custom column that is associated with a custom attribute. This example is taken from the Trailing Stop extension.
ViewManager.CreateMemoColumn "Trailing Stop", "_TrailingStopComment", True
This code creates a memo column called "Trailing Stop" that gets its value from the _TrailingStopComment attribute, and is read-only in the Active Securities view so the user can not edit it. How do we fill in the _TrailingStopComment variable? The answer to this is inside the Trailing Stop extension: the _TrailingStopComment attribute is set when the trailing stop is set on the ticker, or when the high water mark is updated. The code is as follows:
tmp = FormatNumber(CDbl(dStopMark), 2) + ", " + FormatNumber(CDbl(dStopPct), 2) + "%"
ticker.SetProperty "_TrailingStopComment", tmp
The last thing that needs to be done is that the user interface needs to be updated in order to show the new value for this column:
Set ViewManager = Application.GetObject("ViewManager")
ViewManager.UpdateObjectInView(ticker)
This design ensures that the user interface is only updated when necessary, preventing unnecessary running of script code.
With this basic code it is possible to create columns whose value is calculated through script, which allows you to go through your portfolio and do things like calculations based on historical data or relative to another ticker in the portfolio. If you are interested in creating your own scriptable columns, I recommend reading our Personal Stock Streamer object model documentation and samples found on the Developers section of this site. Also, the full source code for the Trailing Stop extension is available here.