I'm trying to develop an indicator with 4 conditions. However I don't know how to string the conditions together. Here it the code and a picture of an example of what I'm trying to accomplish.
Here is my code so far:
#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>
/// plots an arrow test
/// </summary>
[Description("plots an arrow test")]
public class AverageArrow : Indicator
{
#region Variables
// Wizard generated variables
private int eMAinput = 16; // Default setting for EMAinput of 16
private int sMAinput = 13; // Default setting for SMAinput of 13
// Color arrow
private Color dnColor = Color.Yellow;
#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()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// condition set 1 takes a longer EMA and lets the condition know // that it is less then (below) the shorter SMA
if (EMA(eMAinput)[0] < SMA(SMAinput)[0])
{
}
// Condition set 2 looks for a short down trend in the sma three bars back
if (SMA(SMAinput)[3] > SMA(SMAinput)[2]
&& SMA(SMAinput)[2] > SMA(SMAinput)[1])
{
}
// Condition set 3 looks for a down close candle
if (Close[0] <= Open[0])
{
}
// Condition set 4 looks for a bar high greater then .20+SMA for ES
if (High[0] > .20+SMA(SMAinput)[0])
{
}
// Condition set 5 takes all conditions and if they all equal true statements
// it plots a downarrow above the closed bar
if (condition1 && condition2 && condition3
&& condition4)
{
DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0]+1*TickSize, dnColor);
}
}
#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]; }
}
[Description("")]
[Category("Parameters")]
public int SMAinput
{
get { return sMAinput; }
set { sMAinput = Math.Max(1, value); }
}
[XmlIgnore()]
[Description("Color for painted region")]
[Category("Plots")]
public Color DnColor
{
get { return dnColor; }
set { dnColor = 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 AverageArrow[] cacheAverageArrow = null;
private static AverageArrow checkAverageArrow = new AverageArrow();
/// <summary>
/// plots an arrow test
/// </summary>
/// <returns></returns>
public AverageArrow AverageArrow(int sMAinput)
{
return AverageArrow(Input, sMAinput);
}
/// <summary>
/// plots an arrow test
/// </summary>
/// <returns></returns>
public AverageArrow AverageArrow(Data.IDataSeries input, int sMAinput)
{
checkAverageArrow.SMAinput = sMAinput;
sMAinput = checkAverageArrow.SMAinput;
if (cacheAverageArrow != null)
for (int idx = 0; idx < cacheAverageArrow.Length; idx++)
if (cacheAverageArrow[idx].SMAinput == sMAinput && cacheAverageArrow[idx].EqualsInput(input))
return cacheAverageArrow[idx];
AverageArrow indicator = new AverageArrow();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.SMAinput = sMAinput;
indicator.SetUp();
AverageArrow[] tmp = new AverageArrow[cacheAverageArrow == null ? 1 : cacheAverageArrow.Length + 1];
if (cacheAverageArrow != null)
cacheAverageArrow.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheAverageArrow = 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>
/// plots an arrow test
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.AverageArrow AverageArrow(int sMAinput)
{
return _indicator.AverageArrow(Input, sMAinput);
}
/// <summary>
/// plots an arrow test
/// </summary>
/// <returns></returns>
public Indicator.AverageArrow AverageArrow(Data.IDataSeries input, int sMAinput)
{
return _indicator.AverageArrow(input, sMAinput);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// plots an arrow test
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.AverageArrow AverageArrow(int sMAinput)
{
return _indicator.AverageArrow(Input, sMAinput);
}
/// <summary>
/// plots an arrow test
/// </summary>
/// <returns></returns>
public Indicator.AverageArrow AverageArrow(Data.IDataSeries input, int sMAinput)
{
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.AverageArrow(input, sMAinput);
}
}
}
#endregion
Comment