#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
///
/// </summary>
[Description("")]
[Gui.Design.DisplayName("")]
public class CCIAlerts : Indicator
{
#region Variables
// Wizard generated variables
private int fast = 5; // Default setting for Fast
private int slow = 15; // Default setting for Slow
// 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()
{
Period = 45;
Slow = 15;
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CrossAbove(CCI(Period), 180))
{
// Mark the cross above bar with a green dot
DrawDot(Time[0].ToString(), 0, High[0] + TickSize, Color.Green);
// Only generate an alert on real-time data
if (!Historical)
Alert(Time[0].ToString(), NinjaTrader.Cbi.Priority.Medium, "Cross Above", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Black, Color.Yellow);
}
else if (CrossBelow(CCI(Period), -180))
{
// Mark the cross below bar with a red dot
DrawDot(Time[0].ToString(), 0, Low[0] - TickSize, Color.Red);
// Only generate an alert on real-time data
if (!Historical)
Alert(Time[0].ToString(), NinjaTrader.Cbi.Priority.Medium, "Cross Below", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Yellow, Color.Black);
}
}
#region Properties
[Description("Fast period")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
[Description("Slow period")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = 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 CCIAlerts[] cacheCCIAlerts = null;
private static CCIAlerts checkCCIAlerts = new CCIAlerts();
/// <summary>
///
/// </summary>
/// <returns></returns>
public CCIAlerts CCIAlerts(int fast, int slow)
{
return CCIAlerts(Input, fast, slow);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public CCIAlerts CCIAlerts(Data.IDataSeries input, int fast, int slow)
{
checkCCIAlerts.Fast = fast;
fast = checkCCIAlerts.Fast;
checkCCIAlerts.Slow = slow;
slow = checkCCIAlerts.Slow;
if (cacheCCIAlerts != null)
for (int idx = 0; idx < cacheCCIAlerts.Length; idx++)
if (cacheCCIAlerts[idx].Fast == fast && cacheCCIAlerts[idx].Slow == slow && cacheCCIAlerts[idx].EqualsInput(input))
return cacheCCIAlerts[idx];
CCIAlerts indicator = new CCIAlerts();
indicator.SetUp();
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
CCIAlerts[] tmp = new CCIAlerts[cacheCCIAlerts == null ? 1 : cacheCCIAlerts.Length + 1];
if (cacheCCIAlerts != null)
cacheCCIAlerts.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheCCIAlerts = 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>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CCIAlerts CCIAlerts(int fast, int slow)
{
return _indicator.CCIAlerts(Input, fast, slow);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.CCIAlerts CCIAlerts(Data.IDataSeries input, int fast, int slow)
{
return _indicator.CCIAlerts(input, fast, slow);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CCIAlerts CCIAlerts(int fast, int slow)
{
return _indicator.CCIAlerts(Input, fast, slow);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.CCIAlerts CCIAlerts(Data.IDataSeries input, int fast, int slow)
{
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.CCIAlerts(input, fast, slow);
}
}
}
#endregion
Comment