Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendMail() - Quick question: Format Text in rows/paragraphs?

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

    SendMail() - Quick question: Format Text in rows/paragraphs?

    Hey guys,

    I am using the Sendmail() function and everything works as it should.

    As I am sending diverse informations, I would like to know if it possible to break the text into new rows/paragraphs (or format it) to make it look more organized.
    With the current code, the information is send consecutively in one line.

    Code:
    SendMail("[email protected]", "[email protected]", "SYSTEM MONITOR: Attention!", DateTime.Now + " - Instrument: "+Instrument.FullName+" - Strategy Name: "+this.Name+" - Daily Loss in %: "+ Math.Round(dailyPercentageLoss,4)+" - Opening Net Liquidation Value EUR: "+openingAccountValue+"- Current Net Liquidation Value EUR: "+currentAccountValue+" - Daily Loss in EUR: "+dailyAccountLoss);
    I am thankful for your help

    Best wishes
    cNuuuuuu

    #2
    Hello,

    Thank you for the question.

    NinjaScript or C# strings comply to escaped characters so there are a couple of ways to add a new line.

    The most simple is to escape an n character which means new line here is a simple example:

    string testString = "first line \n second line \n third line";

    This should output in the email :
    first line
    second line
    third line

    Here is a full list of escapes: https://msdn.microsoft.com/en-us/library/h21280bw.aspx

    if you find escaping does not work (output window) you can also use the NewLine like so:

    Code:
    string testString = "first line " + Environment.NewLine + " second line " + Environment.NewLine + " third line";
    Print(testString);
    Please let me know if I may be of additional assistance.

    Comment


      #3
      Thanks Jesse, I'll implement your solutions tomorrow!
      But that's exactly what I was searching for

      Comment


        #4
        Thanks Jesse, "new line" works as it should

        In this context I came up with two other quick questions:

        1. What is the difference (if any) between Print(value) and Print(value.ToString())?
        Is toString() less prone to errors?!

        2. I am using the SendMail() function in case my account suffers a certain loss.
        When trading this strategy code with 10 different instruments, I now receive 10 times the same Mail at the same time. How can I avoid this?
        Implementing the SendMail() function to only to one instrument does not seem appropriate, for instance if the strategy/instrument has an error or due to different market opening hours. Is there something like a "Master-Level" where strategies of different instruments can communicate with each other?!

        Comment


          #5
          Hello,

          Thank you for the question.

          ToString is only needed if you get an error in the Print() method or if you are trying to convert an object to a string. Print has overloads for a double, bool, int and DateTime so it would automatically make these into a string.

          A case that you would need to use this would be if you wanted to print an enum for example like the following:

          Print(Position.MarketPosition);

          This would not work but this would:

          Print(Position.MarketPosition.ToString());

          For your second question, it sounds like essentially you are trying to make a collection of all 10 prints in one email. For this there would not really be any supported method or way of doing this as there is not a way to make the scripts communicate with each other.

          You could in theory write all of this information to a file and send that file every X amount of time but that would require some C# that would not really be supported so I couldn't help you there.

          I look forward to being of further assistance.

          Comment


            #6
            ahh okay, thank you very much for your detailed explanation

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X