On Sunday, 13 September 2020 at 07:00:36 UTC, mw wrote:

Here it is: D wrapper for https://ta-lib.org/

https://github.com/mingwugmail/talibd

I end up using C macro to generate D functions, the single template is this one:

https://github.com/mingwugmail/talibd/blob/master/source/talibd.h#L117
#define DECL_TA_FUNC(TA_FUNC, FUNC_INS, FUNC_OUTS, expected_lookback) __NL__\

The most straightforward way to do this in D is with a mixin template. Something like:

mixin template DECL_TA_FUNC(string TA_FUNC, FUNC_INS, FUNC_OUTS, int expected_lookback)
{
    bool impl(...)
    {
        // ...
    }

    // Could also wrap the whole function in a string mixin,
    // but this is easier.
    mixin("alias ", TA_FUNC, " = impl;");
}

Which you would then use like this:

mixin DECL_TA_FUNC!(
    "TA_MA",
    Tuple!(int, "MA_optInTimePeriod", TA_MAType, "opInMAType"),
    Tuple!(double[], "outMA"),
    MA_optInTimePeriod - 1
);

Reply via email to