Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple sendmail questions

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

    Simple sendmail questions

    I found the information on the sendmail in the help file a bit thin - and could not find answers in the forum for my simple questions.

    The help file provides the following example:

    // Generates an email message
    SendMail("[email protected]", "[email protected]", "Trade Alert", "Buy ES");

    My questions
    Should the first email address be the same as the one captured in Tools>Options>Misc? Or can one use [email protected] as in the example?
    Why should one ever capture an email address here - just when you want to use sendmail?
    The screen reads "SMTP" (leave blank for default)" - what is the default? I looked in the help file again to try and understand - but do not.

    Basically I want to be able to sendmail based on triggers in my strategy - please explain what I should do for sendmail to work

    Verge

    #2
    verge, just use the 'from' address you wish to use, most likely your own - this does not correlate with the email address entered under Tools > Options > Misc, as this is the standard support email address and you should not change this.

    When leaving the SMTP server at default > the NinjaTrader SMTP server is used, you can of course also enter your own / ISP one in those settings as explained here -

    Comment


      #3
      Position.AvgPrice in sendmail

      I have a question too.
      I send mail : SendMail("[email protected]", "[email protected]", Instrument.FullName, "Buy CL"); It's work. But I want send mail with the price position.

      If I write code: SendMail("[email protected]", "[email protected]", "Buy CL"+ Position.AvgPrice, ""); It's not work. Where does specify price properly?

      Comment


        #4
        Kotyk, where do you have this SendMail command? In the OnBarUpdate() when there is a strategy position actually open?

        Comment


          #5
          Yes, sendmail is In the OnBarUpdate() after enter position. I receive e-mail when strategy enter position but I want also price position (Position.AvgPrice). Really that?

          Comment


            #6
            If you print this on entry only, I would expect no avg price yet present - try moving the call to SendMail to the next bar when the position has actually registered in the OnBarUpdate() for example.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              If you print this on entry only, I would expect no avg price yet present - try moving the call to SendMail to the next bar when the position has actually registered in the OnBarUpdate() for example.
              Why position not registered ? I print sendmail after EnterLong.
              How I moving sendmail to the next bar if I print it to action set (not condition).

              Comment


                #8
                Right, but you are then still on the current bar where you've entered, the position would only be guaranteed to be updated on the bar then. I would just move the sendmail part out of this and preface with

                if (Position.MarketPosition != MarketPosition.Flat)
                ... SendMail...

                Comment


                  #9
                  Thanks.
                  It works but now I received e-mail every 1 min that I have position. How I can do that e-mail not send time after time (one position = one e-mail) ?

                  Comment


                    #10
                    You would either need to code in a bool flag to only send this one time until for example another flat state would reset the flag to allow sending this info out again.

                    Another option is directly going with this snippet / task to the OnPositionUpdate() event only -

                    Comment


                      #11
                      I never use OnPositionUpdate. Please look my code. That's right?
                      protected override void OnPositionUpdate(IPosition position)
                      {
                      if (Position.MarketPosition == MarketPosition.Long)
                      { SendMail("[email protected]", "[email protected]","CL" + Position.AvgPrice, "Buy Cl");
                      }
                      else if (Position.MarketPosition == MarketPosition.Short)
                      { SendMail("[email protected]", "[email protected]", "CL" + Position.AvgPrice, "Sell CL");}
                      }
                      protected override void OnBarUpdate()
                      .......
                      2. How I can put the space between "CL" + Position.AvgPrice?
                      I received e-mail CL106.85 without space?

                      THANKS.

                      Comment


                        #12
                        Looks alright. Just include the space in either string -

                        SendMail("[email protected]", "[email protected]","CL " + Position.AvgPrice, "Buy Cl");

                        Or

                        SendMail("[email protected]", "[email protected]","CL" + Position.AvgPrice, " Buy Cl");

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        661 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        375 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        110 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
                        579 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X