This is my indicator,
#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 PivotAverage : Indicator
{
private int pivotLookBack = 7;
private int sessionCount = 0;
private DataSeries ppDS;
private bool debug = false;
protected override void Initialize()
{
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
Add(PeriodType.Day, 1); //Add Day Bars to Index location 1
Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Dot, "PPAvg"));
Overlay = true;
BarsRequired = 2;
}
protected override void OnBarUpdate()
{
if(ppDS == null) // Only to sync the ppDS DataSeries to Day Bars
{
ppDS = new DataSeries(SMA(BarsArray[1], 2));
}
if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
return;
if(Bars.SessionBreak)// If there is a new session add one to session count.
{
sessionCount++;
}
if(BarsInProgress == 1)
{
ppDS.Set(Math.Round((Highs[1][0] + Lows[1][0] + Closes[1][0])/3,2));
if(CurrentBar < (BarsRequired + pivotLookBack))
{
PPAvg.Set(ppDS[0]);
}
else
{
PPAvg.Set(SMA(ppDS, pivotLookBack)[0]);
}
if(Rising(PPAvg))
Print("Rising");
if(Falling(PPAvg))
Print("Falling");
if(Debug)
{
Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Print(Time[0]);
Print("Yesterdays Pivot Point is " + ppDS[1]);
Print("Pivot Point is " + ppDS[0]);
Print("Pivot " + pivotLookBack + "Period SMA is " + PPAvg[0]);
Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
}
}
#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 PPAvg
{
get { return Values[0]; }
}
[Description("No of days to calculate the average")]
[GridCategory("Parameters")]
public int PivotLookBack
{
get { return pivotLookBack; }
set { pivotLookBack = Math.Max(1, value); }
}
[Description("Display pivot values to the output window if true")]
[GridCategory("Parameters")]
public bool Debug
{
get { return debug; }
set { debug = 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 PivotAverage[] cachePivotAverage = null;
private static PivotAverage checkPivotAverage = new PivotAverage();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public PivotAverage PivotAverage(bool debug, int pivotLookBack)
{
return PivotAverage(Input, debug, pivotLookBack);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public PivotAverage PivotAverage(Data.IDataSeries input, bool debug, int pivotLookBack)
{
if (cachePivotAverage != null)
for (int idx = 0; idx < cachePivotAverage.Length; idx++)
if (cachePivotAverage[idx].Debug == debug && cachePivotAverage[idx].PivotLookBack == pivotLookBack && cachePivotAverage[idx].EqualsInput(input))
return cachePivotAverage[idx];
lock (checkPivotAverage)
{
checkPivotAverage.Debug = debug;
debug = checkPivotAverage.Debug;
checkPivotAverage.PivotLookBack = pivotLookBack;
pivotLookBack = checkPivotAverage.PivotLookBack;
if (cachePivotAverage != null)
for (int idx = 0; idx < cachePivotAverage.Length; idx++)
if (cachePivotAverage[idx].Debug == debug && cachePivotAverage[idx].PivotLookBack == pivotLookBack && cachePivotAverage[idx].EqualsInput(input))
return cachePivotAverage[idx];
PivotAverage indicator = new PivotAverage();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Debug = debug;
indicator.PivotLookBack = pivotLookBack;
Indicators.Add(indicator);
indicator.SetUp();
PivotAverage[] tmp = new PivotAverage[cachePivotAverage == null ? 1 : cachePivotAverage.Length + 1];
if (cachePivotAverage != null)
cachePivotAverage.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cachePivotAverage = 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.PivotAverage PivotAverage(bool debug, int pivotLookBack)
{
return _indicator.PivotAverage(Input, debug, pivotLookBack);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.PivotAverage PivotAverage(Data.IDataSeries input, bool debug, int pivotLookBack)
{
return _indicator.PivotAverage(input, debug, pivotLookBack);
}
}
}
// 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.PivotAverage PivotAverage(bool debug, int pivotLookBack)
{
return _indicator.PivotAverage(Input, debug, pivotLookBack);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.PivotAverage PivotAverage(Data.IDataSeries input, bool debug, int pivotLookBack)
{
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.PivotAverage(input, debug, pivotLookBack);
}
}
}
#endregion
And I am calling it in my Strategy like this:-
if(Falling(PivotAverage(false, iPivotAvgPeriod)))

Comment