The code below compiles ok but does not plot anything when placed on a chart. Where do I go wrong?
Anyone?
Regards,
Dennis
// 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 EURUSDpara : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
private int _stochastic_period_1 = 60; // Default setting for _stochastic_period_1
private int _lookback_2 = 5; // Default setting for _lookback_2
#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.Orange), PlotStyle.Line, "Plot0"));
Overlay = false;
}
/// <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 result = 0;
if ((High[_stochastic_period_1] - Low[_stochastic_period_1]) != 0)
result += (Close[0] - + Low[_stochastic_period_1]) / (High[_stochastic_period_1] - Low[_stochastic_period_1]);
result *= High[0];
result = Math.Cos(result);
result += Open[0] - Open[_lookback_2];
result = Math.Tanh(result);
if (result > 0)
result = 1;
else if (result < 0)
result = -1;
else
result = 0;
Value.Set(result);
Plot0.Set(result);
}
#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 Plot0
{
get { return Values[0]; }
}
//Put the code below into the Parameters / Properties section
[Description("")]
[GridCategory("Parameters")]
public int _Stochastic_Period_1
{
get { return _stochastic_period_1; }
set { _stochastic_period_1 = Math.Max(10, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int _Lookback_2
{
get { return _lookback_2; }
set { _lookback_2 = Math.Max(5, 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 EURUSDpara[] cacheEURUSDpara = null;
private static EURUSDpara checkEURUSDpara = new EURUSDpara();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public EURUSDpara EURUSDpara(int _Lookback_2, int _Stochastic_Period_1)
{
return EURUSDpara(Input, _Lookback_2, _Stochastic_Period_1);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public EURUSDpara EURUSDpara(Data.IDataSeries input, int _Lookback_2, int _Stochastic_Period_1)
{
if (cacheEURUSDpara != null)
for (int idx = 0; idx < cacheEURUSDpara.Length; idx++)
if (cacheEURUSDpara[idx]._Lookback_2 == _Lookback_2 && cacheEURUSDpara[idx]._Stochastic_Period_1 == _Stochastic_Period_1 && cacheEURUSDpara[idx].EqualsInput(input))
return cacheEURUSDpara[idx];
lock (checkEURUSDpara)
{
checkEURUSDpara._Lookback_2 = _Lookback_2;
_Lookback_2 = checkEURUSDpara._Lookback_2;
checkEURUSDpara._Stochastic_Period_1 = _Stochastic_Period_1;
_Stochastic_Period_1 = checkEURUSDpara._Stochastic_Period_1;
if (cacheEURUSDpara != null)
for (int idx = 0; idx < cacheEURUSDpara.Length; idx++)
if (cacheEURUSDpara[idx]._Lookback_2 == _Lookback_2 && cacheEURUSDpara[idx]._Stochastic_Period_1 == _Stochastic_Period_1 && cacheEURUSDpara[idx].EqualsInput(input))
return cacheEURUSDpara[idx];
EURUSDpara indicator = new EURUSDpara();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator._Lookback_2 = _Lookback_2;
indicator._Stochastic_Period_1 = _Stochastic_Period_1;
Indicators.Add(indicator);
indicator.SetUp();
EURUSDpara[] tmp = new EURUSDpara[cacheEURUSDpara == null ? 1 : cacheEURUSDpara.Length + 1];
if (cacheEURUSDpara != null)
cacheEURUSDpara.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheEURUSDpara = 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.EURUSDpara EURUSDpara(int _Lookback_2, int _Stochastic_Period_1)
{
return _indicator.EURUSDpara(Input, _Lookback_2, _Stochastic_Period_1);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.EURUSDpara EURUSDpara(Data.IDataSeries input, int _Lookback_2, int _Stochastic_Period_1)
{
return _indicator.EURUSDpara(input, _Lookback_2, _Stochastic_Period_1);
}
}
}
// 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.EURUSDpara EURUSDpara(int _Lookback_2, int _Stochastic_Period_1)
{
return _indicator.EURUSDpara(Input, _Lookback_2, _Stochastic_Period_1);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.EURUSDpara EURUSDpara(Data.IDataSeries input, int _Lookback_2, int _Stochastic_Period_1)
{
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.EURUSDpara(input, _Lookback_2, _Stochastic_Period_1);
}
}
}
#endregion
Comment