After Effects: Detect if Lines are Intersecting
The fifth null doesn't wander randomly, it just extends the red and blue lines off beyond their ends. You need to detect whether the intersection point is on the segment between the start and end nulls for each line.

You can test for it with this rather horrifying conditional: basically it tests to see if the intersection is outside the bounds of each point's x then y coordinates. 

Replace the last line of your expression with this:

if ((x &gt; p1[0] &amp;&amp; x &gt; p2[0])||(x &gt; p3[0] &amp;&amp; x &gt; p4[0])||(x &lt; p1[0] &amp;&amp; x &lt; p2[0])||(x &lt; p3[0] &amp;&amp; x &lt; p4[0])||(y &gt; p1[1] &amp;&amp; y &gt; p2[1])||(y &gt; p3[1] &amp;&amp; y &gt; p4[1])||(y &lt; p1[1] &amp;&amp; y &lt; p2[1])||(y &lt; p3[1] &amp;&amp; y &lt; p4[1])){
    value
}else{
    [x,y]
}


Another version, does the same thing but with nice readable code, and a re-useable function:

function outsideBounds(samplePt, p1, p2){
  if (samplePt[0] &gt; Math.max(p1[0], p2[0])) {return true}
  if (samplePt[1] &gt; Math.max(p1[1], p2[1])) {return true}
  if (samplePt[0] &lt; Math.min(p1[0], p2[0])) {return true}
  if (samplePt[1] &lt; Math.min(p1[1], p2[1])) {return true}
  return false 
} 

if (outsideBounds([x,y], p1, p2)||outsideBounds([x,y], p3, p4)){
    value
}else{
    [x,y]
}