Crosses

Crosses ( double direction);

Default values:

direction: CrossingDirection.ANY

Description

The Crosses function tests if data1 gets higher or lower than data2. It returns true when data1 becomes greater than data2 if the direction parameter is CrossingDirection.ABOVE. Conversely, the function returns true when data1 becomes less than data2 if the direction parameter is CrossingDirection.BELOW. The function can also indicate a crossover irrespective of its direction if the direction parameter is CrossingDirection.ANY.

Input parameters

Parameter Default value Description
data1 - Defines the first value for comparison.
data2 - Defines the second value for comparison.
direction - Defines whether to find crossovers of first value above or below the second value. This parameter accepts Crossing Direction constants as value.

Example 1

plot avg = Average(close, 10);
plot crossing1 = close > avg and close[1] <= avg[1];
plot crossing2 = Crosses(close, avg, CrossingDirection.ABOVE);
crossing1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossing2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

The crossing1 and crossing2 variables are equal definitions of a condition when the Close price crosses the simple moving average with the length equal to 10. In other words, the Crosses function serves as a more compact and flexible way of defining intersections.

Example 2

input crossingType = {default above, below};
def avg = Average(close, 10);
plot Crossing = Crosses(close, avg, crossingType == CrossingType.above);
Crossing.SetPaintingStrategy(if crossingType == CrossingType.above
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);

The example first determines the crossing type of the Close price and the simple moving average for the last 10 bars. Depending on whether the crossing is up or down, the code draws either the arrow up or arrow down mark below and above the corresponding bars. Note that above and below here are enumeration constants.