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

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:

    Insert values into a string with string.Format. Specify percentages, decimals and padding.



    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, 10: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 kaywai, 09-01-2023, 08:44 PM
      5 responses
      601 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      22 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      19 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Started by agclub, 04-21-2024, 08:57 PM
      3 responses
      17 views
      0 likes
      Last Post TradingLoss  
      Working...
      X