[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tough coding problem



PureBytes Links

Trading Reference Links

Tom

Tough indeed. Having worked away at this idea with a bunch of If() functions
I've got to the point where I think the solution proposed by Equis is not
workable as stated even for an expert. A problem arises where there are two
or more highest highs in the last x number of bars. The Equis solution
assumes just one bar with the highest period high. Once there are two bars
with that high sooner or later the older high will be interpreted as the
second highest high, whereas in fact it is an earlier occurrence of the
highest high.

For what it's worth here is as far as I have got with this. It's not
elegant, and it's not strictly accurate for the above stated reason.   'y'
is the value of the perceived second highest high, and 'z' is the associated
binary.

Roy

x:=HHVBars(H,20);
a:=If(x=0,Ref(HHV(H,19),-1),
If(x=1,Max(Ref(HHV(H,18),-2),H),
If(x=2,Max(Ref(HHV(H,17),-3),HHV(H,2)),
If(x=3,Max(Ref(HHV(H,16),-4),HHV(H,3)),
If(x=4,Max(Ref(HHV(H,15),-5),HHV(H,4)),0)))));
b:=If(x=5,Max(Ref(HHV(H,14),-6),HHV(H,5)),
If(x=6,Max(Ref(HHV(H,13),-7),HHV(H,6)),
If(x=7,Max(Ref(HHV(H,12),-8),HHV(H,7)),
If(x=8,Max(Ref(HHV(H,11),-9),HHV(H,8)),
If(x=9,Max(Ref(HHV(H,10),-10),HHV(H,9)),0)))));
f:=If(x=10,Max(Ref(HHV(H,9),-11),HHV(H,10)),
If(x=11,Max(Ref(HHV(H,8),-12),HHV(H,11)),
If(x=12,Max(Ref(HHV(H,7),-13),HHV(H,12)),
If(x=13,Max(Ref(HHV(H,6),-14),HHV(H,13)),
If(x=14,Max(Ref(HHV(H,5),-15),HHV(H,14)),0)))));
g:=If(x=15,Max(Ref(HHV(H,4),-16),HHV(H,15)),
If(x=16,Max(Ref(HHV(H,3),-17),HHV(H,16)),
If(x=17,Max(Ref(HHV(H,2),-18),HHV(H,17)),
If(x=18,Max(Ref(H,-19),HHV(H,18)),
If(x=19,HHV(H,19),0)))));
y:=Max(Max(a,b),Max(f,g));
z:=y=H OR y=Ref(H,-1) OR y=Ref(H,-2); y; z;



I am working on a tough coding problem.  Here is what I am trying to do.

Either the day before yesterday, today, or today, the High must be the
"second-highest high" of the past 20 days.
I can not figure out how to find out if the the "second-highest high of the
last 20 days" has occured within the last 3 days.  I can easily find the
highest high but not the second highest high.

Equis support gave a solution which allows me to do the above only in an
expert or exploration, but not in the system tester. Basically the solution
is

"You can use the HHVBars() function to find out how many bars ago the
highest value was.  Buy putting that function inside the LastValue()
function, this number becomes a constant which you can then use inside other
functions.  From there, you can Ref() back to that point and find the
highest value before that one and the highest value since.  This will give
you the second highest value during the 20 bar period.  Then you can compare
it to the most recent three bars to see if it matches one of them."

" this technique will not work with historical values on an expert, though
it could be used to give you alerts on new data.  The reason it is limited
this way is because of the LastValue() function.  This always refers looks
at the last bar loaded and returns the value whatever is being referenced
has on that bar.  Therefore,  in the example I used below, LastValue will
return the number of bars since the 20 day high was made, as calculated on
the last bar of data loaded.  This value is the only number ever used,
regardless of the bar the formula is being calculated on."

Anyone have any other clever ideas on doing this?

Thanks

Tom