Trend Indicator

by daemon in category Trend at 30/08/2012
Description

Based on Instantaneous Trend from  John Ehlers book "Cybernetic Analysis for Stocks and Futures".

 

Download
2548 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    [Levels(0.0)]
    public class TrendIndicator : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 0.07)]
        public double Alpha { get; set; }

        [Output("Main", Color = Colors.Red)]
        public IndicatorDataSeries Result { get; set; }

        [Output("Lag", Color = Colors.Turquoise)]
        public IndicatorDataSeries Lag { get; set; }

        public override void Calculate(int index)
        {
            if (index < 3)
                Result[index] = Source[index];
            else
            {
                if (index < 7)
                    Result[index] = (Source[index] - 2*Source[index - 1] + Source[index - 2])/4;
                else
                    Result[index] = (Alpha - Alpha*Alpha/4)*Source[index]
                                    + Alpha*Alpha*Source[index - 1]/2
                                    - (Alpha - 0.75*Alpha*Alpha)*Source[index - 2]
                                    + 2*(1 - Alpha)*Result[index - 1]
                                    - (1 - Alpha)*(1 - Alpha)*Result[index - 2];

                Lag[index] = 2*Result[index] - Result[index - 2];
            }
        }
    }
}
Comments

Michael Ogbonnaya - September 15, 2012 @ 13:13

This seems like a promising trend indicator. I am gonna give it a try.

davidp13 - May 24, 2015 @ 14:39

Hi. How would one reference this indicator in a robot?

Lebenskünstler - July 22, 2015 @ 21:59

Hi davip13

To use this indicator in your bot just ad the following code.
Please also add a reference to the indicator clicking on "Manage References" next to "Save" and "Build".
-----

private TrendIndicator trnd;

protected override void OnStart()
{
    trnd = Indicators.GetIndicator<TrendIndicator>(MarketSeries.Close, 0.07);
}

protected override void OnTick()
{
    Print("Result " + trnd.Result.Last(0));
    Print("Lag " + trnd.Lag.Last(0));
}

FireMyst - March 28, 2019 @ 08:05

the colors on your screen capture aren't clear which is the "main" and which is the "lag". How is the output meant to be interpreted? When the "main" crosses above the "lag", the trend is buying; when the "main" crosses below the "lag", the trend is selling?

5