safezone: Safezone Stop

Description Usage Arguments Details Value See Also Examples

View source: R/protective_stops.R

Description

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

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.

See Also

Other protective stops: ATR_stop(), chandelier()

Other Alexander Elder functions: alert_marker(), thermometer()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
# show safezone stop on chart
library(quantmod)
ADM <- getSymbols("ADM", 
                  from = "2018-01-01", 
                  to = "2018-07-01",
                  auto.assign = FALSE)
chartSeries(ADM)
addTA(safezone(ADM), on = 1)

## End(Not run)

pverspeelt/Quantfunctions documentation built on Oct. 10, 2021, 1:01 p.m.