I have developed simple indicator that has values -1.0, 0.0, and 1.0 (float):
if (golong && direction != 1)
{
Plot_Observer.Set(1.0);
direction = 1;
}
else if (goshort && direction != -1)
{
Plot_Observer.Set(-1.0);
direction = -1;
}
else
{
Plot_Observer.Set(0.0);
direction = 0;
}
If I use this indicator in chart it works just fine (it really very simple), but in market analyzer it shows strange values ranging -100 to 100 (floats). What can be wrong?
here is the entire indicator, with conditions removed:
********************
#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>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class Observer : Indicator
{
#region Variables
// Wizard generated variables
private int period = 1; // Default setting for Period
// User defined variables (add any user defined variables below)
#endregion
private int direction;
/// <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.ForestGreen), PlotStyle.Square, "Plot_Observer"));
Add(new Line(Color.FromKnownColor(KnownColor.SandyBrown), 0, "ZeroLine"));
Overlay = false;
CalculateOnBarClose = false;
direction = 0;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar<50) return;
bool golong = true, goshort = true;
// conditions were removed ...
if (golong && direction != 1)
{
Plot_Observer.Set(1.0);
direction = 1;
}
else if (goshort && direction != -1)
{
Plot_Observer.Set(-1.0);
direction = -1;
}
else
{
Plot_Observer.Set(0.0);
direction = 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 Plot_Observer
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = 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 Observer[] cacheObserver = null;
private static Observer checkObserver = new Observer();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Observer Observer(int period)
{
return Observer(Input, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Observer Observer(Data.IDataSeries input, int period)
{
if (cacheObserver != null)
for (int idx = 0; idx < cacheObserver.Length; idx++)
if (cacheObserver[idx].Period == period && cacheObserver[idx].EqualsInput(input))
return cacheObserver[idx];
lock (checkObserver)
{
checkObserver.Period = period;
period = checkObserver.Period;
if (cacheObserver != null)
for (int idx = 0; idx < cacheObserver.Length; idx++)
if (cacheObserver[idx].Period == period && cacheObserver[idx].EqualsInput(input))
return cacheObserver[idx];
Observer indicator = new Observer();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
Observer[] tmp = new Observer[cacheObserver == null ? 1 : cacheObserver.Length + 1];
if (cacheObserver != null)
cacheObserver.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheObserver = 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>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.Observer Observer(int period)
{
return _indicator.Observer(Input, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.Observer Observer(Data.IDataSeries input, int period)
{
return _indicator.Observer(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.Observer Observer(int period)
{
return _indicator.Observer(Input, period);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.Observer Observer(Data.IDataSeries input, 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.Observer(input, period);
}
}
}
#endregion
*******************
Comment