NexusFi: Find Your Edge


Home Menu

 





FLD (Hurst) For Ninjatrader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Robx with 3 posts (2 thanks)
    2. looks_two elopezh with 2 posts (6 thanks)
    3. looks_3 Skid with 1 posts (2 thanks)
    4. looks_4 agrock with 1 posts (1 thanks)
      Best Posters
    1. looks_one elopezh with 3 thanks per post
    2. looks_two Skid with 2 thanks per post
    3. looks_3 lolu with 1 thanks per post
    4. looks_4 Robx with 0.7 thanks per post
    1. trending_up 5,055 views
    2. thumb_up 12 thanks given
    3. group 8 followers
    1. forum 8 posts
    2. attach_file 9 attachments




 
Search this Thread

FLD (Hurst) For Ninjatrader

  #1 (permalink)
 Robx 
Madrid + SPAIN
 
Experience: Advanced
Platform: NinjaTrader,AmiBroker,TOS
Trading: Commodities Futures, Options, Stocks
Posts: 19 since Apr 2014
Thanks Given: 18
Thanks Received: 6

Hi,
I´m looking for the FLD (Future Line of Demarcation) Indicator used in Hurst strategies.
It´s a kind of Displaced forward Moving Average of the cycle, usually for 20 periods. I can´t locate in NinjaTrader Indicators
Some Help, please?

Thx,

Follow me on Twitter Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
REcommedations for programming help
Sierra Chart
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
 
  #2 (permalink)
 
Skid's Avatar
 Skid 
Hammond LA
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninja Trader
Trading: NQ, ES and SPY options
Posts: 202 since Aug 2009
Thanks Given: 536
Thanks Received: 316

There are two indicators and some programming in this thread.



If you do what you love, you'll never work a day in your life. Allow your passion to become your purpose.
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
 Robx 
Madrid + SPAIN
 
Experience: Advanced
Platform: NinjaTrader,AmiBroker,TOS
Trading: Commodities Futures, Options, Stocks
Posts: 19 since Apr 2014
Thanks Given: 18
Thanks Received: 6


Hi,
Yes but are for NT7. There are a couple of indicators based on Hurst cycles with FLD for AMIBroker very interesting, so i´m looking something similar for NT8.
Thanks

Follow me on Twitter Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 elopezh 
Oviedo Asturias/Espańa
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL
Posts: 5 since Dec 2018
Thanks Given: 1
Thanks Received: 9


Robx View Post
Hi,
Yes but are for NT7. There are a couple of indicators based on Hurst cycles with FLD for AMIBroker very interesting, so i´m looking something similar for NT8.
Thanks

Hello,
ATTACHED FILES FOR THE nt8 VERSION

jhlHurstExponent.cs

jhlFractalDimension.cs

jhlMAX.cs

jhlMIN.cs

jhl.Utility.cs

Reply With Quote
Thanked by:
  #5 (permalink)
 
lolu's Avatar
 lolu 
Lagos, Nigeria
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader, SierraChart
Trading: Euro Currency & Oil
Frequency: Daily
Duration: Hours
Posts: 2,552 since Jun 2009
Thanks Given: 1,049
Thanks Received: 1,678



jhl.Utility.cs threw up the attached compilation errors on my NT8 8.0.20.1 64-bit. I've not compiled the other .cs files. Are these indicators for NT8 ?

Lolu


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 elopezh 
Oviedo Asturias/Espańa
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL
Posts: 5 since Dec 2018
Thanks Given: 1
Thanks Received: 9


lolu View Post
jhl.Utility.cs threw up the attached compilation errors on my NT8 8.0.20.1 64-bit. I've not compiled the other .cs files. Are these indicators for NT8 ?

Lolu


Good morning Lolu,
I'm sorry for the mistake. They're actually for version 7;

Reply With Quote
Thanked by:
  #7 (permalink)
 Robx 
Madrid + SPAIN
 
