construct.indicator: Constructs a Trading Indicator Combining Entries and Exits

Description Usage Arguments Details Value Author(s) Examples

Description

Constructs an indicator (1 for long, -1 for short, 0 otherwise). The entries and the exits are provided as boolean vectors, separetely for long and short positions.

Usage

1
construct.indicator(long.entries, long.exits, short.entries, short.exits)

Arguments

long.entries

A boolean vector indicating (TRUE) the long entries

long.exits

A boolean vector indicating (TRUE) the long exits

short.entries

A boolean vector indicating (TRUE) the short entries

short.exits

A boolean vector indicating (TRUE) the short exits

Details

Designed to maintain a single position only.

Implemented in C++ - fast.

Value

An object of the same class as long.entries containing a single column. The positions are encoded as 1, -1 and 0 for long, short and none, respectively.

Author(s)

Ivan Popivanov

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Long entries when RSI2 > 90, long exits when RSI2 < 30
## Short entries when RSI2 < 10, short exits when RSI > 70

require(quantmod)

spy = getSymbols("SPY", auto.assign=FALSE)
rsi = RSI(Cl(spy), n=2)
lentries = !is.na(rsi) & rsi < 10
lexits = !is.na(rsi) & rsi > 70
sentries = !is.na(rsi) & rsi > 90
sexits = !is.na(rsi) & rsi < 30
indicator = construct.indicator(lentries, lexits, sentries, sexits)

btutils documentation built on May 2, 2019, 6:09 p.m.