Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Ninja ElliottOscillator Editing Question
Collapse
X
-
Ninja ElliottOscillator Editing Question
Can someone let me know how I could edit the elliottoscillator so that if it's above the zero line it's one color (green) and if it's below the zero line it's one color (red)...no neutral readings...thanksTags: None
-
here you go...thanks
//
// Copyright (C) 2006, NinjaTrader LLC <[email protected]>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Elliot Oscillator
/// </summary>
[Description("The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
[Gui.Design.DisplayName("Elliot Oscillator")]
public class ElliotOscillator : Indicator
{
#region Variables
private int fast = 5;
private int slow = 34;
private double elliot = 0;
private double elliot3 = 0;
private DataSeries fastEma;
private DataSeries slowEma;
#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.Transparent, "Elliot"));
Add(new Plot(new Pen(Color.Black, 3), PlotStyle.Bar, "Neutral"));
Add(new Plot(new Pen(Color.Blue, 3), PlotStyle.Bar, "UpTrend"));
Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Bar, "DownTrend"));
Add(new Plot(Color.Red, "Elliot Displaced"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
fastEma = new DataSeries(this);
slowEma = new DataSeries(this);
CalculateOnBarClose = true;
PriceTypeSupported = true;
AutoScale = true;
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 3)
return;
if (CurrentBar == 0)
{
fastEma.Set(Input[0]);
slowEma.Set(Input[0]);
Value.Set(0);
Elliott3.Set(0);
if (SMA(100)[0] > SMA(200)[0] && SMA(20)[0] > SMA(100)[0])
Uptrend.Set(0);
else if (SMA(100)[0] < SMA(200)[0] && SMA(20)[0] < SMA(100)[0])
Downtrend.Set(0);
else
Neutral.Set(0);
}
else
{
fastEma.Set(SMA(fast)[0]);
slowEma.Set(SMA(slow)[0]);
elliot = ((fastEma[0] - slowEma[0]));
elliot3 = ((fastEma[3] - slowEma[3]));
Value.Set(elliot);
Elliott3.Set(elliot3);
if (SMA(100)[0] > SMA(200)[0] && SMA(20)[0] > SMA(100)[0])
Uptrend.Set(elliot);
else if (SMA(100)[0] < SMA(200)[0] && SMA(20)[0] < SMA(100)[0])
Downtrend.Set(elliot);
else
Neutral.Set(elliot);
}
}
#region Properties
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Default
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Neutral
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Uptrend
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Downtrend
{
get { return Values[3]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Elliott3
{
get { return Values[4]; }
}
/// <summary>
/// </summary>
[Description("Number of bars for fast SMA")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Number of bars for slow SMA")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(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 ElliotOscillator[] cacheElliotOscillator = null;
private static ElliotOscillator checkElliotOscillator = new ElliotOscillator();
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public ElliotOscillator ElliotOscillator(int fast, int slow)
{
return ElliotOscillator(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public ElliotOscillator ElliotOscillator(Data.IDataSeries input, int fast, int slow)
{
if (cacheElliotOscillator != null)
for (int idx = 0; idx < cacheElliotOscillator.Length; idx++)
if (cacheElliotOscillator[idx].Fast == fast && cacheElliotOscillator[idx].Slow == slow && cacheElliotOscillator[idx].EqualsInput(input))
return cacheElliotOscillator[idx];
lock (checkElliotOscillator)
{
checkElliotOscillator.Fast = fast;
fast = checkElliotOscillator.Fast;
checkElliotOscillator.Slow = slow;
slow = checkElliotOscillator.Slow;
if (cacheElliotOscillator != null)
for (int idx = 0; idx < cacheElliotOscillator.Length; idx++)
if (cacheElliotOscillator[idx].Fast == fast && cacheElliotOscillator[idx].Slow == slow && cacheElliotOscillator[idx].EqualsInput(input))
return cacheElliotOscillator[idx];
ElliotOscillator indicator = new ElliotOscillator();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
Indicators.Add(indicator);
indicator.SetUp();
ElliotOscillator[] tmp = new ElliotOscillator[cacheElliotOscillator == null ? 1 : cacheElliotOscillator.Length + 1];
if (cacheElliotOscillator != null)
cacheElliotOscillator.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheElliotOscillator = 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>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ElliotOscillator ElliotOscillator(int fast, int slow)
{
return _indicator.ElliotOscillator(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.ElliotOscillator ElliotOscillator(Data.IDataSeries input, int fast, int slow)
{
return _indicator.ElliotOscillator(input, fast, slow);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ElliotOscillator ElliotOscillator(int fast, int slow)
{
return _indicator.ElliotOscillator(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.ElliotOscillator ElliotOscillator(Data.IDataSeries input, int fast, int slow)
{
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.ElliotOscillator(input, fast, slow);
}
}
}
#endregion
Comment
-
Thanks, think what you seek would just be a minor change to do the coloring based on the <> 0 condition for the main oscillator value - i.e. change the part in OnBarUpdate() where you assign the plots to -
if (Value[0] > 0)
Uptrend.Set(elliot);
else if (Value[0] < 0)
Downtrend.Set(elliot);BertrandNinjaTrader Customer Service
Comment
-
I did what you suggested (not sure if I did it correctly) but neutral still shows up on the chart?
//
// Copyright (C) 2006, NinjaTrader LLC <[email protected]>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Elliot Oscillator
/// </summary>
[Description("The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
[Gui.Design.DisplayName("Elliot Oscillator")]
public class ElliotOscillatorTEST : Indicator
{
#region Variables
private int fast = 5;
private int slow = 34;
private double elliot = 0;
private double elliot3 = 0;
private DataSeries fastEma;
private DataSeries slowEma;
#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.Transparent, "Elliot"));
Add(new Plot(new Pen(Color.Black, 3), PlotStyle.Bar, "Neutral"));
Add(new Plot(new Pen(Color.Blue, 3), PlotStyle.Bar, "UpTrend"));
Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Bar, "DownTrend"));
Add(new Plot(Color.Red, "Elliot Displaced"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
fastEma = new DataSeries(this);
slowEma = new DataSeries(this);
CalculateOnBarClose = true;
PriceTypeSupported = true;
AutoScale = true;
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 3)
return;
if (CurrentBar == 0)
{
fastEma.Set(Input[0]);
slowEma.Set(Input[0]);
Value.Set(0);
Elliott3.Set(0);
if (Value[0] > 0)
Uptrend.Set(elliot);
else if (Value[0] < 0)
Downtrend.Set(elliot);
}
else
{
fastEma.Set(SMA(fast)[0]);
slowEma.Set(SMA(slow)[0]);
elliot = ((fastEma[0] - slowEma[0]));
elliot3 = ((fastEma[3] - slowEma[3]));
Value.Set(elliot);
Elliott3.Set(elliot3);
if (SMA(100)[0] > SMA(200)[0] && SMA(20)[0] > SMA(100)[0])
Uptrend.Set(elliot);
else if (SMA(100)[0] < SMA(200)[0] && SMA(20)[0] < SMA(100)[0])
Downtrend.Set(elliot);
else
Neutral.Set(elliot);
}
}
#region Properties
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Default
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Neutral
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Uptrend
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Downtrend
{
get { return Values[3]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Elliott3
{
get { return Values[4]; }
}
/// <summary>
/// </summary>
[Description("Number of bars for fast SMA")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Number of bars for slow SMA")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(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 ElliotOscillatorTEST[] cacheElliotOscillatorTEST = null;
private static ElliotOscillatorTEST checkElliotOscillatorTEST = new ElliotOscillatorTEST();
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public ElliotOscillatorTEST ElliotOscillatorTEST(int fast, int slow)
{
return ElliotOscillatorTEST(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public ElliotOscillatorTEST ElliotOscillatorTEST(Data.IDataSeries input, int fast, int slow)
{
if (cacheElliotOscillatorTEST != null)
for (int idx = 0; idx < cacheElliotOscillatorTEST.Length; idx++)
if (cacheElliotOscillatorTEST[idx].Fast == fast && cacheElliotOscillatorTEST[idx].Slow == slow && cacheElliotOscillatorTEST[idx].EqualsInput(input))
return cacheElliotOscillatorTEST[idx];
lock (checkElliotOscillatorTEST)
{
checkElliotOscillatorTEST.Fast = fast;
fast = checkElliotOscillatorTEST.Fast;
checkElliotOscillatorTEST.Slow = slow;
slow = checkElliotOscillatorTEST.Slow;
if (cacheElliotOscillatorTEST != null)
for (int idx = 0; idx < cacheElliotOscillatorTEST.Length; idx++)
if (cacheElliotOscillatorTEST[idx].Fast == fast && cacheElliotOscillatorTEST[idx].Slow == slow && cacheElliotOscillatorTEST[idx].EqualsInput(input))
return cacheElliotOscillatorTEST[idx];
ElliotOscillatorTEST indicator = new ElliotOscillatorTEST();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
Indicators.Add(indicator);
indicator.SetUp();
ElliotOscillatorTEST[] tmp = new ElliotOscillatorTEST[cacheElliotOscillatorTEST == null ? 1 : cacheElliotOscillatorTEST.Length + 1];
if (cacheElliotOscillatorTEST != null)
cacheElliotOscillatorTEST.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheElliotOscillatorTEST = 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>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ElliotOscillatorTEST ElliotOscillatorTEST(int fast, int slow)
{
return _indicator.ElliotOscillatorTEST(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.ElliotOscillatorTEST ElliotOscillatorTEST(Data.IDataSeries input, int fast, int slow)
{
return _indicator.ElliotOscillatorTEST(input, fast, slow);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ElliotOscillatorTEST ElliotOscillatorTEST(int fast, int slow)
{
return _indicator.ElliotOscillatorTEST(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.ElliotOscillatorTEST ElliotOscillatorTEST(Data.IDataSeries input, int fast, int slow)
{
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.ElliotOscillatorTEST(input, fast, slow);
}
}
}
#endregion
Comment
-
It should would, yes. As you would need to remove or comment out the section that previously was doing the plot assignment / coloring, namely this part -
if (SMA(100)[0] > SMA(200)[0] && SMA(20)[0] > SMA(100)[0])
Uptrend.Set(elliot);
else if (SMA(100)[0] < SMA(200)[0] && SMA(20)[0] < SMA(100)[0])
Downtrend.Set(elliot);
else
Neutral.Set(elliot);BertrandNinjaTrader Customer Service
Comment
-
here's what I have...the elliott wave does not show on the chart...i know in the colors its transparent but the uptrend and downtrend don't show...thanks
//
// Copyright (C) 2006, NinjaTrader LLC <[email protected]>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Elliot Oscillator
/// </summary>
[Description("The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
[Gui.Design.DisplayName("Elliot Oscillator")]
public class EWOUpDn : Indicator
{
#region Variables
private int fast = 5;
private int slow = 34;
private double elliot = 0;
private double elliot3 = 0;
private DataSeries fastEma;
private DataSeries slowEma;
#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.Transparent, "Elliot"));
Add(new Plot(new Pen(Color.Black, 3), PlotStyle.Bar, "Neutral"));
Add(new Plot(new Pen(Color.Blue, 3), PlotStyle.Bar, "UpTrend"));
Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Bar, "DownTrend"));
Add(new Plot(Color.Red, "Elliot Displaced"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
fastEma = new DataSeries(this);
slowEma = new DataSeries(this);
CalculateOnBarClose = true;
PriceTypeSupported = true;
AutoScale = true;
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 3)
return;
if (CurrentBar == 0)
{
fastEma.Set(Input[0]);
slowEma.Set(Input[0]);
Value.Set(0);
Elliott3.Set(0);
if (Value[0] > 0)
Uptrend.Set(elliot);
else if (Value[0] < 0)
Downtrend.Set(elliot);
}
else
{
fastEma.Set(SMA(fast)[0]);
slowEma.Set(SMA(slow)[0]);
elliot = ((fastEma[0] - slowEma[0]));
elliot3 = ((fastEma[3] - slowEma[3]));
Value.Set(elliot);
Elliott3.Set(elliot3);
if (SMA(100)[0] > SMA(200)[0] && SMA(20)[0] > SMA(100)[0])
Uptrend.Set(elliot);
else if (SMA(100)[0] < SMA(200)[0] && SMA(20)[0] < SMA(100)[0])
Downtrend.Set(elliot);
}
}
#region Properties
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Default
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Neutral
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Uptrend
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Downtrend
{
get { return Values[3]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Elliott3
{
get { return Values[4]; }
}
/// <summary>
/// </summary>
[Description("Number of bars for fast SMA")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Number of bars for slow SMA")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(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 EWOUpDn[] cacheEWOUpDn = null;
private static EWOUpDn checkEWOUpDn = new EWOUpDn();
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public EWOUpDn EWOUpDn(int fast, int slow)
{
return EWOUpDn(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public EWOUpDn EWOUpDn(Data.IDataSeries input, int fast, int slow)
{
if (cacheEWOUpDn != null)
for (int idx = 0; idx < cacheEWOUpDn.Length; idx++)
if (cacheEWOUpDn[idx].Fast == fast && cacheEWOUpDn[idx].Slow == slow && cacheEWOUpDn[idx].EqualsInput(input))
return cacheEWOUpDn[idx];
lock (checkEWOUpDn)
{
checkEWOUpDn.Fast = fast;
fast = checkEWOUpDn.Fast;
checkEWOUpDn.Slow = slow;
slow = checkEWOUpDn.Slow;
if (cacheEWOUpDn != null)
for (int idx = 0; idx < cacheEWOUpDn.Length; idx++)
if (cacheEWOUpDn[idx].Fast == fast && cacheEWOUpDn[idx].Slow == slow && cacheEWOUpDn[idx].EqualsInput(input))
return cacheEWOUpDn[idx];
EWOUpDn indicator = new EWOUpDn();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
Indicators.Add(indicator);
indicator.SetUp();
EWOUpDn[] tmp = new EWOUpDn[cacheEWOUpDn == null ? 1 : cacheEWOUpDn.Length + 1];
if (cacheEWOUpDn != null)
cacheEWOUpDn.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheEWOUpDn = 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>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.EWOUpDn EWOUpDn(int fast, int slow)
{
return _indicator.EWOUpDn(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.EWOUpDn EWOUpDn(Data.IDataSeries input, int fast, int slow)
{
return _indicator.EWOUpDn(input, fast, slow);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.EWOUpDn EWOUpDn(int fast, int slow)
{
return _indicator.EWOUpDn(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.EWOUpDn EWOUpDn(Data.IDataSeries input, int fast, int slow)
{
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.EWOUpDn(input, fast, slow);
}
}
}
#endregion
Comment
-
and I do have an error in the log:
Error on calling 'OnBarUpdate' method for indicator 'EWOUpDn' on bar 3: Index was outside the bounds of the array.
thanks
Comment
-
Hello thesoyboy2,
Thank you for your response.
You lines of code stored in if(CurrentBar ==0) are never going to process as the preceding line ensures nothing processes below 3. I would change your code in the OnBarUpdate() to the following:
Code:protected override void OnBarUpdate() { if (CurrentBar < 3) return; fastEma.Set(Input[0]); slowEma.Set(Input[0]); Value.Set(0); Elliott3.Set(0); fastEma.Set(SMA(fast)[0]); slowEma.Set(SMA(slow)[0]); elliot = ((fastEma[0] - slowEma[0])); elliot3 = ((fastEma[3] - slowEma[3])); Value.Set(elliot); Elliott3.Set(elliot3); if (Value[0] > 0) Uptrend.Set(elliot); else if (Value[0] < 0) Downtrend.Set(elliot); }
Comment
-
I copied what you have and it still doesn't work (no log errors)...thanks
C:\Users\brian\SkyDrive\Public\EWOaa.png
//
// Copyright (C) 2006, NinjaTrader LLC <[email protected]>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Elliot Oscillator
/// </summary>
[Description("The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
[Gui.Design.DisplayName("Elliot Oscillator")]
public class EWOaa : Indicator
{
#region Variables
private int fast = 5;
private int slow = 34;
private double elliot = 0;
private double elliot3 = 0;
private DataSeries fastEma;
private DataSeries slowEma;
#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.Transparent, "Elliot"));
Add(new Plot(new Pen(Color.Black, 3), PlotStyle.Bar, "Neutral"));
Add(new Plot(new Pen(Color.Blue, 3), PlotStyle.Bar, "UpTrend"));
Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Bar, "DownTrend"));
Add(new Plot(Color.Red, "Elliot Displaced"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
fastEma = new DataSeries(this);
slowEma = new DataSeries(this);
CalculateOnBarClose = true;
PriceTypeSupported = true;
AutoScale = true;
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 3)
return;
{
fastEma.Set(Input[0]);
slowEma.Set(Input[0]);
Value.Set(0);
Elliott3.Set(0);
fastEma.Set(SMA(fast)[0]);
slowEma.Set(SMA(slow)[0]);
elliot = ((fastEma[0] - slowEma[0]));
elliot3 = ((fastEma[3] - slowEma[3]));
Value.Set(elliot);
Elliott3.Set(elliot3);
if (Value[0] > 0)
Uptrend.Set(elliot);
else if (Value[0] < 0)
Downtrend.Set(elliot);
}
}
#region Properties
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Default
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Neutral
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Uptrend
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries Downtrend
{
get { return Values[3]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Elliott3
{
get { return Values[4]; }
}
/// <summary>
/// </summary>
[Description("Number of bars for fast SMA")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Number of bars for slow SMA")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(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 EWOaa[] cacheEWOaa = null;
private static EWOaa checkEWOaa = new EWOaa();
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public EWOaa EWOaa(int fast, int slow)
{
return EWOaa(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public EWOaa EWOaa(Data.IDataSeries input, int fast, int slow)
{
if (cacheEWOaa != null)
for (int idx = 0; idx < cacheEWOaa.Length; idx++)
if (cacheEWOaa[idx].Fast == fast && cacheEWOaa[idx].Slow == slow && cacheEWOaa[idx].EqualsInput(input))
return cacheEWOaa[idx];
lock (checkEWOaa)
{
checkEWOaa.Fast = fast;
fast = checkEWOaa.Fast;
checkEWOaa.Slow = slow;
slow = checkEWOaa.Slow;
if (cacheEWOaa != null)
for (int idx = 0; idx < cacheEWOaa.Length; idx++)
if (cacheEWOaa[idx].Fast == fast && cacheEWOaa[idx].Slow == slow && cacheEWOaa[idx].EqualsInput(input))
return cacheEWOaa[idx];
EWOaa indicator = new EWOaa();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
Indicators.Add(indicator);
indicator.SetUp();
EWOaa[] tmp = new EWOaa[cacheEWOaa == null ? 1 : cacheEWOaa.Length + 1];
if (cacheEWOaa != null)
cacheEWOaa.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheEWOaa = 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>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.EWOaa EWOaa(int fast, int slow)
{
return _indicator.EWOaa(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.EWOaa EWOaa(Data.IDataSeries input, int fast, int slow)
{
return _indicator.EWOaa(input, fast, slow);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.EWOaa EWOaa(int fast, int slow)
{
return _indicator.EWOaa(Input, fast, slow);
}
/// <summary>
/// The Elliot Oscillator is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.EWOaa EWOaa(Data.IDataSeries input, int fast, int slow)
{
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.EWOaa(input, fast, slow);
}
}
}
#endregion
Comment
-
thanks. here's a screen shot of what i got.
C:\Users\brian\SkyDrive\Public\cs_file_ninja.png
One thing is neutral is there...just transparent
The other thing is that what I would like is one color if oscillator is above zero line and one color if it is below zero line...this is still using uptrend and downtrend
thank you so much for all your help...
Comment
-
Correct my apologies, there was the neutral series still defined in the properties of the indicator actually so you could run into an array issue as you had seen, the version attached will fix that. For the coloring this will use the two plots, however you may also switch colors over using NT7's PlotColors approach -
Attached FilesBertrandNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ETFVoyageur, Today, 07:55 PM
|
0 responses
4 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:55 PM
|
||
Started by janio973, Today, 07:24 PM
|
1 response
7 views
0 likes
|
Last Post Today, 07:35 PM | ||
Started by aligator, 01-06-2022, 12:14 PM
|
4 responses
241 views
0 likes
|
Last Post
by john_44573
Today, 06:11 PM
|
||
Started by reynoldsn, Today, 05:56 PM
|
0 responses
12 views
0 likes
|
Last Post
by reynoldsn
Today, 05:56 PM
|
||
Started by bortz, 11-06-2023, 08:04 AM
|
51 responses
1,995 views
0 likes
|
Last Post
by aligator
Today, 05:50 PM
|
Comment