safezone: Safezone Stop

Description Usage Arguments Details Value Examples

View source: R/Stops.R

Description

The safezone stop was developed by Alexander Elder. The safezone stop is described in his book "Come Into My Trading Room".

Usage

1
safezone(x, n = 10, coef = 2, prevent = 5, trend = "up")

Arguments

x

An object that is coercible to xts or matrix and contains High-Low prices.

n

Number of lookback periods for the safezone period. Default is 10.

coef

Coefficient for multiplying the average downside (or upside) penetration. Default is 2.

prevent

Prevents the stop from lowering for x days. Default is 5.

trend

Indicates if the safezone stop should be calculated for the up-trend or down-trend. Default is "up". Possible values are "up" or "down".

Details

Once you have defined a trend, you need to choose the length of the lookback period for measuring noise level. It has to be long enough to track recent behavior but short enough to be relevant for current trading.

If the trend is up, mark all downside penetrations during the lookback period, add their depths, and divide the sum by the number of penetrations. This gives you the average downside penetration for the selected lookback period. Multiply the average downside penetration by a coefficient, to place stops farther away from the market than the average level of noise. The results are subtracted from yesterday's low to create the stop. To prevent the stop from lowering too fast, the prevent lookback option will keep the maximum calculated stop for the specified lookback. The rules are reversed for down trend calculations.

Value

Returns the safezone exit points which can be used as stop loss in a trend following strategy.

Examples

1
2
3
4
5
6
7
## Not run: 
# show safezone stop on chart
getSymbols("ADM", from = "2018-01-01", to = "2018-07-01")
chartSeries(ADM)
addTA(safezone(ADM), on = 1)

## End(Not run)

pverspeelt/Quantfunctions documentation built on Jan. 6, 2019, 4:02 a.m.