To Terminus
Can you please test this version.
The strange thing, I got this result using a completely different algorithm.
Moderator: admin
code pour Ninjatrader 7.XX:
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// </summary>
[Description("Mogalef band")]
public class MogalefBand : Indicator
{
#region Variables
// Wizard generated variables
private double coeff = 2; // Default setting for Period
// User defined variables (add any user defined variables below)
private DataSeries CP;
private DataSeries F;
#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(Color.FromKnownColor(KnownColor.Magenta), PlotStyle.Line, "Base"));
Plots[0].Pen.Width = 2;
Add(new Plot(Color.FromKnownColor(KnownColor.Gold), PlotStyle.Line, "BandUp"));
Plots[1].Pen.Width = 2;
Add(new Plot(Color.FromKnownColor(KnownColor.SkyBlue), PlotStyle.Line, "BandDown"));
Plots[2].Pen.Width = 2;
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
CP = new DataSeries(this);
F = new DataSeries(this);
}
protected double MyLinReg(IDataSeries data,int period)
{
double sumX = (double) period * (period - 1) * 0.5;
double divisor = sumX * sumX - (double) period * period * (period - 1) * (2 * period - 1) / 6;
double sumXY = 0;
for (int count = 0; count < period && CurrentBar - count >= 0; count++)
sumXY += count * data[count];
double slope = ((double)period * sumXY - sumX * SUM(data, period)[0]) / divisor;
double intercept = (SUM(data, period)[0] - slope * sumX) / period;
return(intercept + slope * (period - 1));
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
CP.Set( (Open[0]+High[0]+Low[0]+2*Close[0])/5 ) ;
F.Set( MyLinReg(CP,3));
if( CurrentBar < 9 || (F[0] > BandUp[1] || F[0] < BandDown[1]) ) {
double E = StdDev(F,7)[0];
Base.Set(F[0]);
BandUp.Set(F[0]+coeff*E);
BandDown.Set(F[0]-coeff*E);
} else {
Base.Set(Base[1]);
BandUp.Set(BandUp[1]);
BandDown.Set(BandDown[1]);
}
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Base
{
get { return Values[0]; }
}
public DataSeries BandUp
{
get { return Values[1]; }
}
public DataSeries BandDown
{
get { return Values[2]; }
}
[Description("Number of standard Deviation")]
[Category("Parameters")]
public double Coeff
{
get { return coeff; }
set { coeff = Math.Max(0.1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private MogalefBand[] cacheMogalefBand = null;
private static MogalefBand checkMogalefBand = new MogalefBand();
/// <summary>
/// Mogalef band
/// </summary>
/// <returns></returns>
public MogalefBand MogalefBand(double coeff)
{
return MogalefBand(Input, coeff);
}
/// <summary>
/// Mogalef band
/// </summary>
/// <returns></returns>
public MogalefBand MogalefBand(Data.IDataSeries input, double coeff)
{
if (cacheMogalefBand != null)
for (int idx = 0; idx < cacheMogalefBand.Length; idx++)
if (Math.Abs(cacheMogalefBand[idx].Coeff - coeff) <= double.Epsilon && cacheMogalefBand[idx].EqualsInput(input))
return cacheMogalefBand[idx];
lock (checkMogalefBand)
{
checkMogalefBand.Coeff = coeff;
coeff = checkMogalefBand.Coeff;
if (cacheMogalefBand != null)
for (int idx = 0; idx < cacheMogalefBand.Length; idx++)
if (Math.Abs(cacheMogalefBand[idx].Coeff - coeff) <= double.Epsilon && cacheMogalefBand[idx].EqualsInput(input))
return cacheMogalefBand[idx];
MogalefBand indicator = new MogalefBand();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Coeff = coeff;
Indicators.Add(indicator);
indicator.SetUp();
MogalefBand[] tmp = new MogalefBand[cacheMogalefBand == null ? 1 : cacheMogalefBand.Length + 1];
if (cacheMogalefBand != null)
cacheMogalefBand.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheMogalefBand = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Mogalef band
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MogalefBand MogalefBand(double coeff)
{
return _indicator.MogalefBand(Input, coeff);
}
/// <summary>
/// Mogalef band
/// </summary>
/// <returns></returns>
public Indicator.MogalefBand MogalefBand(Data.IDataSeries input, double coeff)
{
return _indicator.MogalefBand(input, coeff);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Mogalef band
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MogalefBand MogalefBand(double coeff)
{
return _indicator.MogalefBand(Input, coeff);
}
/// <summary>
/// Mogalef band
/// </summary>
/// <returns></returns>
public Indicator.MogalefBand MogalefBand(Data.IDataSeries input, double coeff)
{
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.MogalefBand(input, coeff);
}
}
}
#endregion
Users browsing this forum: Bing [Bot] and 78 guests