PureBytes Links
Trading Reference Links
|
At 11:29 AM -0400 5/2/99, Philippe wrote:
>For me, the MRO function doesn't seem to me to be the right one to do this.
>If the MRO function returns 22, it means that C[22] > C[23] is true but it
>can be false for C[21] > C[22],.....etc..
>
>Am I right ?
It works. The code:
if MRO(C <= C[1], 30, 1) > Length then ...
finds the "Most Recent Occurrence" of the OPPOSITE condition, when C <=
C[1], so if it reports a value greater than the number of bars you are
looking for, there were no cases of C <= C[1] within the specified number
of bars.
Pierre's solution is much faster in terms of run time since the MRO
function uses a loop, as did Gary's original solution, but Pierre's takes a
little more code.
My solution takes less code but is slower to run since it uses a more
complex internal function.
Gary's improvement on my version saves some search time by searching only
back to the target bar and using the "not found" return value of -1 from
the MRO function.
We all had slightly different interpretations of the length of the search
as illustrated below.
To test these I created a ShowMe for each:
My original solution:
Input: Length(3);
if MRO(C <= C[1], 30, 1) > Length then Plot1(High,"1";
Pierre's (slightly simplified by Gary):
Input: N(4);
Vars: Idx(0);
if c > c[1] then idx = idx + 1;
if idx - inx[N] = N then Plot1(Low,"1");
And mine (simplified by Gary):
Input: Length2(5);
if MRO(C <= C[1], Length2 - 1, 1) < 0 then Plot1(MedianPrice,"1";
All gave the same results if N = Length + 1 = Length2 = 2 (So we need to
make sure we use the correct value for what was required.)
This is a good illustration of the tradeoffs between code size, execution
speed, and code clarity that is very typical in all programming.
It also illustrates the need to check for the end conditions carefully
since we all had different interpretations of the length. This is also a
common error in programming.
Bob Fulks
|