Your implementation of crossOver/Under is also naive. In the following example, the Blue line has clearly crossed over the Red line at bar 67, where Blue=2 and Red=1. But crossOver(Blue, Red) is consistently zero throughout.
Code:
function run() {
  set(PLOTNOW);
  MaxBars = 250;
  asset("");
  PlotHeight1 = 0;
  PlotHeight2 = 256;

  vars Red = series(2 - (int)(genSine(120, 120) * 3));
  plot("Red", Red, LINE+NEW, RED);
  vars Blue = series((int)(genSine(120, 120) * 3))+3;
  plot("Blue", Blue, LINE, BLUE);

  plot("Cross", crossOver(Blue, Red), LINE+NEW, RED);  // always 0.
  printf("\n%d %f %f", Bar, Red[0], Blue[0]);
}


Remove the (int) conversions in Red and Blue's definition, making the crossovers is instant, 1 bar wide, and crossOver works correctly.

See attachments.

Attached Files
crossover_edge_case.png (103 downloads)
Last edited by GPEngine; 08/13/14 03:38.