Menu

#84 MACD Lookback function off for signal values of one

open
Bug (61)
5
2020-11-19
2008-08-28
Luis Garcia
No

the lookback function seems to return a wrong number when the signal variable is set to 1. It always returns a lower number that what it should (off by one unit) so if you want to replicate the error do this:

int lookback = ti_lib.macdLookback(2, 7, 1);

and you will see the problem. The lookback numer will be 5 instead of 6. Now, do this:

int lookback = ti_lib.macdLookback(2, 7, 2);

and you will get the exact number in the lookback (7).

I use genetic algorithms in my strategies and the GA is the one that sets the values of the different variables. And yes, they look funky like those sometimes; but the results work, and work very well... except for this.

Discussion

  • Mario Fortier

    Mario Fortier - 2008-08-29

    Logged In: YES
    user_id=1123
    Originator: NO

    Thanks Luis for reporting this bug.

    TA_MACD uses TA_EMA. The MACD optInSignalPeriod is also used internally as a parameter to TA_EMA.

    The MACD optInSignalPeriod parameter range allows the value 1, but the TA_EMA minimum value allowed is 2. The internal call to TA_EMALookback fails (returning -1). That explains the problem you observe.

    To fix the bug I need to either:
    (1) Make TA_EMA allow a parameter of value 1 (that would mean no smoothing done).
    OR
    (2) Change the range of optInSignalPeriod to start at 2.

    I think (1) offer the most flexibility, as it allows to disable a smoothing in a larger algo.

    Do you have a preference of one solution over the other?

    Thanks,

    \Mario

     
  • Luis Garcia

    Luis Garcia - 2008-08-30

    Logged In: YES
    user_id=1474155
    Originator: YES

    Hi Mario,
    Yeah, I saw the code after I reported the bug and figured it out. I really don't have a preference. What I did was to restrict my engine to 2 and problem solved, or patched. Someone else may have a different preference and want a faster signal... unlikely though, so 2 I think is sufficient.

     
  • Alexander Trufanov

    Just for the reference. There is a discussion abut this problem here. In the end I've decided to change the check from optInTimePeriod < 2 to optInTimePeriod < 1 for following indicators: SMA, EMA, WMA, DEMA, TEMA, TRIMA, KAMA, T3. Bcs the problem affects MACDEXT function too that can call any of MA indicators. And also added checks for LOOKBACK_CALL(MA or EMA) return value in MACD and STOCH indicators.

     

Log in to post a comment.