Sunteți pe pagina 1din 43

TickInvest 0.8.

0
Documentation
Date: 28 October 2010

written by
Erich Behmen
1 Datamanager................................................................................................................................................ 6
1.1 Create a Symbol List............................................................................................................................ 6
1.2 Downloading and Updating Your Data.................................................................................................. 6
2 Charts........................................................................................................................................................... 7
2.1 Working With Charts............................................................................................................................. 7
2.1.1 Opening a New Chart................................................................................................................... 7
2.1.2 Right Mouse Button Menu............................................................................................................ 7
2.1.3 Scrolling........................................................................................................................................ 7
2.1.4 Zooming........................................................................................................................................ 7
2.1.5 Selecting a Line Type.................................................................................................................... 8
2.1.6 Adding an Indicator....................................................................................................................... 8
2.1.7 Changing an Indicator................................................................................................................... 8
2.1.8 Removing an Indicator.................................................................................................................. 8
3 TickInvest Script Tutorial............................................................................................................................... 9
3.1 Your First Script.................................................................................................................................... 9
3.2 Operators.............................................................................................................................................. 9
3.3 Logical Operators................................................................................................................................. 9
3.4 Variable Assignment............................................................................................................................. 9
3.5 Built in Variables................................................................................................................................. 10
3.5.1 Built in Variables For Backtesting............................................................................................... 10
3.5.2 Built in Variables For Screening.................................................................................................. 10
3.6 Arrays.................................................................................................................................................. 10
3.7 Functions............................................................................................................................................ 10
3.8 Functions Returning Custom Objects.................................................................................................. 11
3.9 The if Statement.................................................................................................................................. 11
3.10 The for Statement............................................................................................................................. 11
3.11 The while Statement......................................................................................................................... 12
4 Writing Java Plugins................................................................................................................................... 13
4.1 Creating New Plugins......................................................................................................................... 13
4.2 Create a New Function....................................................................................................................... 13
4.2.1 Functions With Parameters......................................................................................................... 13
4.2.2 Dataset Parameter...................................................................................................................... 14
4.2.3 Arrays......................................................................................................................................... 15
4.3 Functions Returning Custom Objects................................................................................................. 15
5 Drawing Tools............................................................................................................................................. 16
6 Indicators.................................................................................................................................................... 17
6.1 Creating a Custom Indicator............................................................................................................... 17
6.2 Input Parameters................................................................................................................................ 17
6.3 Legend Name..................................................................................................................................... 18
6.4 Plot Function....................................................................................................................................... 18
7 Stock Screener........................................................................................................................................... 19
7.1 Screener Options................................................................................................................................ 19
7.2 How to Write Screener Scripts............................................................................................................ 19
8 Backtesting................................................................................................................................................. 20
9 Alerts........................................................................................................................................................... 21
10 Memory Usage......................................................................................................................................... 22
11 TickInvest Functions.................................................................................................................................. 23
11.1 Standard Functions........................................................................................................................... 23
11.1.1 ADDCOLUMN........................................................................................................................... 23
11.1.2 ALERTIF................................................................................................................................... 23
11.1.3 BARSSINCE............................................................................................................................. 23
11.1.4 BARSUBPLOT.......................................................................................................................... 24
11.1.5 COMPOSITE .......................................................................................................................... 24
11.1.6 CROSS..................................................................................................................................... 24
11.1.7 GAPDOWN............................................................................................................................... 24
11.1.8 GAPUP..................................................................................................................................... 25
11.1.9 GROUP..................................................................................................................................... 25
11.1.10 HHV (highest high value)........................................................................................................ 25
11.1.11 HHVBARS............................................................................................................................... 26
11.1.12 HIGHEST................................................................................................................................ 26
11.1.13 HIGHESTBARS...................................................................................................................... 26
11.1.14 HIGHESTSINCE..................................................................................................................... 26
11.1.15 IIF............................................................................................................................................ 27
11.1.16 INSIDE.................................................................................................................................... 27
11.1.17 LEGENDNAME....................................................................................................................... 27
11.1.18 NAME...................................................................................................................................... 27
11.1.19 OUTSIDE................................................................................................................................ 28
11.1.20 PLOT....................................................................................................................................... 28
11.1.21 REF......................................................................................................................................... 28
11.1.22 SUBPLOT............................................................................................................................... 28
11.1.23 SYMBOL ..................................................................................................................... 29
11.2 Indicator Functions............................................................................................................................ 30
11.2.1 AD............................................................................................................................................. 30
11.2.2 ADOSC..................................................................................................................................... 30
11.2.3 ADX........................................................................................................................................... 30
11.2.4 ADXR........................................................................................................................................ 30
11.2.5 APO........................................................................................................................................... 30
11.2.6 AROON..................................................................................................................................... 31
11.2.7 AROONOSC............................................................................................................................. 31
11.2.8 ATR........................................................................................................................................... 31
11.2.9 AVGPRICE................................................................................................................................ 31
11.2.10 BBAND.................................................................................................................................... 31
11.2.11 BETA....................................................................................................................................... 32
11.2.12 CCI.......................................................................................................................................... 32
11.2.13 MOM....................................................................................................................................... 32
11.2.14 MACD..................................................................................................................................... 32
11.2.15 OBV........................................................................................................................................ 33
11.2.16 PPO........................................................................................................................................ 33
11.2.17 RSI.......................................................................................................................................... 33
11.2.18 SAR......................................................................................................................................... 33
11.2.19 STOCH................................................................................................................................... 33
11.2.20 STOCHF................................................................................................................................. 34
11.2.21 ULTOSC.................................................................................................................................. 34
11.2.22 WILLR..................................................................................................................................... 34
11.3 Drawing Functions............................................................................................................................ 35
11.3.1 DRAWLINE............................................................................................................................... 35
11.3.2 DRAWRAY................................................................................................................................ 35
11.3.3 DRAWEXTLINE........................................................................................................................ 35
11.3.4 CREATEANNOTATION............................................................................................................. 35
11.4 Message Functions........................................................................................................................... 36
11.4.1 showMessage........................................................................................................................... 36
11.4.2 showInfo.................................................................................................................................... 36
11.4.3 showWarning............................................................................................................................ 36
11.4.4 showError.................................................................................................................................. 36
11.4.5 showYesNoQuestion................................................................................................................. 36
11.4.6 showOkCancelQuestion............................................................................................................ 37
11.4.7 writeMessage............................................................................................................................ 37
12 Math Functions......................................................................................................................................... 38
12.1 Ceil................................................................................................................................................... 38
12.2 Floor.................................................................................................................................................. 38
12.3 Min.................................................................................................................................................... 38
12.4 Max................................................................................................................................................... 38
12.5 Abs.................................................................................................................................................... 39
12.6 Asin................................................................................................................................................... 39
12.7 Atan................................................................................................................................................... 39
12.8 Atan2................................................................................................................................................. 39
12.9 Cbrt................................................................................................................................................... 39
12.10 CopySign........................................................................................................................................ 40
12.11 Cos.................................................................................................................................................. 40
12.12 Cosh............................................................................................................................................... 40
12.13 Exp.................................................................................................................................................. 40
12.14 Expm1............................................................................................................................................. 41
12.15 Hypot.............................................................................................................................................. 41
12.16 Log.................................................................................................................................................. 41
12.17 Log10.............................................................................................................................................. 41
12.18 RInt................................................................................................................................................. 42
12.19 Round............................................................................................................................................. 42
12.20 Sin................................................................................................................................................... 42
12.21 Sinh................................................................................................................................................. 42
12.22 Sqrt................................................................................................................................................. 43
12.23 Tan.................................................................................................................................................. 43
12.24 Tanh................................................................................................................................................ 43
1 Datamanager
To start working with TickInvest you need to create or import a symbol list of your favorite stocks and
download stock data from a data provider.

