User error, was: Cross Function Problem?

Hey Guys,
I want to use the cross function to indicate when a security crosses below an MA. However, I am getting a true result when the close equals the MA without crossing below. For example, on 1/27/21 the close for the symbol NM (on the NYSE) equals it's 10MA but the cross function indicates a cross below. Is this how the cross function is suppose to operate?

@Apoc, welcome to this forum.

As a general rule, it is a lot better to post the lines of code you wrote to show us the problem.

Your description is not enough to truly understand why you see that result.
In any case, I suggest rereading the documentation of the cross function.

To find out when ARRAY1 crosses below ARRAY2, use the formula cross(ARRAY2, ARRAY1)

Is this what you have done in your formula (note that the array order is reversed vs. the cross "above)?

2 Likes
CrossBelowMA10 = Cross( MA( C, 10 ), C );

This code gives a true result for NM on 1/27/21. It is my understanding it should give a true result on 1/28/21.

See,

1 Like

@Apoc, I suppose your doubt is related to the fact that on that specific date, the MA( C, 10 ) value and the Close are equal (i.e., $ 3.6100) for symbol NM - NYSE - Navios Maritime Holdings Inc.

image

Why do you think there is a problem?

@beppe I think the "problem" is that the Cross function specifically says that Array1 must be a cross below Array2, not equal to Array2.
@Apoc I don't know if my data source is different or if there is problem created by looking for too many significant digits, but if you expand your exploration you may find the cross below.
image

2 Likes

No it doesn't. Moving average is NOT equal to close. You are misguided in your assumptions because you are looking at ROUNDED numbers (to 2 decimals), while computer actually uses full available accuracy (see previous post for actual numbers)

And really? How did you come to assumption that there is a "problem" in function that has been used zillions of times during last 25 years?

2 Likes

@portfoliobuilder you are right!
Indeed no signal happens (nor above, nor below) if the Array1 and Array2 are exactly at the same level (to test it, I modified them via code, changing a specific bar value).

image

As usual, the documentation is very accurate. I wrongly supposed that in the case of equality there was a rule >= or <= . My fault!

1 Like

You guys need to understand that it is highly unlikely that moving average is ever EQUAL to close (with exception when it is calculated from one and only one price point or from row of exactly same prices).
Actually the chance that two random floating point numbers are equal is 2^-32 =
0.000000000232831

4 Likes

Thank you @portfoliobuilder! It was a rounding issue. I should have caught this before I wasted everyone's time.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.