View Full Version : Getting Errors in the Properties Section
erinys
12-30-2009, 07:33 AM
Hi,
I'm trying to create Ehlers Predictive Moving Average. When I paste my code into the NT indicator template I get lots of errors in the Properties section! Any help would be appreciated!
Regards,
Erin
Below is the formula I'm pasting:
protected override void OnBarUpdate()
{
double WMA1;
double WMA2;
double Predict;
double Trigger
if (CurrentBar < 7)
{
WMA1 = 0;
WMA2 = 0;
Predict = 0;
Trigger = 0;
}
else
{
double WMA1 = (7*Median + 6*Median[1] + 5*Median[2] + 4*Median[3] + 3*Median[4] + 2*Median[5] + Median[6])/28;
double WMA2 = (7*WMA1 + 6*WMA1 [1] + 5*WMA1[2] + 4*WMA1[3] + 3*WMA1[4] + 2*WMA1[5] + WMA1[6])/28;;
double Predict = 2*WMA1 - WMA2;
double Trigger = (4*Predict + 3*Predict [1] + 2*Predict[2] + Predict)/10;
Value.Set(Predict);
Value.Set(Trigger);
}
NinjaTrader_Austin
12-30-2009, 08:11 AM
erinys, you'll need a bit more code in the properties section and in the Initialize() section. I am going to assume that Predict and Trigger are two sets of data that you wish to plot (because calling Value.Set(...) twice will just replace the first value with the second value), so you will need to add the plot in Initialize():
Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Line, "Predict"));
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Line, "Trigger"));
Then, the plots will need to be defined in the properties section:
[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 Predict
{
get { return Values[0]; }
}
[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 Trigger
{
get { return Values[1]; }
}
Hopefully this code gets you going in the right direction.. Let us know if you have any other questions.
erinys
12-30-2009, 09:31 AM
Hi Austin,
Thanks for the help. The changes to the initialize portion work fine.
But in the Properties section, I added what you suggested....still getting lots of '; expected' and 'statement expected' errors!
any help woudl be appreciated!
e
NinjaTrader_Austin
12-30-2009, 09:39 AM
Erin, sorry, I just noticed some things I didn't notice the first time. First of all, variables can't be declared twice. You can remove the 'double' in front of the variables inside the OnBarUpdate() section. Another thing: the line that starts with 'double WMA2' actually has two semi-colons at the end; it only needs one semi-colon.
If you don't mind, you could copy + paste the entire code and I'll take a quick look and see if anything else looks out of place.
erinys
12-30-2009, 09:58 AM
#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>
/// Predictive Moving Average (ehlers)
/// </summary>
[Description("Predictive Moving Average (ehlers)")]
public class PMA : Indicator
{
#region Variables
// User defined variables (add any user defined variables below)
#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(new Pen(Color.Blue, 2), PlotStyle.Line, "Predict"));
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Line, "Trigger"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = true;
}
/// <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.
double WMA1;
double WMA2;
double Predict;
double Trigger;
if (CurrentBar < 7)
{
WMA1 = 0;
WMA2 = 0;
Predict = 0;
Trigger = 0;
}
else
{
double WMA1 = (7*Median + 6*Median[1] + 5*Median[2] + 4*Median[3] + 3*Median[4] + 2*Median[5] + Median[6])/28;
double WMA2 = (7*WMA1 + 6*WMA1 [1] + 5*WMA1[2] + 4*WMA1[3] + 3*WMA1[4] + 2*WMA1[5] + WMA1[6])/28;;
double Predict = 2*WMA1 - WMA2;
double Trigger = (4*Predict + 3*Predict [1] + 2*Predict[2] + Predict)/10;
Value.Set(Predict);
Value.Set(Trigger);
Plot0.Set(Predict[0]);
Plot1.Set(Trigger[0]);
}
#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 Predict
{
get { return Values[0]; }
}
[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 Trigger
{
get { return Values[1]; }
}
#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 PMA[] cachePMA = null;
private static PMA checkPMA = new PMA();
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public PMA PMA()
{
return PMA(Input);
}
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public PMA PMA(Data.IDataSeries input)
{
if (cachePMA != null)
for (int idx = 0; idx < cachePMA.Length; idx++)
if (cachePMA[idx].EqualsInput(input))
return cachePMA[idx];
PMA indicator = new PMA();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.SetUp();
PMA[] tmp = new PMA[cachePMA == null ? 1 : cachePMA.Length + 1];
if (cachePMA != null)
cachePMA.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cachePMA = tmp;
Indicators.Add(indicator);
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>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.PMA PMA()
{
return _indicator.PMA(Input);
}
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public Indicator.PMA PMA(Data.IDataSeries input)
{
return _indicator.PMA(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.PMA PMA()
{
return _indicator.PMA(Input);
}
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public Indicator.PMA PMA(Data.IDataSeries input)
{
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.PMA(input);
}
}
}
#endregion
NinjaTrader_Austin
12-30-2009, 10:13 AM
Erin, I don't usually do this, and I'm not really supposed to but your indicator was much more complicated than I originally thought and I didn't want to leave you hanging with some pointers that might not have helped you anyways...
#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>
/// Predictive Moving Average (ehlers)
/// </summary>
[Description("Predictive Moving Average (ehlers)")]
public class PMA : Indicator
{
#region Variables
// declare the variables here
double WMA2;
double Trigger;
// create the dataseries here
private DataSeries WMA1;
private DataSeries Predict;
#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 the plots here
Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Line, "Predict_Plot"));
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Line, "Trigger_Plot"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = true;
// initialize dataseries here
WMA1 = new DataSeries(this);
Predict = new DataSeries(this);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// if there isn't enough data just set the variables to 0
if (CurrentBar < 7)
{
WMA1.Set(0);
WMA2 = 0;
Predict.Set(0);
Trigger = 0;
}
// else set the variables to the real values
else
{
WMA1.Set((7*Median[0] + 6*Median[1] + 5*Median[2] + 4*Median[3] + 3*Median[4] + 2*Median[5] + Median[6])/28);
WMA2 = (7*WMA1[0] + 6*WMA1[1] + 5*WMA1[2] + 4*WMA1[3] + 3*WMA1[4] + 2*WMA1[5] + WMA1[6])/28;
Predict.Set(2*WMA1[0] - WMA2);
Trigger = (4*Predict[0] + 3*Predict[1] + 2*Predict[2] + Predict[3])/10;
}
// set the plots
Predict_Plot.Set(Predict[0]);
Trigger_Plot.Set(Trigger);
}
#region Properties;
// create the dataseries for the plots
[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 Predict_Plot
{
get { return Values[0]; }
}
[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 Trigger_Plot
{
get { return Values[1]; }
}
#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 PMA[] cachePMA = null;
private static PMA checkPMA = new PMA();
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public PMA PMA()
{
return PMA(Input);
}
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public PMA PMA(Data.IDataSeries input)
{
if (cachePMA != null)
for (int idx = 0; idx < cachePMA.Length; idx++)
if (cachePMA[idx].EqualsInput(input))
return cachePMA[idx];
lock (checkPMA)
{
if (cachePMA != null)
for (int idx = 0; idx < cachePMA.Length; idx++)
if (cachePMA[idx].EqualsInput(input))
return cachePMA[idx];
PMA indicator = new PMA();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();
PMA[] tmp = new PMA[cachePMA == null ? 1 : cachePMA.Length + 1];
if (cachePMA != null)
cachePMA.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cachePMA = 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>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.PMA PMA()
{
return _indicator.PMA(Input);
}
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public Indicator.PMA PMA(Data.IDataSeries input)
{
return _indicator.PMA(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.PMA PMA()
{
return _indicator.PMA(Input);
}
/// <summary>
/// Predictive Moving Average (ehlers)
/// </summary>
/// <returns></returns>
public Indicator.PMA PMA(Data.IDataSeries input)
{
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.PMA(input);
}
}
}
#endregion
erinys
12-30-2009, 10:37 AM
austin,
greatly appreciate it!
i have one error remaining. line 83. it says '} expected.
its seems correct as it...why am i getting that error?
seriously, thank you so much!
e
NinjaTrader_Austin
12-30-2009, 10:42 AM
Erin, not sure why you're receiving that error. The code compiles fine on my machine. Did you erase everything before copy + pasting the code I provided? Chances are you have an extra opening bracket "{" somewhere. I've attached the indicator anyways.
erinys
12-30-2009, 10:45 AM
appreciate your assistance, austin.
e