String Support

See Also

 

 

 

 

In Aspen Graphics 4.0, you can assign a string to a return value.

 

direction(instrument)=begin

if instrument.last > instrument.prev then retval = 'RISING'|CLR_GREEN

if instrument.last < instrument.prev then retval = 'FALLING'|CLR_RED

if instrument.last == instrument.prev then retval = 'LEVEL'|CLR_YELLOW

retval

end

 

In the example above, notice the assignment (e.g., retval = 'RISING' CLR_GREEN, etc.) at the end of each if statement. The assignment sets retval equal to both a string and an Aspen color constant. The string is enclosed in single quotation marks, and the constant follows the string. When the formula returns retval, the value is one of three strings, "RISING", "FALLING" or "LEVEL", with the instruction to render the value in green, red or yellow, respectively.

 

Were you to use this formula in a quote window, the value (and its color) displayed depends on the relationship between the last price and the previous price (or net change).

 

You do not have to set the color of the string.

 

Strings are not case sensitive. All strings are displayed in upper case, regardless of how they are typed in the expression.

 

Using Strings on Charts

Aspen Graphics enables you to place strings on charts. This is particularly useful in identifying the existence of certain conditions. For example, the avgxing() formula below prints strings on charts when the lines of short- and long-term moving averages cross:

 

avgxing(input)={

x=''

avg1=eavg($1,10)

avg2=eavg($1,100)

if avg1[1] > avg2[1] and avg1<avg2 then x= 'Sell'|clr_red|below|fsmall|vertical

if avg1[1] < avg2[1] and avg1>avg2 then x = 'Buy'|clr_green|above|fsmall|vertical

x

}

 

Note that each font directive is separated by a pipe ( | ) character.

 

Here, the if statements employ several constants to specify how the string is rendered. In the first if statement, the constants specify that the string 'Sell' will be drawn in red, be below the bar, use the small type face, and be written along a vertical axis (stacked letters). In the second if statement, the string 'Buy' will be drawn in green, be above the bar, use the small type face, and, again, be written vertically.

 

 

©2008 Aspen Research Group, Ltd. All rights reserved. Terms of Use.