1.1 Create a Symbol List

Go to Datamanager → Organize Stocks. First create a new group. Use the Table below for reference.

Field Description
Group Name The stock-list that you create will be saved under this group
name.
Data Provider Select your Data Provider
Interval Interval (EOD, 1min, 5mins...)
Download from Start Date for historical data download.
Composite Symbol (Optional) Choose a symbol from your stock-list as composite
index. Or type a new symbol and select 'Use calculated
Composite' checkbox.
Use calculated Composite Currently not implemented
Autoupdate on Startup Currently not implemented

Click save. Now you can add stock symbols or use the ASCII import button to import symbols from a file to
the selected group.

1.2 Downloading and Updating Your Data

Select the group that you would like to download data for. Use the Download Data button to start a new
download or to update your current data. The Clear Data button clears all previously downloaded data, with
the exception of your symbol list.
2 Charts

2.1 Working With Charts

2.1.1 Opening a New Chart

Select the group, interval and symbol. A new chart window will open.

2.1.2 Right Mouse Button Menu

The right mouse button menu allows you to select the line type, remove indicators and save the current
indicator setup for every new chart. Press the right mouse button over a chart to activate this menu.

2.1.3 Scrolling

To scroll, place the mouse over the chart and, while pressing the left mouse button move the mouse in the
direction you wish to scroll, left or right.

2.1.4 Zooming

To zoom, place the mouse over the chart and use the mouse wheel to zoom in or out.
2.1.5 Selecting a Line Type

While in the right mouse button menu choose the Line Type menu. Now you can choose: Candlestick,
OHLC and Line chart

2.1.6 Adding an Indicator

Select the chart in which you would like to add the indicator. Then choose the indicator from the Indicator
menu.

2.1.7 Changing an Indicator

Click on the Legend name of the indicator you want to edit and a dialog will open, allowing you to change the
selected indicator. Some indicators, like Volume, have no options. In these cases, a dialog will not open.

2.1.8 Removing an Indicator

There are two ways to remove the Indicator:

• From the right mouse button menu in the chart window, select Indicators → Remove...

• …or select a legend name and click Remove in the dialog. The Dialog will not open if the Indicator
has no options.
3 TickInvest Script Tutorial

3.1 Your First Script

You can write a script to create your own chart indicators, backtest a strategy, create a new drawing tool or
perform a stock screen. Every script contains one or more statements which must all be terminated by
semicolons. In the backtester and screener the script is executed for each processed stock symbol.

3.2 Operators

