• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sendmail() issues

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

    Sendmail() issues

    Hello,

    I'm having issues trying to use the sendmail function : it continiously sends email to my adress until the condition is false..

    I would like the script to send one and only one email alert.. can someone have a look at my code ?

    Many thanks

    #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.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    ///
    /// </summary>
    [Description("")]
    public class JeromeSTDEV : Strategy

    {
    #region Variables
    // Wizard generated variables
    private bool jeromeStdev = true; // Default setting for JeromeStdev
    // User defined variables (add any user defined variables below)
    #endregion
    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>

    protected override void Initialize()
    {

    CalculateOnBarClose = true;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1

    if (CrossBelow(Close, Indicator1(0.83, 1, 0.83, 1).LowerOutside, 1))
    {
    Alert("MyAlert0", Priority.High, "Possible Long", "", 360, Color.Salmon, Color.White);
    SendMail("[email protected]", "[email protected]", "NT LNG", "NT LNG");
    }

    // Condition set 2
    if (CrossAbove(Close, Indicator1(0.83, 1, 0.83, 1).UpperOutside, 1))
    {
    Alert("MyAlert1", Priority.High, "S/S", "", 360, Color.LimeGreen, Color.Black);
    SendMail("[email protected]", "[email protected]", "NT S/S", "NT S/S");
    }

    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public bool JeromeStdev
    {
    get { return jeromeStdev; }
    set { jeromeStdev = value; }
    }
    #endregion
    }
    }

    #2
    Hello,

    Thank you for the question.

    I am unable to test this script because it is referencing a custom indicator so I can not see exactly what you are.

    I would like to ask, are you referring to how to prevent this from sending an email for all historical orders that cause the condition to become true? Would you like this to only send messages in real time for new orders?

    If this is the case you can wrap the sendmail in a if statement to prevent this, this would be the syntax:
    Code:
    if(!Historical)
    {
         //sendmail here
    }

    Because I do not have the referenced indicator, this may also depend on your cross condition. Does the condition in which you are sending your email constantly report as true or is the cross happening each bar?


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you very much for your quick reply

      My indicator is similar to a bollinger bands

      what I am testing is current bar crosses above the upperband then alert + sendmail(). I have no trading orders linked to this condition yet. I have attached what the indicator look like to get an idea.

      for some reason the alert does trigger even before the bar is not closed yet and emails are sent continiously

      What does the !historical actually do ?


      Thank you,
      Best regards,
      Attached Files

      Comment


        #4
        Hello,

        Thank you for the details.

        I am unsure why this would happen continously unless you are referring to this happening for the historical bars. The way this is, when it is run it will run through the historical bars and then go into real time data. Without the additional indicator it is hard to say if your scripts conditions are always true or not, have you tried using a Print() statement inside these conditions to see how often they happen?

        I switched the referenced indicator with a bollinger and tried your conditions. I did get it happening where the cross over was found but it did not continue after that once it hit realtime.

        Also are you using this on calculateOnBar Close set to true or false? It is true in your script, are you setting it to false on the chart?

        The !Historical is a switch, you can use this to determine if a bar is historical or not.

        in this case the way your code is currently it will be run historically first and then will run during real time data.
        you would have a email sent for every historical bar where your condition becomes true once you enable the strategy.

        To prevent emails from being sent during historical bars you would wrap them with the prior if statement I posted.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Sorry to re-open this issue in 2017, but I'm having the same issue with NT8.
          I think it's occuring as the market "breathes" back and forth. If Calculate.OnPriceChange or Calculate.OneachTick is set to true. Calculate.OnBarClose doesn't generate this problem.

          In my case, whenever my strategy enters long or short, SendMail is activated; but I may get 10 emails for the same thing. Since only 1 entry per direction is allowed, I don;t get several entries though! But how do I stop this. I need to calculate on Price change rather than on bar close.

          Many thanks.

          Comment


            #6
            Hello,

            Thank you for the reply.

            If the event is triggering multiple times in realtime while using Calculate.OnPriceChange or OnEachTick you would need to add logic in to prevent that.

            Essentially what is occuring is that your condition is remaining true allowing the email to be re sent each tick or price change.

            You could do something simple like using a bool to control if it can send and reset the bool when it should be able to send again:

            Code:
            private bool canSendMail  = true;
            protected override void OnBarUpdate()
            {
                if (IsFirstTickOfBar)
                {
                    canSendMail = true;
                }
                if (CrossBelow(Close, Indicator1(0.83, 1, 0.83, 1).LowerOutside, 1))
                {
                  
                    if(canSendMail)
                    {
                     SendMail("[email protected]", "Trade Alert", "Buy ES");
                       canSendMail = false;
                    }
                }
            }
            http://ninjatrader.com/support/helpG...tsub=firsttick

            This type of logic would just prevent the email from happening after it has been sent once. On each new bar, the variable is reset so the email can be sent again when the condition becomes true again.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by markus3500, Today, 03:29 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by bohenriksen, Today, 04:00 AM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by brett0, Today, 12:33 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Melissa  
            Started by lordvader34, Today, 11:12 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by tausifkhan, Today, 05:18 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X