Hello,
This is my first post. I am new to code but mase a simple strategy to test out. It worked and plotted as expected. Converted it to an indicator. Indicator will not plot. I looked through some tips and updated as such. It compiles just fine. Can someone help me to see what I am missing. Sorry if this has been answered before. And not sure if posted correctly. New to forums in general.
Thank you in advance for any help.
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 Indicator5 : Indicator
{
region Variables
// Wizard generated variables
private int fast = 8; // Default setting for Fast
private int slow = 13; // Default setting for Slow
private int smooth = 11; // Default setting for Smooth
private int aroonPeriod = 14; // Default setting for AroonPeriod
// 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(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
{if (CurrentBar < 1)
return;
if (Close[0] > Close[1])
// Do something
// Condition set 1
if (MACD(Fast, Slow, Smooth)[0] >= MACD(Fast, Slow, Smooth).Avg[0]
&& Aroon(AroonPeriod).Up[0] >= Aroon(AroonPeriod).Down[0])
{
BackColorAll = Color.PaleGreen;
}
// Condition set 2
if (MACD(Fast, Slow, Smooth)[0] <= MACD(Fast, Slow, Smooth).Avg[0]
&& Aroon(AroonPeriod).Up[0] <= Aroon(AroonPeriod).Down[0])
{
BackColorAll = Color.RosyBrown;
}
// Condition set 3
if (MACD(Fast, Slow, Smooth)[0] >= MACD(Fast, Slow, Smooth).Avg[0]
&& Aroon(AroonPeriod).Up[0] >= Aroon(AroonPeriod).Down[0]
&& MACD(BarsArray[1],Fast, Slow, Smooth)[0] >= MACD(BarsArray[1],Fast, Slow, Smooth).Avg[0]
&& Aroon(BarsArray[1],AroonPeriod).Up[0] >= Aroon(BarsArray[1],AroonPeriod).Down[0])
{
BackColorAll = Color.CornflowerBlue;
}
// Condition set 4
if (MACD(Fast, Slow, Smooth)[0] <= MACD(Fast, Slow, Smooth).Avg[0]
&& Aroon(AroonPeriod).Up[0] <= Aroon(AroonPeriod).Down[0]
&& MACD(BarsArray[1],Fast, Slow, Smooth)[0] <= MACD(BarsArray[1],Fast, Slow, Smooth).Avg[0]
&& Aroon(BarsArray[1],AroonPeriod).Up[0] <= Aroon(BarsArray[1],AroonPeriod).Down[0])
{
BackColorAll = Color.Tomato;
}
}}
region Properties
[Description("Fast")]
[GridCategory("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
[Description("Slow")]
[GridCategory("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
[Description("Smooth")]
[GridCategory("Parameters")]
public int Smooth
{
get { return smooth; }
set { smooth = Math.Max(1, value); }
}
[Description("AroonPeriod")]
[GridCategory("Parameters")]
public int AroonPeriod
{
get { return aroonPeriod; }
set { aroonPeriod = 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 Indicator5[] cacheIndicator5 = null;
private static Indicator5 checkIndicator5 = new Indicator5();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator5 Indicator5(int aroonPeriod, int fast, int slow, int smooth)
{
return Indicator5(Input, aroonPeriod, fast, slow, smooth);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator5 Indicator5(Data.IDataSeries input, int aroonPeriod, int fast, int slow, int smooth)
{
if (cacheIndicator5 != null)
for (int idx = 0; idx < cacheIndicator5.Length; idx++)
if (cacheIndicator5[idx].AroonPeriod == aroonPeriod && cacheIndicator5[idx].Fast == fast && cacheIndicator5[idx].Slow == slow && cacheIndicator5[idx].Smooth == smooth && cacheIndicator5[idx].EqualsInput(input))
return cacheIndicator5[idx];
lock (checkIndicator5)
{
checkIndicator5.AroonPeriod = aroonPeriod;
aroonPeriod = checkIndicator5.AroonPeriod;
checkIndicator5.Fast = fast;
fast = checkIndicator5.Fast;
checkIndicator5.Slow = slow;
slow = checkIndicator5.Slow;
checkIndicator5.Smooth = smooth;
smooth = checkIndicator5.Smooth;
if (cacheIndicator5 != null)
for (int idx = 0; idx < cacheIndicator5.Length; idx++)
if (cacheIndicator5[idx].AroonPeriod == aroonPeriod && cacheIndicator5[idx].Fast == fast && cacheIndicator5[idx].Slow == slow && cacheIndicator5[idx].Smooth == smooth && cacheIndicator5[idx].EqualsInput(input))
return cacheIndicator5[idx];
Indicator5 indicator = new Indicator5();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.AroonPeriod = aroonPeriod;
indicator.Fast = fast;
indicator.Slow = slow;
indicator.Smooth = smooth;
Indicators.Add(indicator);
indicator.SetUp();
Indicator5[] tmp = new Indicator5[cacheIndicator5 == null ? 1 : cacheIndicator5.Length + 1];
if (cacheIndicator5 != null)
cacheIndicator5.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheIndicator5 = 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.Indicator5 Indicator5(int aroonPeriod, int fast, int slow, int smooth)
{
return _indicator.Indicator5(Input, aroonPeriod, fast, slow, smooth);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.Indicator5 Indicator5(Data.IDataSeries input, int aroonPeriod, int fast, int slow, int smooth)
{
return _indicator.Indicator5(input, aroonPeriod, fast, slow, smooth);
}
}
}
// 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.Indicator5 Indicator5(int aroonPeriod, int fast, int slow, int smooth)
{
return _indicator.Indicator5(Input, aroonPeriod, fast, slow, smooth);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.Indicator5 Indicator5(Data.IDataSeries input, int aroonPeriod, int fast, int slow, int smooth)
{
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.Indicator5(input, aroonPeriod, fast, slow, smooth);
}
}
}
#endregion
Comment