Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Email Price Alert Indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    #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>
    /// 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 = "[email protected]"; // Default setting for ToEmail
    private string fromEmail = "[email protected]"; // 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 = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if(CurrentBar < 1)
    return;

    PriceAlert.Set(Close[0]);

    if(Close[0] == Close[0])
    {
    SendMail(fromEmail, toEmail, "", " " + Close[0]);
    }

    }

    #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
    }
    }

    #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 EmailPriceAlert[] cacheEmailPriceAlert = null;

    private static EmailPriceAlert checkEmailPriceAlert = new EmailPriceAlert();

    /// <summary>
    /// Sends an email when a specified price is reached.
    /// </summary>
    /// <returns></returns>
    public EmailPriceAlert EmailPriceAlert(string fromEmail, double priceLevel, string toEmail)
    {
    return EmailPriceAlert(Input, fromEmail, priceLevel, toEmail);
    }

    /// <summary>
    /// Sends an email when a specified price is reached.
    /// </summary>
    /// <returns></returns>
    public EmailPriceAlert EmailPriceAlert(Data.IDataSeries input, string fromEmail, double priceLevel, string toEmail)
    {
    if (cacheEmailPriceAlert != null)
    for (int idx = 0; idx < cacheEmailPriceAlert.Length; idx++)
    if (cacheEmailPriceAlert[idx].FromEmail == fromEmail && Math.Abs(cacheEmailPriceAlert[idx].PriceLevel - priceLevel) <= double.Epsilon && cacheEmailPriceAlert[idx].ToEmail == toEmail && cacheEmailPriceAlert[idx].EqualsInput(input))
    return cacheEmailPriceAlert[idx];

    lock (checkEmailPriceAlert)
    {
    checkEmailPriceAlert.FromEmail = fromEmail;
    fromEmail = checkEmailPriceAlert.FromEmail;
    checkEmailPriceAlert.PriceLevel = priceLevel;
    priceLevel = checkEmailPriceAlert.PriceLevel;
    checkEmailPriceAlert.ToEmail = toEmail;
    toEmail = checkEmailPriceAlert.ToEmail;

    if (cacheEmailPriceAlert != null)
    for (int idx = 0; idx < cacheEmailPriceAlert.Length; idx++)
    if (cacheEmailPriceAlert[idx].FromEmail == fromEmail && Math.Abs(cacheEmailPriceAlert[idx].PriceLevel - priceLevel) <= double.Epsilon && cacheEmailPriceAlert[idx].ToEmail == toEmail && cacheEmailPriceAlert[idx].EqualsInput(input))
    return cacheEmailPriceAlert[idx];

    EmailPriceAlert indicator = new EmailPriceAlert();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    indicator.FromEmail = fromEmail;
    indicator.PriceLevel = priceLevel;
    indicator.ToEmail = toEmail;
    Indicators.Add(indicator);
    indicator.SetUp();

    EmailPriceAlert[] tmp = new EmailPriceAlert[cacheEmailPriceAlert == null ? 1 : cacheEmailPriceAlert.Length + 1];
    if (cacheEmailPriceAlert != null)
    cacheEmailPriceAlert.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheEmailPriceAlert = 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>
    /// Sends an email when a specified price is reached.
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.EmailPriceAlert EmailPriceAlert(string fromEmail, double priceLevel, string toEmail)
    {
    return _indicator.EmailPriceAlert(Input, fromEmail, priceLevel, toEmail);
    }

    /// <summary>
    /// Sends an email when a specified price is reached.
    /// </summary>
    /// <returns></returns>
    public Indicator.EmailPriceAlert EmailPriceAlert(Data.IDataSeries input, string fromEmail, double priceLevel, string toEmail)
    {
    return _indicator.EmailPriceAlert(input, fromEmail, priceLevel, toEmail);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// Sends an email when a specified price is reached.
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.EmailPriceAlert EmailPriceAlert(string fromEmail, double priceLevel, string toEmail)
    {
    return _indicator.EmailPriceAlert(Input, fromEmail, priceLevel, toEmail);
    }

    /// <summary>
    /// Sends an email when a specified price is reached.
    /// </summary>
    /// <returns></returns>
    public Indicator.EmailPriceAlert EmailPriceAlert(Data.IDataSeries input, string fromEmail, double priceLevel, string toEmail)
    {
    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.EmailPriceAlert(input, fromEmail, priceLevel, toEmail);
    }
    }
    }
    #endregion


    Hi Support,

    the above is the code for the EmailPriceAlert indicator,i`ve only change the Price Value logic.What i`d like to ask is to add the logic that will Alert me in the message if the price actually closed above or below relative to the prior bar and hence,if the current price closes above the prior bar,i`d like "Sell at X" text int the alert message.

    anyone willing to help?

    Thanks a lot in advance!

    Comment


      #17
      How could you modify it to email the execution order information? This is what I am testing out right now... Will it work for any type of execution? (manual/automated/atm/non-atm/)

      private IOrder entryOrder = null;

      protected override void OnExecution(IExecution execution)
      {

      if (entryOrder != null && entryOrder == execution.Order)
      {
      Print(execution.ToString());
      SendMail("@gmail.com", "@gmail.com", "Trade Alert ", execution.ToString());
      }
      }
      Last edited by brucelevy; 01-13-2016, 09:51 PM.

      Comment


        #18
        Hello brucelevy,

        Using OnExecution() would only pull the strategy instance's executions. There is no means to pull other executions outside of the strategy's own orders that it submits.

        Comment


          #19
          Ok, what could I use to email the order information (instrument, order type, fill price, long/short etc)

          Comment


            #20
            Hello brucelevy,

            Are you looking to e-mail the strategy's executions or the accounts?

            Comment


              #21
              I want to email the order information when the automated strategy takes a trade

              Comment


                #22
                Originally posted by brucelevy View Post
                How could you modify it to email the execution order information? This is what I am testing out right now... Will it work for any type of execution? (manual/automated/atm/non-atm/)

                private IOrder entryOrder = null;

                protected override void OnExecution(IExecution execution)
                {

                if (entryOrder != null && entryOrder == execution.Order)
                {
                Print(execution.ToString());
                SendMail("@gmail.com", "@gmail.com", "Trade Alert ", execution.ToString());
                }
                }
                brucelevy,

                There should be no issue doing this in the OnExecution() method. Are you running into any errors?

                Comment


                  #23
                  Well I am not receiving any email regarding trade alerts. The only email I got was one that says "Error on loading chart data for 'NQ 03-16 Globex': Connection to data server is busy or not available right now. Please try again later."

                  Comment


                    #24
                    brucelevy,

                    We can take a closer look at this. Please send me your log and trace files for today so that I may look into what occurred. You can do this by going to the Control Center-> Help-> Mail to Platform Support. Please list 'ATTN: Patrick H - 1445521' in the subject line.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fx.practic, 10-15-2013, 12:53 AM
                    5 responses
                    5,404 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by Shai Samuel, 07-02-2022, 02:46 PM
                    4 responses
                    95 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by DJ888, Yesterday, 10:57 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by MacDad, 02-25-2024, 11:48 PM
                    7 responses
                    159 views
                    0 likes
                    Last Post loganjarosz123  
                    Started by Belfortbucks, Yesterday, 09:29 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post Belfortbucks  
                    Working...
                    X