TickInvest supports basic operators.

++ increment by one
-- decrement by one
> greater than
>= greater than or equal to
< less than
<= less than or equal to

3.3 Logical Operators

You can combine expressions with logical operators


And operator: (both expressions must be true)

If(close > 10 and close < 100) {



}

Or operator: (one expression must be true)

If(close > 10 or volume > 1000000) {



}

3.4 Variable Assignment

You can freely define new variables. Variables are not restricted to a type. The following examples assign the
outcome of the expressions to the variables 'x', 'y' and 'z' respectively.
The following would assign the value 7 to the variable 'x'.

x = 2+5;
The following would assign the array returned by the moving average function to the variable 'y'.

y = ma(close, 200);

The following would assign the boolean value 'false' to the variable 'z'.

z = 5 > 10;

3.5 Built in Variables

The TickInvest script contains built in variables to allow access to selected useful information. To access
stock data, the arrays: open, high, low, close and volume are available for each currently processed stock.

3.5.1 Built in Variables For Backtesting

For backtesting the special variables buy, sell, score, sellafter and trailstop are available.
The buy array contains boolean values (0 = false/1 = true) for each bar. When the buy array contains a 1 or
true value it means that the backtester can buy this stock at the current bar.
The sell array tells the backtester if the stock can be sold at the current bar.
The score array is used for sorting stocks from high priority to low priority and is explained in the backtesting
chapter 8.

3.5.2 Built in Variables For Screening

The stock screener processor uses the built in variable filter. See chapter 7.2 for details.

3.6 Arrays

If an expression, or the result of an assignment, contains an array, all other single values are converted to
arrays.
For example, this statement contains the array 'close'. The result is that the value '1' will be added to each
value of the array 'close'.

X = close + 1;

Here the array 'buy' is initialized with boolean 'true' values

buy = 1;

3.7 Functions

A function call executes a plugin developed in the java language. Each function can take parameters and can
return an outcome. All functions in TickInvest are implemented as a plugin and are open source.
The following example calls the function ma(). The function takes 2 parameters. The result will be available
for futher processing in the variable 'average'.
average = ma(close, 200);

3.8 Functions Returning Custom Objects

It is possible to return a custom object from a function and then access properties of the object. A good
example is the bband() function.

bb=bband(length, deviation);
legend = legendName("BBand", length, deviation);
plot(legend, bb.bband1, color1 );
plot(legend, bb.bband2, color2 );
plot(legend, bb.bband3, color3 );

The bband() function calculates the Bollinger Bands and returns an instance to this calculation. Later you can
access the 3 calculated arrays with bb.bband1, bb.bband2 and bb.bband3.
Note that 'bb.bband1' is not a function call, you don´t use parentheses and you cannot pass any parameters.
Real function calls are not supported on this objects

3.9 The if Statement

The if statement is a control flow statement. It allows to execute a certain section of code depending on the
result of a test.
If the statement 'x < 10' evaluates to true, then the code 'test = true' in the first block will be executed.
Otherwise, the code in the else block will be executed.

If(x < 10) {


test = true;
} else {
test = false;
}

The else block is optional, so the simplest example of the if statement is this:

If(x < 10) {


test = true;
}

3.10 The for Statement

The for statement is used to iterate over a range of values.


The for statement starts by executing the initialization block. The initialization block is called only once.
Typically, initialization sets a variable to either zero or one. Then, as long as the condition block is true, it
repeatedly executes the body block and then the increment block.

for(initialization; condition; increment) {


body
}
The following example uses the for statement to iterate over all bars of a stock.

mov = ma(close, 200);


for(i=0; i<barcount; i++) {
buy[i] = close[i] > mov[i];
}

Barcount is a built in variable that contains the number of bars.

3.11 The while Statement

The while statement is executed as long as a condition is true.

for(condition) {
body
}

The following example uses the while statement to iterate over all bars of a stock.

x = 0;
mov = ma(close, 200);
while(x < barcount) {
x++;
buy[x] = close[x] > mov[x];
}
4 Writing Java Plugins

4.1 Creating New Plugins

If you are able to programme with Java, creating new plugins for TickInvest is very easy. If you are not
already familiar with a Java IDE, we recommend the use of Netbeans IDE due to its simplicity.

Before you start developing, review the existing plugins in TickInvest. Source code is available for all
TickInvest functions and can be found under … /TickInvest /sdk/TickInvest-Plugins
The following libraries are required to create new plugins:
• TickInvest-SDK
• tclib (Collection library used in TickInvest)

The following libraries are optional:


• ta-lib (Technical Analysis Library)
• jfreechart (Chart Library)
All libraries are located under …/TickInvest /lib.
When you have created a new plugin, place the jar into the …/TickInvest /plugins folder, restart TickInvest
and you can now use the new functions.

4.2 Create a New Function

A function plugin is an annotated java class. To create a helloWorld() function you need
• A java class that implements the FunctionPlugin interface.
• An annotated method with @Function("helloWorld")

Example:

public class HelloWorldExample implements FunctionPlugin {


@Function("helloWorld")
public String function() {
return “Hello World”;
}
}

4.2.1 Functions With Parameters

You can add parameters to the function.

