LEVELCROSS

Purpose:

Creates a series with 1.0 (TRUE) where the input series crosses the level and 0.0 (FALSE) elsewhere.

Syntax:

LEVELCROSS(series, level, edgedetect, edgeout)

series

-

An input series.

level

-

A real, the level crossing threshold.

edgedetect

-

Optional. An integer for crossing definition. Defaults to 0. Valid arguments are:

0:

Detect both rising and falling edges (default).

1:

Detect rising edges only.

2:

Detect falling edges only.

edgeout

-

Optional. An integer. Output value alignment. The output value will be placed to the left or right of the actual crossing point as specified below:

0:

Left if input edge rising, right if falling (default).

1:

Right on rising, left on falling.

2:

Right whether rising or falling.

3:

Left whether rising or falling.

4:

Linearly interpolate the X crossing values if necessary.

Returns:

A binary series.

Example:

levelcross(gsin(100, .01, 4), 0.0)

 

returns a binary series with values of 1 wherever the sine wave crosses a threshold of 0.0 (whether rising or falling), and 0 elsewhere.

Example:

W1: gsin(100, .01, 4)

W2: 0.3*levelcross(w1, 0.3, 0, 4);setsym(14);overp(w1,lred);setplotstyle(1,1)

 

W1 contains a 4 Hz sinewave.

 

W2 returns an XY series with values of 0.3 wherever the sine wave crosses a threshold of 0.3 (whether rising or falling). The original sinewave is overplotted and the level crossings are marked as solid circle symbols.

Remarks:

Because LEVELCROSS returns a regularly spaced series (i.e. an interval series), the actual crossing point may occur between two data points. The optional edgeout parameter determines where the detected edge output will be placed.

 

LEVELCROSS returns the exact crossing point if edgeout is set to 4. In this case, LEVELCROSS returns an XY series, where X is the crossing location and Y is 1.0. For example:

 

W1: gsin(100, .01)

W2: xvals(levelcross(W1, 0.2, 0, 4))

 

Returns the series {0.032058, 0.467942}, the interpolated X locations of where W1 == 0.2.

 

When edgeout != 4, LEVELCROSS returns a zero if there is a value in the series identically equal to the crossing threshold. To identify this point as a crossing point use:

 

levelcross(series,level,edgedetect) || (series == level)

See Also:

&& || ! AND OR NOT XOR (Logical Operators)

< <= > >= == != (Conditional Operators)

GETPEAK

GETVALLEY

XY