• No results found

o Using Profiles

In document Think Script Manual (Page 34-44)

The TPO, Volume, and Monkey Bars profiles can be created in thinkScript using corresponding Profile functions. You can find the detailed description of these functions in the Profiles section.

In order to demonstrate the use of the functions, let's create a TPO profile study (colored blue) that aggregates all chart data on the right expansion.

Here is the code: def allchart = 0;

profile tpo = timeProfile("startnewprofile" = allchart); tpo.show("color" = Color.BLUE);

Reference

The reference describes thinkscript elements (functions, constants, declarations, etc.) required to create studies and strategies. The items are distributed alphabetically among the following sections: Constants, Declarations, Functions, and Reserved Words. Each article provides the syntax, description, and an example of use of the selected item.

All interrelated thinkscript items are cross-linked to ensure you have the fullest information about the relations inside the thinkscript.

Here is the list of the reference sections:

Reserved Words

37

• Declarations 68 • Functions 78 Constants 256 Data Types

312

Operators

315

Reference

o Reserved Words 37 o Declarations 68 o Functions 78  Fundamentals 79  Option Related 92  Technical Analysis 104

 Mathematical and Trigonometrical 132

 Statistical 156

 Date and Time 170

 Corporate Actions 185

 Look and Feel 191

 Profiles 220  Others 234 o Constants 256  Aggregation Period 257  Alert 268  ChartType 269  Color 273  CrossingDirection 283  Curve 285  Double 289  EarningTime 291  FundamentalType 293  OrderType 297  PaintingStrategy 299  PricePerRow 309  Sound 310 o Data Types 312 o Operators 315

o

Reserved Words

The thinkScript supports a number of simple commands such as for example: declare, plot, and input. These commands control the basic behavior of your thinkScript study. Choose your command from the list:

oabove

Syntax

See the crosses reserved word article. Description

The above reserved word is used with the crosses operator to test if a value gets higher than another value.

oago

Syntax

<value> from 1 bar ago

<value> from <length> bars ago Description

This reserved word is used to specify a time offset in a human- friendly syntax. For more information, see the Referencing Historical Data article.

oand

Syntax

<condition1> and <condition2> Description

The and logical operator is used to define complex conditions. For a complex condition to be true it is required that each condition from it is true. In order to define the operator you can also use &&. This reserved word is also used to define an interval in the between expression.

Example

plot InsideBar = high <high[1] and low > low[1];

InsideBar.SetPaintingStrategy(PaintingStrategy.BOOLEAN _POINTS);

Draws a dot near each inside price bar.

obar

Syntax

<value> from 1 bar ago Description

This reserved word is used to specify a time offset in a human- friendly syntax. For more information, see the Referencing Historical Data article.

Note that bar and bars reserved words can be used interchangeably.

obars

Syntax

<value> from <length> bars ago Description

This reserved word is used to specify a time offset in a human- friendly syntax. For more information, see the Referencing Historical Data article.

Note that bar and bars reserved words can be used interchangeably.

obelow

Syntax

See the crosses reserved word article. Description

The below reserved word is used with the crosses operator to test if a value becomes less than another value.

obetween

Syntax

<parameter> between <value1> and <value2> Description

This reserved word is used in the between logical expression. It tests if the specified parameter is within the range of value1 and value2 (inclusive). The thinkscript also has the between function with a different syntax and usage.

Example declare lower;

def isIn = close between close[1] * 0.9 and close[1] * 1.1; plot isOut = !isIn;

In this example between is used to check whether the current closing price hits the 10% channel of the previous closing price. The isOut plot reflects the opposite condition.

ocase

Syntax

See the switch statement. Description

The reserved word is used in combination with the switch statement to define a condition.

ocrosses

Syntax

<value1> crosses above <value2> <value1> crosses below <value2> <value1> crosses <value2> Description

This reserved word is used as a human-readable version of the Crosses function. It tests if value1 gets higher or lower than value2.

Example

plot Avg = Average(close, 10);

plot ArrowUp = close crosses above Avg; plot ArrowDown = close crosses below Avg; plot Cross = close crosses Avg;

ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARR OW_UP); ArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ ARROW_DOWN); Cross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS );

This code plots up arrows indicating the bars at which the Close price gets higher than its 10 period average, and down arrows at which the Close price gets lower than its 10 period average.

The same result can be achieved by using the Crosses function: plot Avg = Average(close, 10);

plot ArrowUp = Crosses(close, Avg, CrossingDirection.Above); plot ArrowDown = Crosses(close, Avg,

CrossingDirection.Below);

plot Cross = Crosses(close, Avg, CrossingDirection.Any); ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARR OW_UP); ArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ ARROW_DOWN); Cross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS ); Example

plot Avg = Average(close, 10); plot Cross = close crosses Avg;

Cross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS );

This code plots arrows indicating the bars at which the Close price gets higher or lower than its 10 period average. The equivalent code is:

plot Avg = Average(close, 10);

plot Cross = close crosses above Avg or close crosses below Avg;

Cross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS );

odeclare

Syntax

declare <supported_declaration_name> Description

The declare keyword is a method for telling the chart

something basic about the appearance of the study or strategy you are creating. You can find the list of supported

declarations in the Declarations section. Example

declare lower;

plot PriceOsc = Average(close, 9) - Average(close, 18); The example shows how to use one of the most commonly used declations called lower. For other examples on declarations, see the Declarations section.

odef

In document Think Script Manual (Page 34-44)

Related documents