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>
/// Sends an email when a specified price is reached.
/// </summary>
[Description("Sends an email when a specified price is reached.")]
public class EmailPriceAlert : Indicator
{
#region Variables
// Wizard generated variables
private double priceLevel = 1; // Default setting for PriceLevel
private string toEmail = " "; // Default setting for ToEmail
private string fromEmail = " "; // Default setting for FromEmail
// 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.HLine, "PriceAlert"));
Overlay = true;
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(CurrentBar < 1)
return;
PriceAlert.Set(PriceLevel);
if(Close[0] == PriceLevel)
{
SendMail(fromEmail, toEmail, "Price Alert", "Price level was hit at: " + PriceLevel);
}
}
#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 PriceAlert
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public double PriceLevel
{
get { return priceLevel; }
set { priceLevel = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public string ToEmail
{
get { return toEmail; }
set { toEmail = value; }
}
[Description("")]
[GridCategory("Parameters")]
public string FromEmail
{
get { return fromEmail; }
set { fromEmail = value; }
}
#endregion
}
}
Comment