0% found this document useful (0 votes)
173 views5 pages

Hurst Envelope Indicator for NinjaTrader

This document defines the HurstEnvelope indicator class in C# for the NinjaTrader platform. The indicator calculates upper and lower envelope bands around a median price value using a Hurst exponent method. It takes in a period and offset multiplier to configure the calculation. Methods are included to initialize the indicator, calculate values on each bar update, and access the calculated data series.

Uploaded by

top step
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views5 pages

Hurst Envelope Indicator for NinjaTrader

This document defines the HurstEnvelope indicator class in C# for the NinjaTrader platform. The indicator calculates upper and lower envelope bands around a median price value using a Hurst exponent method. It takes in a period and offset multiplier to configure the calculation. Methods are included to initialize the indicator, calculate values on each bar update, and access the calculated data series.

Uploaded by

top step
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Declarations and Setup
  • Summary and Variables
  • Properties and Methods
  • Indicator Class Implementation
  • Market Analyzer Integration
  • Initialization and Access

//

//

#region Using declarations


using System;
using [Link];
using [Link];
using [Link].Drawing2D;
using [Link];
using [Link];
using [Link];
using [Link];
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace [Link]
{
/// <summary>
///
/// </summary>
[Description("The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'")]
public class HurstEnvelope : Indicator
{
#region Variables
private int period
= 10;
private double offsetMultiplier = 1.5;
private DataSeries diff;
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once
before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot([Link], "Midline"));
Add(new Plot([Link], "Upper"));
Add(new Plot([Link], "Lower"));

diff = new DataSeries(this);

Overlay = true;
PriceTypeSupported = false;
}

/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < Period)
return;
[Link](High[0] - Low[0]);

double middle = TMA(Median, Period)[0];


double offset = TMA(diff, Period)[0] * offsetMultiplier;
double upper = middle + offset;
double lower = middle - offset;

KeltnerChannel env = KeltnerChannel(Median, offsetMultiplier,


(period/2));

[Link](middle);
[Link](upper);
[Link](lower);

DrawLine("UPPER", true, (period/2), upper, 0, [Link][0],


[Link], [Link], 1);
DrawLine("LOWER", true, (period/2), lower, 0, [Link][0],
[Link], [Link], 1);

#region Properties
/// <summary>
/// </summary>
[Description("Numbers of bars used for calculations")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = [Link](1, value); }
}

/// <summary>
/// </summary>
[Description("How much to expand the upper and lower band from the
normal offset")]
[Category("Parameters")]
[[Link]("Offset multiplier")]
public double OffsetMultiplier
{
get { return offsetMultiplier; }
set { offsetMultiplier = [Link](0.01, value); }
}

/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Midline
{
get { return Values[0]; }
}

/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Upper
{
get { return Values[1]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Lower
{
get { return Values[2]; }
}
#endregion
}
}

#region NinjaScript generated code. Neither change nor remove.


// This namespace holds all indicators and is required. Do not change it.
namespace [Link]
{
public partial class Indicator : IndicatorBase
{
private HurstEnvelope[] cacheHurstEnvelope = null;

private static HurstEnvelope checkHurstEnvelope = new HurstEnvelope();

/// <summary>
/// The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'
/// </summary>
/// <returns></returns>
public HurstEnvelope HurstEnvelope(double offsetMultiplier, int period)
{
return HurstEnvelope(Input, offsetMultiplier, period);
}

/// <summary>
/// The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'
/// </summary>
/// <returns></returns>
public HurstEnvelope HurstEnvelope([Link] input, double
offsetMultiplier, int period)
{
[Link] = offsetMultiplier;
offsetMultiplier = [Link];
[Link] = period;
period = [Link];

if (cacheHurstEnvelope != null)
for (int idx = 0; idx < [Link]; idx++)
if ([Link](cacheHurstEnvelope[idx].OffsetMultiplier -
offsetMultiplier) <= [Link] && cacheHurstEnvelope[idx].Period == period &&
cacheHurstEnvelope[idx].EqualsInput(input))
return cacheHurstEnvelope[idx];

HurstEnvelope indicator = new HurstEnvelope();


[Link] = BarsRequired;
[Link] = CalculateOnBarClose;
[Link] = input;
[Link] = offsetMultiplier;
[Link] = period;
[Link]();
HurstEnvelope[] tmp = new HurstEnvelope[cacheHurstEnvelope == null ?
1 : [Link] + 1];
if (cacheHurstEnvelope != null)
[Link](tmp, 0);
tmp[[Link] - 1] = indicator;
cacheHurstEnvelope = tmp;
[Link](indicator);

return indicator;
}

}
}

// This namespace holds all market analyzer column definitions and is required. Do
not change it.
namespace [Link]
{
public partial class Column : ColumnBase
{
/// <summary>
/// The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'
/// </summary>
/// <returns></returns>
[[Link]("Indicator")]
public [Link] HurstEnvelope(double offsetMultiplier, int
period)
{
return _indicator.HurstEnvelope(Input, offsetMultiplier, period);
}

/// <summary>
/// The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'
/// </summary>
/// <returns></returns>
public [Link] HurstEnvelope([Link] input, double
offsetMultiplier, int period)
{
return _indicator.HurstEnvelope(input, offsetMultiplier, period);
}

}
}

// This namespace holds all strategies and is required. Do not change it.
namespace [Link]
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'
/// </summary>
/// <returns></returns>
[[Link]("Indicator")]
public [Link] HurstEnvelope(double offsetMultiplier, int
period)
{
return _indicator.HurstEnvelope(Input, offsetMultiplier, period);
}

/// <summary>
/// The Hurst Envelope is described in J.M Hursts 'The Profit Magic of
Stock Transaction Timing'
/// </summary>
/// <returns></returns>
public [Link] HurstEnvelope([Link] input, double
offsetMultiplier, int period)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with
the default input/bar series from within the 'Initialize()' method");

return _indicator.HurstEnvelope(input, offsetMultiplier, period);


}

}
}
#endregion

//
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D
double upper
= middle + offset;
double lower
= middle - offset;
KeltnerChannel env = KeltnerChannel(Median, offsetMultiplier,
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Lower
{
get { return Values[2]; }
}
        #
HurstEnvelope[] tmp = new HurstEnvelope[cacheHurstEnvelope == null ? 
1 : cacheHurstEnvelope.Length + 1];
period)
        {
            return _indicator.HurstEnvelope(Input, offsetMultiplier, period);
        }
        /// <summar

You might also like