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

TS LinearRegSlope error - solved



PureBytes Links

Trading Reference Links

OK, I have figured out that my problem isn't with LinearRegSlope,
because the version M. Simms sent me does the same thing.  The
problem is in my Signal.

Recall these were the calculations:

AD=100*(adv-dec)/(adv+dec+unc);
mm1 = LinearRegSlope(AD, 6);
mm2 = LinearRegSlope(mm1, 4);

Here are results from printing values in my signal and inside
LinearRegSlope.  Let's start on 6/28/2000.  Notice the value of AD
on bar 659.  AD=19.55.  This is the correct value calculated from
the adv/dec/unc inputs.

 date=1000628  CurrentBar=659  MaxBarsBack=50  AD=19.55  mm1=4.73  mm2=2.78
    bar =    659    AD =     19.55
    bar =    658    AD =     10.70
    bar =    657    AD =      4.45
    bar =    656    AD =    -12.52
    bar =    655    AD =    -24.74
    bar =    654    AD =    -11.14

All right.  So far so good.  All the AD values are correct.
Now let's look what happens on the next bar.  Notice what happens to AD
on bar 659.  It changes value!

 date=1000629  CurrentBar=660  MaxBarsBack=50  AD=-0.57  mm1=7.91  mm2=3.60
    bar =    660    AD =     -0.57
    bar =    659    AD =    658.00
    bar =    658    AD =     10.70
    bar =    657    AD =      4.45
    bar =    656    AD =    -12.52
    bar =    655    AD =    -24.74

And it retains that value until bar 659 rolls off the lookback
range for LinearRegSlope.  It looks like AD somehow got assigned
the previous bar number.  Naturally during this time, mm1 will be
trashed.  I checked over my code carefully.  Sure enough, I had a
line hidden deep in an 'if' statement that would get executed on
rare occasions, that accidentally used AD as a temporary variable,
and the result of that calculation was by pure coincidence similar
to the previous bar number.

Damn, damn.  Sorry to bother everyone.  Thank you for the help,
anyway!

-Alex