public class HelloExample implements FunctionPlugin {


@Function("hello")
public String function(String yourName) {
return “Hello “ + yourName;
}
}
4.2.2 Dataset Parameter

To get access to the Open, High, Low, Close, Volume and other useful data, create a new function method
and add the Dataset parameter.

@Function("example")
public void example(Dataset data, long length) {

Now you can call the function without passing the Dataset parameter. The Dataset will be automatically
passed by the script-interpreter.

example(200);
4.2.3 Arrays

For performance reasons, an open source collection library, with some minor modifications, is used for
working with arrays: http://www.sosnoski.com/opensrc/tclib/index.html
The most important collection classes are com.sosnoski.util.array.DoubleArray and
com.sosnoski.util.array.BooleanArray.
This is an example of the 'cross' function, that takes two double arrays and returns a boolean array:

@Function("cross")
public static BooleanArray function(DoubleArray array1, DoubleArray
array2) {
assert (array1.size() == array2.size());
BooleanArray crossArray = new BooleanArray(array1.size());
crossArray.add(false);
for (int i = 1; i < array1.size(); i++) {
crossArray.add(array1.get(i - 1) < array2.get(i - 1)
&& array1.get(i) > array2.get(i));
}
return crossArray;
}

4.3 Functions Returning Custom Objects

You can return any object that you create or the instance of the function-plugin.
The script-developer gets read-only access to all properties of the custom object. (see: chapter 3.8)

double[] ma1, ma2, ma3;

@Function("bband")
public BollingerBands bband(Dataset data, long lLength, long
lDeviation) {
// calculates the bollinger bands here...
return this;
}
public DoubleArray getBband1() {
return new DoubleArray(ma1);
}
public DoubleArray getBband2() {
return new DoubleArray(ma2);
}
public DoubleArray getBband3() {
return new DoubleArray(ma3);
}

To allow access to a property you need to create a getter method. Note that the getter-methods do not have
an annotation. To call the property from a script you need to write the method name without the 'get' prefix.
5 Drawing Tools
TickInvest contains ready to use drawing tools: Line, Ray, Extended Line, Horizontal Line, Vertical Line,
Triangle, Rectangle, Parallel Lines. Other will follow in the next releases of TickInvest.
You can easily create your own drawing tools with TickInvest script. You can review the existing drawing
tools in the Draw Editor dialog. The draw script is executed on every mouse move or click and contains
template variables for each x and y position. Each draw function validates first if all passed template
variables are initialized and do nothing if an initialization is missing.
The following example draws a line and creates two annotations for the first and second mouseclick.

drawLine(1, #x1, #y1, #x2, #y2);


createAnnotation(2, #x1, #y1);
createAnnotation(3, #x2, #y2);

The first parameter in both functions is a random number, it is only required, that the number is unique. The
unique id is used to keep an assignment between the draw function and the drawn object on the chart. #x1 is
the x-position of the first mouseclick. #y1 is the y-position of the first mouseclick, #x2 is the x-position of the
second mouseclick and so on.
After the line is drawn, you can move the mouse over the line and drag the line to a another position.
The annotation represents the mouseclick and is drawn as a point. You can later move the mouse over the
annotation and drag the annotation.
Other draw functions are drawRay() to draw a Ray and drawExtLine() to draw an Extended Line.
6 Indicators
Go to Indicators->Edit scripts. You can review the code of all indicators and create your own.

6.1 Creating a Custom Indicator

6.2 Input Parameters

If your indicator requires parameters from the user, you must define them. All input functions use the $ sign
as a prefix.

$IntegerInput(String label, Number defaultValue) takes a numerical value as input..


The example asks the user for the length parameter. The default value is 200.

length=$IntegerInput("Length", 200);

$Combobox(String label, String... options) creates a combobox input component. The function takes
none or an unlimited number of options.
The example creates a combobox with 2 selectable values: “Sma” and “Ema”

type=$Combobox("Type","Sma", "Ema");

If you need to choose a dataset field or other custom variable enter the name of the variable as a string. The
string will be automatically converted to the variable if the function does not accept a string parameter.
Because the ma function requires an array as the first parameter, the chosen string value will be converted to
a variable, i.e. “close” will be converted to the close variable, “high” to the high variable and so on.

field=$Combobox("Range","CLOSE","HIGH","LOW","OPEN");
plot(legend, ma(field, length, type), color );

$ColorChooser(String label, String color) creates a color chooser component.


The example below creates a color chooser component with a default color of red:

color=$ColorChooser("Color","RED");

The following colors are supported as default parameters:

Black Blue Cyan Dark gray


Gray Green Light gray Magenta
Orange Pink Red White
Yellow

6.3 Legend Name

lengendName(String legendName, Object... parameter) This function creates the legend description for
the indicator. It takes none or a unlimited number of parameters.

legend = legendName(“Sma”, length);

6.4 Plot Function

The plot function needs a legendName, an array and a color to plot.


This is the complete example for the moving average indicator:

length=$IntegerInput("Length", 200);
type=$Combobox("Type","Sma", "Ema");
color=$ColorChooser("Color","RED");
field=$Combobox("Range","CLOSE","HIGH","LOW","OPEN");
legend = legendName(type, length);
plot(legend, ma(field, length, type), color );
7 Stock Screener
The stock screener helps you find the stocks that meet your trading strategy. You must write a script with
your criteria to define the results you wish to see. After the stock screening process you can click on the
resulting stocks and analyse the chart.

7.1 Screener Options

Before you start screening for stocks you can select the date range.
n last days lets you search the last 'n' days. The default value for 'n' is 7 days.
from / to range lets you specify a date range. Use it when you want analyse stocks that matched your
strategy in the past.

7.2 How to Write Screener Scripts

filter is a special boolean array generated by the assigned criteria. The screener processor uses this special
variable to find stocks that match your criteria.

The following script searches for stocks where the 'close' value is higher than 10 and lower than 100.

filter = close > 10 and close < 100;

addColumn() is a functions that creates a new column in the screener Results table. By default only the
'symbol' and 'date' columns are available. The following example adds the 'close' value to the Results table.

addColumn(close, “Close”);

This example finds stocks that have closed more than 20 percent higher than their moving average and
creates an additional result column that shows the “Over MA” percentage. The script plots a moving average
with length 200 when you analyse a stock.

filter = close > ma(close, 200) * 1.2 and ma(close, 200) != 0;


addColumn(100/ma(close, 200)*close-100, "Over MA");
name = legendName("MA", "200");
plot(name, ma(close, 200), "red");
8 Backtesting
In the Backtester dialog you can create and test your own trading systems with TickInvest script. All scripts
are saved in a locally embedded database. If you later change the script, your old backtesting results and
scripts are kept in the history. Scripts that have never been backtested will not be kept in the history.
To access the scripts in the history, select the current script node in the script database and the node will
open. Now you can compare the saved results. To get detailed results for current or historcal script you need
to select the script and run the backtest. You can remove historical script using the delete button. If you
remove the parent script, all historical scripts will be deleted.

For backtesting the special variables buy, sell, score, sellafter are available.
The buy array contains boolean values (0 = false/1 = true) for each bar. When the buy array contains a 1 or
true value it means that the backtester can buy this stock at the current bar.
The following example buys stocks where the close crosses over the moving average with length 200.

buy = cross(close, ma(close, 200));

The sell array tells the backtester if the stock can be sold at the current bar.
The following example sells stocks where the close crosses under the moving average with length 200.

sell = cross(ma(close, 200), close);

The score array is used for sorting stocks from high priority to low priority.
The following example measures the distance between the close and the moving average in percentage. Top
performing stocks with the highest percentage will be preferred.

score = 100/ma(close, 200)*close-100;

sellafter variable sells stocks after a fixed number of bars.


The following example sells stocks after 20 bars.

sellafter = 20;
9 Alerts
When you enable alerts, they are executed automatically on every program start. You can use alerts on
charts that you open or select whole groups of stocks to execute alerts on.
If you select groups, all groups will be automatically updated on program start. Then the alert script is
executed for every stock in the group.
If you use a real-time dataprovider, the script will be executed periodically. Currently the period is set to 10
seconds. You will be able to adjust the period in the next program release.

Field Description
Scan number of bars The stock-list that you create will be saved under this group
name.
Alert execution When checked, the script will be executed when you enable
alerts. Uncheck this to disable scripts that you don´t want to
use.
Execute alerts on: open charts Alerts will be executed only on charts that are currently open
on your desktop.
Execute alerts on: selected groups When you select this, you will be able to select multiple groups
of stocks to execute alerts on.
10 Memory Usage
If you are working with many years of stock data, you may need to reserve more memory. If you do not have
enough memory reserved, you will get an “out of memory” error message.
In the TickInvest install directory open the file TickInvest.vmoptions with an text editor. The -Xmx parameter
is the maximum heap size and the -Xms parameter is the minimum heap size. The default maximum heap
size is set to 512MB. Change the -Xmx parameter to suit your needs.

-Xmx512m
-Xms128m

It is importnant that you keep a blank line on the end of the file, so do not remove this line!
11 TickInvest Functions

11.1 Standard Functions

11.1.1 ADDCOLUMN

Creates a new column in the stock-screener result list.


Syntax:
• addColumn( DOUBLE ARRAY, STRING COLUMN_NAME )
Returns:
• NOTHING
Example:
• addColumn( ma(close, 200), “MA(200)”)

11.1.2 ALERTIF

Creates an alert for the latest bar in the boolean array that evaluates to true.
If an alert is executed depends on the seting in the alert editor. Only the last n bars that you have set for this
alert script will be evaluated. This Function can be used only in the alert editor.
For more information about alerts read chapter 9. Alerts.

Syntax:
• alertIF( BOOLEAN ARRAY, STRING MESSAGE )

The following example executes an alert if the close cross above the moving average.
Example:

ma = ma(close, 200);
cross = cross(close, ma);
alertIF(cross, "Crossed MA(200)");

11.1.3 BARSSINCE

Calculates the number of bars since an boolean expression was true


Syntax:
• barsSince( BOOLEAN ARRAY )
Returns:
• DOUBLE ARRAY
Example:
• barsSince(close > 50)
11.1.4 BARSUBPLOT

Plots the array to a subplot using the bar renderer. The first version creates a new subplot, The second
version uses an existing subplot.
Syntax:
• barsubplot(LEGENDNAME, DOUBLE ARRAY, COLOR)
• barsubplot(XYPLOT, LEGENDNAME, DOUBLE ARRAY, COLOR)
Returns:
• XYPLOT

11.1.5 COMPOSITE

Returns the dataset of the composite stock that belongs to the selected group in backtesting or screening.
Syntax:
• symbol(STRING_SYMBOL)
Returns:
• DATASET with the properties: open, high, low, close and volume
See also:
• symbol()
• group()

11.1.6 CROSS

Creates a boolean array with the value 1, or true, when array1 crosses above array2 or otherwise the value
is 0, or false.
Syntax:
• cross( DOUBLE ARRAY1, DOUBLE ARRAY2 )
Returns:
• BOOLEAN ARRAY
Example:
• cross(close, ma(close, 200))

11.1.7 GAPDOWN

Creates a boolean array with the value 1, or true, when current bar´s high is lower than the previous bar´s
low.
Syntax:
• gapdown()
Returns:
• BOOLEAN ARRAY
11.1.8 GAPUP

Creates a boolean array with the value 1, or true, when current bar´s low is higher than the previous bar´s
high.
Syntax:
• gapup()
Returns:
• BOOLEAN ARRAY

11.1.9 GROUP

Allows you to iterate over all symbols of a foreign group. The returned object has the properties hasNext and
next. With hasNext you test if another symbol is available in the current iteration, hasNext returns a boolean.
'next' returns the next available DATASET in the current iteration.
This function can be very slow, because it loads all stocks into memory.
Syntax:
• group(STRING_GROUP)
Returns:
• GROUP OBJECT with the properties: hasNext and next (see example)
See also:
• symbol()
• composite()
Example:

g = group("S&P 500");
while(g.hasNext) {
foreignStock = g.next;
...
}

11.1.10 HHV (highest high value)

Calculates the highest value in the ARRAY over the preceding periods.
Syntax:
• hhv( DOUBLE ARRAY, PERIODS )
Returns:
• DOUBLE ARRAY
Example:
• hhv( close, 7 ) - Calculates the highest value for the last 7 periods.
11.1.11 HHVBARS

Calculates the number of periods that have passed since the ARRAY reached its periods period peak.
Syntax:
• hhvbars( DOUBLE ARRAY, PERIODS )
Returns:
• DOUBLE ARRAY

11.1.12 HIGHEST

Calculates the highest VALUE in the ARRAY for previous and the current day.
Syntax:
• highest( DOUBLE ARRAY )
Returns:
• DOUBLE ARRAY
Example:
• maxMA = highest( ma(close, 200) )

11.1.13 HIGHESTBARS

Returns the number of periods that have passed since the ARRAY´s highest DOUBLE VALUE in the
DOUBLE ARRAY
Syntax:
• highest( DOUBLE ARRAY )
Returns:
• DOUBLE VALUE

11.1.14 HIGHESTSINCE

Returns the highest ARRAY value since EXPRESSION was true on the Nth (default=1) most recent
occurrence.
Syntax:
• highestsince( BOOLEAN EXPRESSION, DOUBLE ARRAY )
• highestsince( BOOLEAN EXPRESSION, DOUBLE ARRAY, NTH OCCURENCE )
Returns:
• DOUBLE VALUE
11.1.15 IIF

Evaluates the boolean expression and returns value1 for true and value2 for false.
If you pass one or two arrays then array processing will be used to create the return value.
Syntax:
• iif(BOOLEAN EXPRESSION, VALUE1/ARRAY1 FOR TRUE, VALUE2/ARRAY2 FOR FALSE )
Returns:
• DOUBLE ARRAY, BOOLEANARRAY or OBJECT depending on the parameter types.

11.1.16 INSIDE

Creates a boolean array with the value 1, or true, when current bar´s low is higher then previous bar low and
current bar´s high is lower than previous high.
Syntax:
• inside()
Returns:
• BOOLEAN ARRAY

11.1.17 LEGENDNAME

This function creates the legend description for the plot / indicator. It takes none or a unlimited number of
parameters.
Syntax:
• legendname( STRING NAME, PARAMETERS... )
Returns:
• LEGENDNAME

Example

legend = legendName(“Sma”, length);


plot(legend, ma(field, length, type), color );

11.1.18 NAME

Returns the symbol-name of the current stock


Syntax:
• name()
Returns:
• STRING
11.1.19 OUTSIDE

Creates a boolean array with the value 1, or true, when current bar´s low is lower then previous bar low and
current bar´s high is higher than previous high.
Syntax:
• outside()
Returns:
• BOOLEAN ARRAY

11.1.20 PLOT

Plots the array to the chart.


Syntax:
• plot(LEGENDNAME, DOUBLE ARRAY, COLOR)
Returns:
• XYPLOT

11.1.21 REF

References a previous or subsequent element in a ARRAY.


A positive period references "n" periods in the future.
A negative period references "n" periods ago.
Syntax:
• ref( ARRAY, PERIOD )
Returns:
• ARRAY
Example:
• barsSince(close > 50)

11.1.22 SUBPLOT

Plots the array to a subplot. The first version creates a new subplot, The second version uses an existing
subplot.
Syntax:
• subplot(LEGENDNAME, DOUBLE ARRAY, COLOR)
• subplot(XYPLOT, LEGENDNAME, DOUBLE ARRAY, COLOR)
Returns:
• XYPLOT
11.1.23 SYMBOL

Returns the dataset of a foreign stock symbol that belongs to the selected group.

Syntax:
• symbol(STRING SYMBOL)
Returns:
• DATASET with the properties: open, high, low, close and volume
See also:
• composite()
• group()
11.2 Indicator Functions

11.2.1 AD

Chaikin A/D Line


Syntax:
• AD()
Returns:
• DOUBLE ARRAY

11.2.2 ADOSC

Chaikin A/D Oscillator


Syntax:
• ADOSC( FAST_PERIOD, SLOW_PERIOD )
Returns:
• DOUBLE ARRAY

11.2.3 ADX

Average Directional Movement Index


Syntax:
• ADX( PERIOD )
Returns:
• DOUBLE ARRAY

11.2.4 ADXR

Average Directional Movement Index Rating


Syntax:
• ADXR( PERIOD )
Returns:
• DOUBLE ARRAY

11.2.5 APO

Absolute Price Oscillator


Syntax:
• ADXR( FAST_PERIOD, SLOW_PERIOD )
Returns:
• DOUBLE ARRAY
11.2.6 AROON

Aroon Indicator
Syntax:
• aroon( PERIOD )
Returns:
• DOUBLE ARRAY

11.2.7 AROONOSC

Aroon Oscillator
Syntax:
• aroonosc( PERIOD )
Returns:
• DOUBLE ARRAY

11.2.8 ATR

Average True Range


Syntax:
• atr( PERIOD )
Returns:
• DOUBLE ARRAY

11.2.9 AVGPRICE

Average Price
Syntax:
• avgprice()
Returns:
• DOUBLE ARRAY

11.2.10 BBAND

Calculates the Bollinger Bands


Syntax:
• BBAND( PERIOD, DEVIATION )
Returns:
• BBAND object with properties to bband1 (upper band), bband2 (moving average), bband3 (lower
band)
Example:

bb=bband(period, deviation);
legend = legendName("BBand", period, deviation);
plot(legend, bb.bband1, color1 );
plot(legend, bb.bband2, color2 );
plot(legend, bb.bband3, color3 );

11.2.11 BETA

Beta Indicator
Syntax:
• beta( ARRAY1, ARRAY2, PERIOD)
Returns:
• DOUBLE ARRAY

11.2.12 CCI

CCI Indicator
Syntax:
• cci( LENGTH )
Returns:
• DOUBLE ARRAY

11.2.13 MOM

Momentum Indicator
Syntax:
• mom( LENGTH )
Returns:
• DOUBLE ARRAY

11.2.14 MACD

Moving Average Convergence Divergence.


A trend-following momentum indicator.
Syntax:
• MACD( FAST_PERIOD, SLOW_PERIOD, SIGNAL_PERIOD )
Returns:
• MACD Object with properties: line, signal and histogram
11.2.15 OBV

On Balance Volume
Syntax:
• obv()
Returns:
• DOUBLE ARRAY

11.2.16 PPO

Percentage Price Oscillator


Syntax:
• ADXR( FAST_PERIOD, SLOW_PERIOD )
Returns:
• DOUBLE ARRAY

11.2.17 RSI

Relative Strength Index


Syntax:
• RSI( DOUBLE ARRAY, PERIOD )
Returns:
• DOUBLE ARRAY

11.2.18 SAR

Parabolic SAR
Syntax:
• SAR( ACCELERATION, MAXIMUM )
Returns:
• DOUBLE ARRAY

11.2.19 STOCH

Slow Stochastic Oscillator


Syntax:
• stoch( K-PERIOD, D-PERIOD )
• stoch( K-PERIOD, SLOWING, D-PERIOD, MA-TYPE )
Returns:
• STOCH Object with properties: stochK and stochD
11.2.20 STOCHF

Fast Stochastic Oscillator


Syntax:
• stochf( K-PERIOD, D-PERIOD )
Returns:
• STOCHF Object with properties: stochK and stochD

11.2.21 ULTOSC

Ultimate Oscillator
Syntax:
• ultOsc( LENGTH, LENGTH2, LENGTH3 )
Returns:
• DOUBLE ARRAY

11.2.22 WILLR

Williams %R
Syntax:
• williamsR( LENGTH )
Returns:
• DOUBLE ARRAY
11.3 Drawing Functions

11.3.1 DRAWLINE

Draws a line from a startpoint to endpoint.


Syntax:
• drawline( ID, START_POS_X, START_POS_Y, END_POS_X, END_POS_Y )

11.3.2 DRAWRAY

Draws a ray.
Syntax:
• drawray( ID, START_POS_X, START_POS_Y, END_POS_X, END_POS_Y )

11.3.3 DRAWEXTLINE

Draws an extended line.


Syntax:
• drawextline( ID, START_POS_X, START_POS_Y, END_POS_X, END_POS_Y )

11.3.4 CREATEANNOTATION

Creates a annotation point.


Syntax:
• createannotation( ID, START_POS_X, START_POS_Y )
11.4 Message Functions

11.4.1 showMessage

Creates a dialog with a title and a message


Syntax:
• showMessage( STRING TITLE, STRING MESSAGE )

11.4.2 showInfo

Creates a dialog with an info icon with a title and a message


Syntax:
• showInfo( STRING TITLE, STRING MESSAGE )

11.4.3 showWarning

Creates a dialog with an warning icon with a title and a message


Syntax:
• showWarning( STRING TITLE, STRING MESSAGE )

11.4.4 showError

Creates a dialog with an error icon with a title and a message


Syntax:
• showError( STRING TITLE, STRING MESSAGE )

11.4.5 showYesNoQuestion

Creates a yes / no question dialog with a title and a message

Syntax:
• showYesNoQuestion( STRING TITLE, STRING MESSAGE )
Returns:
• boolean value
Example:

if(showYesNoQuestion( “question”, “do you agree?” ) {


….
} else {
…..
}
11.4.6 showOkCancelQuestion

Creates an ok / cancel question dialog with a title and a message

Syntax:
• showOkCancelQuestion( STRING TITLE, STRING MESSAGE )
Returns:
• boolean value

11.4.7 writeMessage

Writes text to the status window. The color is optional and defaults to black.
Syntax:
• writeMessage( STRING TEXT )
• writeMessage( STRING TEXT, COLOR )

writeMessage( “This is a message”, “red” );

}
12 Math Functions

12.1 Ceil

Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is
equal to a mathematical integer.
Syntax:
• ceil( double a )
Returns:
• double

12.2 Floor

Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal
to a mathematical integer.
Syntax:
• floor( double a )
Returns:
• double

12.3 Min

Returns the smaller of two values. The result is the value closer to negative infinity. If the arguments have
the same value, the result is that same value.
Syntax:
• min( double a, double b )
Returns:
• double

12.4 Max

Returns the greater of two values. The result is the argument closer to positive infinity. If the arguments have
the same value, the result is that same value.
Syntax:
• max( double a, double b )
Returns:
• double
12.5 Abs

Returns the absolute value of a value. If the argument is not negative, the argument is returned. If the
argument is negative, the negation of the argument is returned.
Syntax:
• abs( double a )
Returns:
• double

12.6 Asin

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.
Syntax:
• asin( double a )
Returns:
• double

12.7 Atan

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.
Syntax:
• atan( double a )
Returns:
• double

12.8 Atan2

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.
Syntax:
• atan2( double y, double x )
Returns:
• double

12.9 Cbrt

Returns the cube root of a double value. For positive finite x, cbrt(-x) == -cbrt(x) that is, the cube root of a
negative value is the negative of the cube root of that value's magnitude.
Syntax:
• cbrt( double x )
Returns:
• double
12.10 CopySign

Returns the first floating-point argument with the sign of the second floating-point argument.
Syntax:
• copySign( double magnitude, double sign )
Returns:
• double

12.11 Cos

Returns the trigonometric cosine of an angle.


Syntax:
• cos( double a )
Returns:
• double

12.12 Cosh

Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be
(ex + e-x)/2 where e is Euler's number.
Syntax:
• cos( double x )
Returns:
• double

12.13 Exp

Returns Euler's number e raised to the power of a double value.


Syntax:
• exp( double a )
Returns:
• double
12.14 Expm1

Returns ex-1. Note that for values of x near 0, the exact sum of expm1(x)+1 is much closer to the true result
of ex than exp(x).
Syntax:
• expm1( double x )
Returns:
• double

12.15 Hypot

Returns sqrt(x2+y2) without intermediate overflow or underflow.


Syntax:
• hypot( double x, double y )
Returns:
• double

12.16 Log

Returns the natural logarithm (base e) of a double value.


Syntax:
• log( double a )
Returns:
• double

12.17 Log10

Returns the base 10 logarithm of a double value.


Syntax:
• log( double a )
Returns:
• double
12.18 RInt

Returns the double value that is closest in value to the argument and is equal to a mathematical integer. If
two double values that are mathematical integers are equally close, the result is the integer value that is
even.
Syntax:
• rint( double a )
Returns:
• double

12.19 Round

Returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor
of the result, and casting the result to type long. In other words, the result is equal to the value of the
expression: (long)Math.floor(a + 0.5d)

Syntax:
• round( double a )
Returns:
• long

12.20 Sin

Returns the trigonometric sine of an angle.

Syntax:
• sin( double a )
Returns:
• double

12.21 Sinh

Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be (ex-e-x)/2 where e is
Euler's number.

Syntax:
• sinh( double x )
Returns:
• double
12.22 Sqrt

Returns the correctly rounded positive square root of a double value.

Syntax:
• sqrt( double a )
Returns:
• double

12.23 Tan

Returns the trigonometric tangent of an angle.

Syntax:
• tan( double a )
Returns:
• double

12.24 Tanh

Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be (ex-e-x)/
(ex+e-x), in other words, sinh(x)/cosh(x). Note that the absolute value of the exact tanh is always less
than 1.

Syntax:
• tanh( double x )
Returns:
• double

S-ar putea să vă placă și