TASC December 2020 - Ehler's NET

I coded up the NET version of Ehler's RSI from the latest TASC magazine. screenshot matches the pictures from the article as far as I can tell. Feedback is welcome. That Y variable is entirely unused, but I left it there because it was in all the examples.

NET

// TASC December 2020 Noise Elimination Technology by John F. Ehlers
// afl coding by J Talikka
// based partially on code by Tomasz at http://www.amibroker.com/members/traders/05-2018.html

RSILength = Param( "RSILength", 14, 2, 50 );
NETLength = Param( "NETLength", 14, 2, 50 );


function EhlersRSI( Data, Period )
{
    Diff = Data - Ref( Data, -1 );

    Up = Max( Diff, 0 );
    Dn = Max( -Diff, 0 );

    CU = Sum( Up, RSILength );
    CD = Sum( Dn, RSILength );

    result = IIf( CU + CD != 0, ( CU - CD ) / ( CU + CD ), 0 );

    return result;
}

function NET( Data, Period )
{
    for( count = 1; count < Period + 1; count++ )
    {
        VarSet( "X" + count, Ref( Data, 1 - count ) );
        VarSet( "Y" + count, -count );
    }

    Num = 0;

    for( count = 2; count < Period + 1; count++ )
    {
        for( K = 1; K < count; K++ )
        {
            Num = Num - sign( VarGet( "X" + count ) - VarGet( "X" + K ) );
        }
    }

    Denom = 0.5 * Period * ( Period - 1 );

    result = Num / Denom;

    return result;
}


Plot( EhlersRSI( C, RSILength ), "EhlersRSI" + _PARAM_VALUES(), colorRed, styleThick );
Plot( 0, "", colorBlack, styleLine );
Plot( NET( EhlersRSI( C, RSILength ), NETLength ), "NET" + _PARAM_VALUES(), colorBlue, styleThick );

7 Likes

It is highly unlikely that CU + CD becomes zero.

@Tomasz has written just this too
MyRSI = ( CU - CD ) / ( CU + CD );

Still if you feel better you might use function SafeDivide.


This function can be simplified as it does not need two loops and dynamic variables.

So simplified to

function NET( Data, Period )
{
    /// AFL translation from EL
    /// http://traders.com/Documentation/FEEDbk_docs/2020/12/TradersTips.html#item1
    Num = 0;
    for( n = 1; n < Period; n++ ) 
    {
        arr1 = Ref(Data,-n);
        for( k = 0; k < n; k++ )
            Num += sign(Ref(Data,-k)-arr1);
    }
    Denom = 0.5 * Period * (Period - 1);
    result = Num / Denom;
    return result;
}

Whole one

// TASC December 2020 Noise Elimination Technology by John F. Ehlers
// afl coding by Tomasz Janeczko & J Talikka & fxshrat
// https://forum.amibroker.com/t/tasc-december-2020-ehlers-net/22501

RSILength = Param( "RSILength", 14, 2, 50 );
NETLength = Param( "RSILength", 14, 2, 50 );

function EhlersRSI( Data, Period )
{
    /// By Tomasz Janeczko
    /// @link http://www.amibroker.com/members/traders/05-2018.html
    Diff = Data - Ref( Data, -1 );

    Up = Max( Diff, 0 );
    Dn = Max( -Diff, 0 );

    CU = Sum( Up, RSILength );
    CD = Sum( Dn, RSILength );

    result = (CU - CD) / (CU + CD);
    //result = SafeDivide(CU-CD,CU+CD);
    return result;
}

function NET( Data, Period )
{
    /// AFL translation from EL
    /// http://traders.com/Documentation/FEEDbk_docs/2020/12/TradersTips.html#item1
    Num = 0;
    for( n = 1; n < Period; n++ ) 
    {
        arr1 = Ref(Data,-n);
        for( k = 0; k < n; k++ )
            Num += sign(Ref(Data,-k)-arr1);
    }
    Denom = 0.5 * Period * (Period - 1);
    result = Num / Denom;
    return result;
}


Plot( EhlersRSI( C, RSILength ), "EhlersRSI" + _PARAM_VALUES(), colorRed, styleThick );
Plot( 0, "", colorBlack, styleLine );
Plot( NET( EhlersRSI( C, RSILength ), NETLength ), "NET" + _PARAM_VALUES(), colorBlue, styleThick );
10 Likes

That's brilliant fxshrat, I like the simplification and removal of the Varset/Varget thing I was doing, and it's always nice to learn of a new function like SafeDivide (which doesn't seem to appear in my afl language reference?).

I noticed you copied the code before I edited a couple of errors:
2nd line NETLength I copied and pasted from RSILength, and so the description was the same and the parameter un-adjustable, so I've fixed that in the code above.
I've also changed the labels for the lines a touch as the _PARAM_VALUES() didin't really make sense.

4 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.