Category Oscilators  Published on 03/04/2023

Signalysis

Description

An common way to analyze a signal (indicator line), is to check whether it is rising, falling.

Some other ways:

  • Stochastic: (Cur - Min) / (Max - Min) over a period. If it is 1, then the Curent Value (Cur) is the max of that period. If it is > 0, then there is a bias toward high side.
  • Rsi (Relative Strength Index): CU/(CU + CD), CU: Close Up, CD: Close Down, calculated over a period. If it is 1, then we have all rising for that period. If it is > 0, the rise is more than the fall.
  • Rvi (Relative Vigor Index): (C - O)/(H - L), C: Close, O: Open, H: High, L: Low, calculated over a period. If it is 1, then it is an extreme bias to the high. If it is > 0, there is a bias toward the high side.
  • Mometum: Cur - Prev(i), where i is the period. Momentum > 0 indicates a bias toward the high side.

In this Signalysis indicator, I combined all 4 above types of analysis, plus some other things.

It can performs analysis on any source, not only price. For example, if you apply Signalysis on the RSI and check the Sto, you will get the famous StochasticRSI indicator.

SourceType:

  • HL2: (High + Low) / 2
  • HLC3: (High + Low + Close) / 3
  • Close
  • Custom: selectable source.

CustomSource: the source to be used if SourceType is Custom.

Transform: 

  • None: no transform.
  • IFish: Inverse Fisher transform (see Ehlers book).
  • Fish: Fisher transform (see Ehlers book).

SmoothFactor: factor to be used for selected SmoothType. For example, if SmoothType is WMA, SmoothFactor == 3 means WMA for 3 periods.

SmoothType: WMA, EMA, SMA, TwoPoles, ThreePoles, Lague, None.

  • WMA, EMA, SMA: Conventions Weighted/Exponetial/Simple Moving Average.
  • TwoPoles, ThreePoles: Ehlers 2, 3 Poles smoother (see Ehlers book). SmoothFactor will be the CutOff period, e.g. if CutOff == 10, those with frequency equivalent to < 10 bars will be depressed.
  • Lague: Laguerre filter (see Ehlers book). SmoothFactor is the Gamma for Laguerre filter [0 - 0.99].

Period: The period used for calculation (if Adaptive is False).

Adaptive: If yes, then the Period is auto calculated using Hilbert Transform (mentioned in Ehlers book).

 

Bonus: with the following setting, you will get the Ehlers Smoothed Adaptive Momentum (SAM) indicator:

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using LittleTrader;
using LittleTrader.Ehlers;
using LittleTrader.Extensions;
using MoreLinq;

namespace cAlgo
{
    [Levels(-0.5, 0, 0.5)]
    [Indicator(AccessRights = AccessRights.None)]
    public class LT_Ind_Signalysis : Indicator
    {
        [Parameter(DefaultValue = SourceTypes.Close)]
        public SourceTypes SourceType { get; set; }

        [Parameter()]
        public DataSeries CustomSource { get; set; }

        [Parameter(DefaultValue = Transforms.None)]
        public Transforms Transform { get; set; }

        [Parameter(DefaultValue = SmoothTypes.SMA)]
        public SmoothTypes SmoothType { get; set; }

        [Parameter(DefaultValue = 3)]
        public double SmoothFactor { get; set; }

        [Parameter(DefaultValue = 3)]
        public double IFishAmp { get; set; }

        [Parameter(DefaultValue = 8)]
        public int Period { get; set; }

        [Parameter(DefaultValue = false)]
        public bool Adaptive { get; set; }

        [Output("Rsi", LineColor = "Red")]
        public IndicatorDataSeries Rsi { get; set; }

        [Output("Rvi", LineColor = "Blue")]
        public IndicatorDataSeries Rvi { get; set; }

        [Output("Sto", LineColor = "Purple")]
        public IndicatorDataSeries Sto { get; set; }

        [Output("Momentum", LineColor = "Green")]
        public IndicatorDataSeries Momentum { get; set; }

        EhlersCombineFilter _ehlersCombine;
        protected override void Initialize()
        {
            var u = new IndUtils()
            {
                Bars = Bars,
                CreateSeriesFunc = CreateDataSeries,
                SourceType = SourceType,
                CustomSource = CustomSource
            };
            List<ILTSeries> list = new List<ILTSeries>()
            {
                new LTRsi() { IndSeries = Rsi, Period = Period, SmoothType = SmoothType, SmoothFactor = SmoothFactor },
                new LTRvi() { IndSeries = Rvi, Period = Period, SmoothType = SmoothType, SmoothFactor = SmoothFactor },
                new LTStochastic() { IndSeries = Sto, Period = Period, SmoothType = SmoothType, SmoothFactor = SmoothFactor },
                new LTMomentum() { IndSeries = Momentum, Period = Period, SmoothType = SmoothType, SmoothFactor = SmoothFactor },
            };

            if (Transform == Transforms.Fish)
            {
                list.OfType<LTSeries>().ForEach(x => { x.Fish = x.IndSeries; x.IndSeries = null; });
            }
            else if (Transform == Transforms.IFish)
            {
                list.OfType<LTSeries>().ForEach(x => { x.IFish = x.IndSeries; x.IndSeries = null; x.IFishAmp = IFishAmp; });
            }

            if (Adaptive)
            {
                list.OfType<LTSeries>().ForEach(x => x.Adaptive = true);
                list.Add(new LTCycleMeas() { IndSeries = CreateDataSeries(), Alpha = 0.07 });
            }

            _ehlersCombine = new EhlersCombineFilter(list, u);

        }

        public override void Calculate(int index)
        {
            if (index < Period) return;
            try
            {
                _ehlersCombine.Calculate(index);
            }
            catch (Exception ex)
            {
                Print(ex.ToString());
                throw;
            }
        }

    }
}

dhnhuy's avatar
dhnhuy

Joined on 03.04.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: LT_Ind_Signalysis.algo
  • Rating: 0
  • Installs: 496
Comments
Log in to add a comment.
No comments found.