I just discovered something I don't quite understand. Based on the definition of the cross function, I would assume these two lines of code would mean the same thing, but I get slightly different results by toggling between these and I'm not sure why.
Buy = Cross(High, Ref(High, -1))
Buy = (High > Ref(High, -1))
I get that Cross is useful for things like moving averages where you'll have one higher than another except the instant they cross over and you want to capture that instant because just the logical version of this will give you a true statement the entire time it is greater, which you don't want.
But if you are just checking one bar and whether the current bar has a high greater than the bar before it, shouldn't both these yield the same result?
Yes, if the cross occurs (and is after a reset) on the bar you are checking both will be true.
State vs Impulse.
@millerrh an additional example to help expand upon @TrendSurfer 's answer. The
Cross function is only true if the array (the High in your example) crosses from being a lower high to a higher high.
See this color coded exploration and the only places an Impulse signal takes place is after lower High's had occurred (lower High's are colored red in this Exploration).
For more clarity just search this forum as there are several examples and discussions of State signals vs Impulse (or Pulse) signals.
Thanks @TrendSurfer & @portfoliobuilder I'll look more into State vs. Impulse. I was searching for the wrong terms to try to get to the bottom of this.
In the meantime, my takeaway is that if you are just looking for whether a current high is higher than the previous one, it is safer to use the Logical argument and not the Cross function. The cross depends on it coming from a lower high state which might not be reality. But if the new high is greater than the previous high logically, it will capture all those.
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.