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

Fw: PivotHighVS Bugs. Was (Re: Long term SAR system)



PureBytes Links

Trading Reference Links

Someone sent me this if anyone cares. -David



> Replying to your message of Tuesday, April 15, 2003, 6:17:48 PM,
> 
> David,
> I was looking at the system you posted and the PivotHighVS function
> that you sent me.  I am pretty certain there is a bug in the
> PivotHighVS code.  Specifically, the code:
> If Pivot[0] <> 0 Then Begin
>         For Count = 1 To 50 Begin
>                 Pivot[Count] = 0;
>         End;
> End;
> Should actually be:
> If Pivot[1] <> 0 Then Begin         {only change is array index value}
>         For Count = 1 To 50 Begin
>                 Pivot[Count] = 0;
>         End;
> End;
> 
> The way the code was originally implemented, there is never an
> assignment to Pivot[0], so Pivot is never reinitialized.  As a result,
> towards the end of the code, when Pivot[Occur] is referenced, an old
> value may be accessed and returned as the function value.
> 
> I THINK this would only be a problem if you reference an Occur greater
> than the number of pivots within the current interval of size length.
> That is, if there was ever an occurrence of a pivot high, the value of
> that occurrence would be preserved in Pivot[1].  The next call to the
> function that finds a pivot high would shift the old Pivot[1] into
> Pivot[2].  If a subsequent call to the function is looking for an
> Occur = 2, and the current interval of length bars has only a single
> pivot the code would return the old value.
> 
> I imagine PivotLowVS has the same problem but I haven't looked at the
> code to verify it.
> 
> I did test my change to the code and it appears to work fine.
> 
> Since you were kind enough to send me the code I was missing, and to
> post your SAR system on the O-list, I wanted to let you know what I
> found.  If you want to repost this email to the O-list, feel free.
> 
> Paul
> P.S. If you use back-adjusted contracts, it is possible to have
> negative prices.  A pivot high could actually be 0.  I.e., my fix only
> fixes part of the problem with this code.  It would be safer to
> initialize Pivot to a large negative number, rather than using 0 to
> represent "undefined." And reinitialize Pivot on every call of the
> function.
>