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

SendMailChart will not fire

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

    SendMailChart will not fire

    I've been trying to get SendMailChart from SendMailChartLib to work and after two days of trying it myself I cant seem to figure out why it won't go off. I did test teh same mail settings from the Ninjatrader preferences interface and it does work there. Anyone familiar with the SendMailchartLib.cs file - I kept the example to the example so my code looks like this (with different email addresses and passwords):

    if (1==1) // strategy signal logic goes here
    {
    if (!Historical)
    {
    string subj = Instrument.MasterInstrument.Name + " " + Time[0].ToShortDateString() + " " + Time[0].ToShortTimeString();
    string message = "Close " + Close[0].ToString();
    SendMailChart(ChartControl, subj, message, "[email protected]", "[email protected]", "smtp.gmail.com", 587, "[email protected]", "obviouslyfake");
    }
    }

    This is in the onBarUpdate() portion. I'm fairly new at this so I apologize if it's an obvious error.

    #2
    Debugged

    I have since debugged this with Visual Studio and removed the if (!Historical). It gets to the SendMailChart(..) line and "executes" but nothing seems to happen. Still need some help with what is wrong on that line.

    Comment


      #3
      Hello sobertradingpartner,

      While, this not something that we can support the GMail mail servers require the "SSL" to be enabled. So you may want to enable this option.

      Code:
      SmtpClient smtp = new SmtpClient(Host, Port);
      				
      smtp.EnableSsl = true;
      
      // rest of code
      JCNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_JC View Post
        Hello sobertradingpartner,

        While, this not something that we can support the GMail mail servers require the "SSL" to be enabled. So you may want to enable this option.

        Code:
        SmtpClient smtp = new SmtpClient(Host, Port);
                        
        smtp.EnableSsl = true;
        
        // rest of code
        http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

        Thanks for the help. I was finally able to get it working but have a new strange issue. I setup hmailserver locally to make sure there were no problems sending the email. Apparently when I load the strategy, the chart hangs for about 30 seconds. During that time it sends out close to 300 emails! The emails have blank photos instead of the chart as the chart has yet to fully display. After the chart finally displays on the screen the strategy works as normal and only sends out the email when a trigger hits. I believe the culprit is the Bitmap/MemoryStream process. Anyone who can help I'd be appreciative. I'll post the relevant code below:

        try
        {
        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(chart.ChartPanel.Width, chart.ChartPanel.Height, PixelFormat.Format16bppRgb555);
        chart.ChartPanel.DrawToBitmap(bmp, chart.ChartPanel.ClientRectangle);
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        bmp.Save(stream, ImageFormat.Png);
        stream.Position = 0;
        MailMessage theMail = new MailMessage(From, To, Subject, Body);
        System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(stream, "image.png");
        theMail.Attachments.Add(attachment);
        SmtpClient smtp = new SmtpClient(Host, Port);
        smtp.Credentials = new System.Net.NetworkCredential(Username, Password);
        smtp.UseDefaultCredentials = false;
        smtp.EnableSsl = false;
        smtp.Send(theMail);
        }
        catch (Exception ex)
        {
        Print(" -------- SendMailChart Exception: " + ex);
        SendMail(From, To, "SendMailChart Exception", "SendMailChart Exception");
        }

        Comment


          #5
          Hello sobertradingpartner,

          This is going to be due to the Strategy being processed on Historical Data. Have you added back in the "if (!Historical)" check?

          This will make sure it does not get processed Historically because the chart will not be visible until NinjaTrader finishes loading up the data. Otherwise, you may get many different message as each OnBarUpdate() is called. So for example on a 1 Minute chart you could have 1440 different send messages.
          JCNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_JC View Post
            Hello sobertradingpartner,

            This is going to be due to the Strategy being processed on Historical Data. Have you added back in the "if (!Historical)" check?

            This will make sure it does not get processed Historically because the chart will not be visible until NinjaTrader finishes loading up the data. Otherwise, you may get many different message as each OnBarUpdate() is called. So for example on a 1 Minute chart you could have 1440 different send messages.

            Thanks, that fixed it!!!!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by popecapllc, 08-09-2023, 07:42 PM
            8 responses
            1,349 views
            0 likes
            Last Post Johng22
            by Johng22
             
            Started by ETFVoyageur, 04-30-2024, 02:04 PM
            11 responses
            100 views
            0 likes
            Last Post ETFVoyageur  
            Started by bubblegum, 03-18-2024, 10:41 AM
            3 responses
            45 views
            0 likes
            Last Post vjsworld  
            Started by JamesK1, Today, 02:48 PM
            1 response
            13 views
            0 likes
            Last Post JamesK1
            by JamesK1
             
            Started by llanqui, Today, 03:51 PM
            0 responses
            13 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Working...
            X