Mogalef Bands

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Re: Mogalef Bands

Postby Apprentice » Wed May 25, 2011 1:14 pm

To Terminus
Can you please test this version.
The strange thing, I got this result using a completely different algorithm.
Mogalef.lua
(4.38 KiB) Downloaded 708 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 25382
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Mogalef Bands

Postby Terminus » Wed May 25, 2011 1:58 pm

No modification at the screen... Same problem, one candle too late ....
a real headache ...

Maby the code in ninja trader station can help you........ :?

Thank you for your work !


Code: Select all

 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
Attachments
Mogalef PB.png
Terminus
 
Posts: 27
Joined: Thu May 19, 2011 1:54 pm

Re: Mogalef Bands

Postby Terminus » Thu May 26, 2011 2:33 am

Apprentice,

in fact there is a problem with the last "mogalef.lua" that you maked,it doesn't work
When i try to charge it on the station i have an error message .
Detail of the error ( image on attachment) : String "Mogalef.lua" : 98')' exepted near'period'

(When i charge it on the plaform i forgeted to actualise and in fact i use the old vesion ...)
Attachments
Capture d’écran 2011-05-26 à 09.32.26.png
Terminus
 
Posts: 27
Joined: Thu May 19, 2011 1:54 pm

Re: Mogalef Bands

Postby Terminus » Thu May 26, 2011 4:16 am

Sorry i try again to put in the station the new indicator and now it's ok.
we get closer to a clean version but there are still problems
I noted the differences on the attached image
Attachments
Prorealtime-TS2-2.png
Terminus
 
Posts: 27
Joined: Thu May 19, 2011 1:54 pm

Re: Mogalef Bands

Postby Terminus » Fri May 27, 2011 5:01 am

after testing it sounds ok on small units of time
but there is a problem from the 30mn
Perhaps a story of GAP ....

Many thanks for your work Apprentice
Terminus
 
Posts: 27
Joined: Thu May 19, 2011 1:54 pm

Re: Mogalef Bands

Postby kaya_171 » Wed Jun 08, 2011 4:07 am

Hi Apprentice

I'm sorry for being late (I'm working for the moment) : thank you very much for this indicator and your work
It's great :D

and thanks Terminus ;)
kaya_171
 
Posts: 29
Joined: Tue Feb 08, 2011 3:37 am

Re: Mogalef Bands

Postby BlueBloodedTrader » Tue Aug 09, 2011 3:30 pm

If these Mogalef Bands work on the basis of standard deviations away from the median regression line, what is the difference between these and Bollinger bands?
BlueBloodedTrader
 
Posts: 11
Joined: Tue Feb 15, 2011 6:02 pm

Re: Mogalef Bands

Postby Terminus » Tue Aug 16, 2011 3:52 pm

Put the two indicators on one screen and you can see the difference. :shock:
this two different vison of a range.
Terminus
 
Posts: 27
Joined: Thu May 19, 2011 1:54 pm

Re: Mogalef Bands

Postby Terminus » Tue Aug 16, 2011 3:54 pm

More informations ( beacause my english is so bad....) on mogalef.com
Terminus
 
Posts: 27
Joined: Thu May 19, 2011 1:54 pm

Re: Mogalef Bands

Postby luciana » Wed Aug 17, 2011 4:58 pm

Hi, I don't know whether this code was already part of the thread, but I found it published on a french forum. There are two files, one is concerning linear regression and the other file is the mogalef bands. Not too much french involved but if needed ask for help.

http://www.pro-at.com/forums-bourse/bou ... 33637.html
luciana
 
Posts: 41
Joined: Mon Nov 29, 2010 9:08 am

PreviousNext

Return to Custom Indicators

Who is online

Users browsing this forum: wuhuilin11 and 17 guests