• 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

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

    SendMail

    Hey all, I'm trying to send an email alert with a few different values. I'm sure there is a simple solution to this, but I can't seem to find it in the help files.

    For example, to send a single value, in this case a MIN, I have been using:

    SendMail(@"[email protected]", @"Subject", @"MIN1: " + MIN1[0]);

    How do I send multiple values? Like if I wanted to send the values for: MIN1[0], MAX1[0], Position.AveragePrice, myOrder.LimitPrice, etc.

    Also, is there a way to add any formatting in the email sent? Like put in new line, or new paragraph?

    If this is actually possible, then if you could just point me in the right direction I'll figure it out.

    Thanks again for your help!
    -Michael

    #2
    Hello RobotSyndicate,

    In this case, I would suggest using a feature/method of C# called string.Format().

    This simplifies making long strings that contain variables.

    You could do something like the following to concatenate some values into a string:

    Code:
    string myString = string.Format("{0} - {1} - {2}", Close[0], Open[0], High[0]);
    SendMail(@"[email protected]", @"Subject", myString );
    There are many formats you can specify, the {0}, {1} and {2} are just placeholders for the variables that come after the string. You can read more about this method in the following links:

    https://www.dotnetperls.com/format


    You can also just use the plus symbol as you are now but this can become long or complicated, in any case, this is how you would do that:

    Code:
    string myString = "MIN1: " + MIN1[0] + " MIN2:" + MIN2[0];
    SendMail(@"[email protected]", @"Subject", myString );
    For other formatting in the email, this is something you would need to test to see how your email client displays the result. In most cases you can use new lines in strings like the following:

    Code:
    string myString = "line one \n line two";
    You may also be able to use HTML syntax in the string and have it displayed, this will depend on the email client so this is something that would need to be tested.


    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 12-18-2018, 09:33 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse, thanks for the GREAT answer! I'll dive into it.

      Take care,
      Michael

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by pstrusi, Today, 09:06 AM
      0 responses
      4 views
      0 likes
      Last Post pstrusi
      by pstrusi
       
      Started by vpzdcv, Today, 02:31 AM
      0 responses
      9 views
      0 likes
      Last Post vpzdcv
      by vpzdcv
       
      Started by YevhenShynkarenko, Today, 01:22 AM
      1 response
      20 views
      0 likes
      Last Post YevhenShynkarenko  
      Started by ttodua, Today, 12:52 AM
      0 responses
      8 views
      0 likes
      Last Post ttodua
      by ttodua
       
      Started by ttodua, Today, 12:50 AM
      0 responses
      8 views
      0 likes
      Last Post ttodua
      by ttodua
       
      Working...
      X