Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
Eroco, Code:C>Valuewhen(1,H>Ref(HHV(H,2),-1) AND H>Ref(HHV(H,2),+2),H);
Let us pretend today is Wednesday. Your code is looking for the condition when Wednesday's CLOSE is greater than the expression in the ValueWhen() function. Let's also assume this expression is TRUE today, Wednesday. How can the expression in the ValueWhen() be evaluated as being TRUE today when it makes reference to the HHV(H,2) in two days time, that's Friday but today is only Wednesday? The only way the expression can be evaluated on Wednesday is for Friday's information to be known, that is, on or after Friday, at which time the entry signal is placed on Wednesday's bar. If you have a broker that will allow you to buy stocks on Friday at Wednesday's prices, knowledgable of the price movement then please give their number to me! Your code will be giving you a signal today that you should have entered the trade two bars ago! Is this much use in real life? You have to be very careful writing codes that use foresight or know the final result before it is possible for the final result to be known, or code that uses hindsight to add/remove indicators in the past. If you put your code into an exporation, you will notice that MS returns only N/A preventing any signals from being generated, and see on a chart there are no returns from the indicator on the last two bars of the chart; this is the effect of the forward referencing. MS will still show the signals generated before, but these cannot be traded in real life, the system tester thinks they can! Rethink your algorithm from the perspective of Friday's bar, only looking backwards into the known history and I am sure you will find you have completely different results. Once you have your algorithm, run it in an exploration and see how many results it gives on the last bar. If the exploration rejects 100% there is probably something still wrong with the code. Hope this helps. wabbit [:D] P.S. On a slightly different note; you should be careful about how MS counts bars. HHV(H,2) will compute the highest value on the most recent bar and the one before it, a total of two bars, whereas, Ref(H,-2) will return the value 2 bars displaced in history, that is not the most current bar, not the bar before the current bar, but the bar before that, so MS actually 'looks' at three bars. This can cause some confusion when trying to align, for example, HHV() and Ref() functions.
|