crossOver (vars Data1, vars Data2) : bool

crossUnder (vars Data1, vars Data2) : bool

crossOver (vars Data, var border) : bool

crossUnder (vars Data, var border) : bool

Determines if the data1 series crosses over or under the data2 series, or over or under a fixed border value. Often used for trade signals.

Parameters:

Data1 First data series.
Data2 Second data series.
border border value.

Returns:

true if the first series crosses the second, false otherwise.

Modifies

rMomentum - Data movement in percent per time frame at the time of the crossing; indicates the 'speed' of the crossover.

Algorithms:

bool crossOver(var* data1,var* data2) { return (data1[0] > data2[0]) && (data1[1] < data2[1]); }
bool crossUnder(var* data1,var* data2) { return (data1[0] < data2[0]) && (data1[1] > data2[1]); }
bool crossOver(var* data,var border) { return (data[0] > border) && (data[1] < border); }
bool crossUnder(var* data,var border) { return (data[0] < border) && (data[1] > border); }

Remarks:

Example:

function run()
{
  vars Price = series(priceClose());
  vars SMA100 = series(SMA(Price,100));
  vars SMA30 = series(SMA(Price,30));

  if(crossOver(SMA30,SMA100))
    enterLong();
  else if(crossUnder(SMA30,SMA100))
    enterShort();
}

See also:

series, rising/falling, peak/valley, crossOverF/UnderF, predict

► latest version online