Experience: Advanced
Platform: NinjaTrader,AmiBroker,TOS
Trading: Commodities Futures, Options, Stocks
Posts: 19 since Apr 2014
Thanks Given: 18
Thanks Received: 6

Yeah, they were NT7. If someone find them for NT8 we appreciate it.
Best,

Follow me on Twitter Started this thread Reply With Quote
  #8 (permalink)
agrock
Medellín
 
Posts: 1 since May 2017
Thanks Given: 0
Thanks Received: 1

Hi,

Here is a version for NT8. I put together all classes (FractalDimension, MINN, MAXX) in a single file for ease of use. The indicator has been tested and it seems to be OK.

 
Code
#region Using declarations

using System;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using NinjaTrader.Gui;

#endregion

// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
    public class HurstCoefficient : Indicator
    {
        #region Fields

        private FractalDimension fd;

        #endregion

        #region Properties

        [Range(1, int.MaxValue), NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
        public int Period { get; set; }

        [Range(1, int.MaxValue), NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Smooth period", GroupName = "NinjaScriptParameters", Order = 1)]
        public int SmoothPeriod { get; set; }

        #endregion

        private Series<double> Hurst
        {
            get { return this.Values[0]; }
        }

        private Series<double> HurstSmooth
        {
            get { return this.Values[1]; }
        }

        protected override void OnBarUpdate ()
        {
            if (this.CurrentBar < this.Period) return;

            this.Hurst[0] = -(this.fd.SetValue(this.Input[0], this.CurrentBar) - 2.0);
            this.HurstSmooth[0] = this.EMA(this.Hurst, this.SmoothPeriod)[0];
        }

        protected override void OnStateChange ()
        {
            if (this.State == State.SetDefaults)
            {
                this.Description = Custom.Resource.NinjaScriptIndicatorDescriptionHurstCoefficient;
                this.Name = Custom.Resource.NinjaScriptIndicatorNameHurstCoefficient;
                this.BarsRequiredToPlot = 0;
                this.Calculate = Calculate.OnBarClose;
                this.DrawOnPricePanel = false;
                this.IsSuspendedWhileInactive = true;
                this.Period = 30;
                this.SmoothPeriod = 14;

                this.AddPlot(new Stroke(Brushes.Red, 1), PlotStyle.Dot, "Hurst");
                this.AddPlot(new Stroke(Brushes.DodgerBlue, 1), PlotStyle.Line, "HurstSmooth");
            }
            else if (this.State == State.DataLoaded)
            {
                this.fd = new FractalDimension(this.Period);
            }
        }
    }

    public class FractalDimension
    {
        #region Fields

        private int period;
        private int bars;
        private int lastBar = -1;
        private MINN min;
        private MAXX max;
        private double[] value;
        private double c1;
        private double c2;

        #endregion

        #region Constructors

        public FractalDimension (int period)
        {
            this.period = Math.Max(1, period);
            this.min = new MINN(this.period);
            this.max = new MAXX(this.period);
            this.value = this.min.value;
        }

        #endregion

        public double SetValue (double curVal, int barNum)
        {
            double min, delta = this.max.SetValue(curVal, barNum) - (min = this.min.SetValue(curVal, barNum));

            if (barNum != this.lastBar)
            {
                this.lastBar = barNum;
                if (this.bars < this.period)
                {
                    if (++this.bars > 1)
                    {
                        this.c1 = Math.Pow(1 / (this.bars - 1), 2);
                        this.c2 = Math.Log(2 * (this.bars - 1));
                    }
                }
            }

            if (this.bars < 2 || (delta <= double.Epsilon && -delta <= double.Epsilon))
                return 1;

            double length = 0, yPrev = (curVal - min) / delta;
            for (int i = 1; i < this.bars; ++i)
            {
                double y = (this.value[(barNum - i) % this.period] - min) / delta;
                length += Math.Sqrt(Math.Pow(y - yPrev, 2) + this.c1);
                yPrev = y;
            }

            return 1.0 + (Math.Log(length) + Math.Log(2.0)) / this.c2;
        }
    }

    public class MINN
    {
        #region Fields

        private int period;
        private int lowBar;
        private int lastBar = -1;
        private double low = double.MaxValue;

        #endregion

        #region Constructors

        public MINN (int period)
        {
            this.period = Math.Max(period, 1);
            this.value = new double[this.period];
        }

        #endregion

        #region Properties

        public double[] value { get; private set; }

        #endregion

        public double SetValue (double curVal, int barNum)
        {
            if (barNum == this.lastBar)
                // Intrabar (tick) update
                return Math.Min(this.value[barNum % this.period] = curVal, this.low);

            if (this.lastBar < 0)
            {
                // First call, initialization
                this.lastBar = barNum;
                return this.value[barNum % this.period] = curVal;
            }

            // New bar (either first tick of new bar, or COBC = false)
            if (this.value[this.lastBar % this.period] <= this.low)
            {
                this.low = this.value[this.lastBar % this.period];
                this.lowBar = this.lastBar;
            }

            if (barNum - this.lowBar >= this.period)
            {
                this.low = double.MaxValue;
                int i = barNum - (this.lastBar - this.lowBar);
                for (int index = i % this.period; i < barNum; index = ++i % this.period)
                {
                    if (this.value[index] <= this.low)
                    {
                        this.low = this.value[index];
                        this.lowBar = i;
                    }
                }
            }

            this.lastBar = barNum;

            return Math.Min(this.value[barNum % this.period] = curVal, this.low);
        }
    }

    public class MAXX
    {
        #region Fields

        private double[] value;
        private int period;
        private int hiBar;
        private int lastBar = -1;
        private double hi = double.MinValue;

        #endregion

        #region Constructors

        public MAXX (int period)
        {
            this.period = Math.Max(period, 1);
            this.value = new double[this.period];
        }

        #endregion

        public double SetValue (double curVal, int barNum)
        {
            if (barNum == this.lastBar)
                // Intrabar (tick) update
                return Math.Max(this.value[barNum % this.period] = curVal, this.hi);

            if (this.lastBar < 0)
            {
                // First call, initialization
                this.lastBar = barNum;
                return this.value[barNum % this.period] = curVal;
            }

            // New bar (either first tick of new bar, or COBC = false)
            if (this.value[this.lastBar % this.period] >= this.hi)
            {
                this.hi = this.value[this.lastBar % this.period];
                this.hiBar = this.lastBar;
            }

            if (barNum - this.hiBar >= this.period)
            {
                this.hi = double.MinValue;
                int i = barNum - (this.lastBar - this.hiBar);
                for (int index = i % this.period; i < barNum; index = ++i % this.period)
                {
                    if (this.value[index] >= this.hi)
                    {
                        this.hi = this.value[index];
                        this.hiBar = i;
                    }
                }
            }

            this.lastBar = barNum;

            return Math.Max(this.value[barNum % this.period] = curVal, this.hi);
        }
    }
}

Attached Thumbnails
Click image for larger version

Name:	image_572.png
Views:	262
Size:	128.8 KB
ID:	307190  
Attached Files
Elite Membership required to download: HurstCoefficient.cs
Reply With Quote
Thanked by:
  #9 (permalink)
augustfay
Brooklyn, NY, USA
 
Posts: 2 since Jul 2020
Thanks Given: 1
Thanks Received: 0


agrock View Post
Hi,

Here is a version for NT8. I put together all classes (FractalDimension, MINN, MAXX) in a single file for ease of use. The indicator has been tested and it seems to be OK.

Hey thanks for the upload... but I'm getting this error in NT8. Any ideas why?

Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2021-01-24 at 12.07.47 AM.png
Views:	150
Size:	55.3 KB
ID:	308452  
Reply With Quote




Last Updated on January 27, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts