Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendMail with Price?

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

    SendMail with Price?

    Hi,

    I currently have my strat set up to email me upon entry, breakeven and exit. However, these are just basic notifications and I was wondering if there was a way to add more detail to the message, namely the actual price of entry and exit.

    Thanks,
    Dave

    #2
    You can send such information if you grab it from the TradeCollection object.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Well, I went here: http://www.ninjatrader-support.com/H...helpguide.html but it's gibberish to me. Any other links or a hint?

      Thanks,
      Dave

      Comment


        #4
        Dave,

        What you can do is save your entry price when you are in the trade with Position.AvgPrice. Store it in a variable and then send that variable along with your email. For your exit price you can pretty much grab the price at the time your order was closed to get the exit price. If you are using limit orders you will know the limit price and can just use that instead. Store those into a different variable and also send it in your email.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Sir,

          I'm really flying blindly on this one. Would the following work?:

          Variables
          private IOrder Position.Avg.Price = null;

          ...

          SendMail("", "[email protected]", "Position.Avg.Price", "");

          Thanks,
          Dave

          Comment


            #6
            Dave,

            No, Position.AvgPrice is a variable you would use in OnBarUpdate() directly. Whenever you hold a position. The average entry price for that position is reflected by the Position.AvgPrice variable. You do not need to make an IOrder for this.

            SendMail("", "[email protected]", "Some email subject", "Some email text: My average entry price was: " + Position.AvgPrice);
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh,

              The good news is that it worked. The bad news is it sent me a million emails. I'd like only one when it enters, moves my stop to even and exits. I guess I can't use built-ins like Position.AvgPrice?

              Thanks,
              Dave

              Comment


                #8
                Dave, you can still use Position.AvgPrice to access this info, however you need to be mindful where to issue the SendMail() statement then to avoid duplicate emails, for example you include it as part of your entry rules to send only when you enter and not on each following OnBarUpdate() bar per se.

                Comment


                  #9
                  Hey Bertrand,

                  This is what I did:

                  if (CrossAbove(EMA(20), EMA(50), 1))
                  {
                  entryOrder = EnterLong(DefaultQuantity, "2050 Cross");
                  DrawArrowUp("", true, 0, Low[0] - 12 * TickSize, Color.Blue);
                  DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] - 12 * TickSize, Color.Blue);
                  SendMail("", "[email protected]", "ES Long " + Position.AvgPrice, "");

                  I got about 15 emails before stopping the strat.

                  Comment


                    #10
                    dsraider,

                    When you put it in such a condition you will receive an email every single time that condition is true. If you are using CalculateOnBarClose = false, that condition could be true hundreds of times within a bar. That would mean hundreds of emails.

                    You should limit the number of times you send the email. Use a bool variable within your if-statement.

                    In Variables region of your code
                    Code:
                    private bool someBool = true;
                    In OnBarUpdate()
                    Code:
                    if (CrossAbove(EMA(20), EMA(50), 1))
                    {
                         if (someBool == true)
                         {
                              someBool = false;
                              SendMail(....);
                         }
                    }
                    else
                          someBool = true;
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Josh,

                      I like the idea of using a bool but wouldn't I run into the same issue since my strat's set to CalculateOnBarClose = false? Not sure what I can use as a one-time signal. Would it be easier to go back to Trade or TradeCollection? I didn't really understand that code, though, so I'd need another pointer

                      Dave

                      Comment


                        #12
                        No, you would not run into the same issue. The code in my previous post is a general frame work. You would need to still put in the logic you want for when to reset your bool variable to true. Only when it is true will the mail be sent. Once set to false it will remain false till set back to true in the code again.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Okay, the good news is I got one and ONLY one email. Thanks for that. The bad news is my email read "ES Long 0". Here's my code:

                          Code:
                          if (CrossAbove(EMA(20), EMA(50), 1))
                                      {
                                          entryOrder = EnterLong(DefaultQuantity, "2050 Cross");
                          				DrawArrowUp("", true, 0, Low[0] - 12 * TickSize, Color.Blue);
                          				DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] - 12 * TickSize, Color.Blue);
                          				
                          				if(longEntry == true)
                          				{longEntry = false;
                          				SendMail("", "[email protected]", "ES Long " + Position.AvgPrice, "");
                          				}
                                      }
                          What I do wrong?

                          Thanks.

                          Comment


                            #14
                            At this point of sending the MarketPosition has not registered the long price value yet, so try adding a check for it - if (Position.MarketPosition != MarketPosition.Flat)

                            Comment


                              #15
                              Bertrand and Josh,

                              I've decided that the two of you enjoy torturing me! Today is my birthday and I'm thinking one example of clearly written code would be a great present (hint hint, nudge nudge). It might even get the first to post my drink ticket at next year's expo

                              Dave

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              663 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              376 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
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X