Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendMail with Price?

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

    #76
    Hi Tim,

    I'm trying to get SendMail() to include PnL so I get something like: ES Stop Filled: +3.5. I'm now trying to define var1 in variables but keep getting error messages. It doesn't like private int or private double. Is there one I should be using?

    Thanks,
    Dave

    Comment


      #77
      Hi dsraider,

      If you are including the "+", you can try a string type. You may want to separate the variable to include your just the number value, as a double then add the + in the SendMail()
      TimNinjaTrader Customer Service

      Comment


        #78
        Hi Tim,

        I admit not knowing what you mean exactly but can you tell me why lastTrade works perfectly and lastTrade.ProfitPoints stops my strat from working? From everything I've read, I don't understand why that would be an issue and I think that's what's stopping my progress.

        Thanks,
        Dave

        Comment


          #79
          Dave,

          There may be a point in time when lastTrade is empty or null and trying to access its properties when it is in such a state will cause problems. If you are just accessing the object itself it won't have an issue telling you it is empty though. This all depends on your code and when exactly you are printing.
          Josh P.NinjaTrader Customer Service

          Comment


            #80
            I'm waiting for this thread to hit 100 posts. This is my small contribution.
            UNBELIEVABLE

            Comment


              #81
              Hey Josh,

              I tried the following but it caused it not to email at all:

              PHP Code:
              if (stopLossTokens.Contains(order.Token))
                          {
                              // Check order for terminal state
                              if (order.OrderState == OrderState.Filled)
                              {
                                  if(lastTrade != null)
                                  {    
                                  // Print out information about the order
                                  Print(order.ToString());
                                  SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Stop Filled " + order.AvgFillPrice + ": " + (lastTrade.ProfitPoints/4 >= 0 ? "+" + Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4)), "");
                                  Print("SendMail: " + Instrument.MasterInstrument.Name + " Cross2050 Stop Filled " + order.AvgFillPrice + ": " + lastTrade.ProfitPoints);
                                  }
                              if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)    
                                  // Remove from collection
                                  {
                                  stopLossTokens.Remove(order.Token);
                                      entryOrder1 = null;
                                      entryOrder2 = null;
                                  }
                                  
                              }
                              // Print out the current stop loss price
                              else
                                  Print("The order name " + order.Name + " stop price is currently " + order.StopPrice);
                          } 
              
              Am I on the right track?

              Thanks.

              P.S. That makes 81, Baruch.

              Comment


                #82
                Hi dsraider,

                I suggest removing all the email stuff for now and just focus on debugging this. Add unique Print() statements inside each level of "if" conditions to ensure each condition is being entered.
                TimNinjaTrader Customer Service

                Comment


                  #83
                  Turns out all I had to do was combine some code. If anyone is interested, this is the working result:

                  PHP Code:
                  if (stopLossTokens.Contains(order.Token))
                              {
                                  // Check order for terminal state
                                  if (order.OrderState == OrderState.Filled && stopSent == false)
                                  {
                                      // Print out information about the order
                                      if (Performance.RealtimeTrades.Count > 0) 
                                          {     
                                              // Get the last completed real-time trade (at index 0) 
                                              Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
                   
                                              if (lastTrade != null) 
                                              {
                                                  if(lastTrade.ProfitPoints >= 0)
                                                  {    
                                                  Print("The last trade profit is " + (lastTrade.ProfitPoints >= 0 ? "+" + Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints/4)));
                                                  SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Stop Filled " + order.AvgFillPrice + ": +" + lastTrade.ProfitPoints, "");
                                                  stopSent = true;    
                                                  }
                                                  else 
                                                  {
                                                      Print("The last trade profit is " + (lastTrade.ProfitPoints >= 0 ? "+" + Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints)));
                                                      SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Stop Filled " + order.AvgFillPrice + ": " + lastTrade.ProfitPoints, "");
                                                  stopSent = true;
                                                  }
                                              } 
                                          }    
                                  if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)    
                                      // Remove from collection
                                      {
                                      stopLossTokens.Remove(order.Token);
                                          entryOrder1 = null;
                                          entryOrder2 = null;
                                      }
                   
                                  }
                                  // Print out the current stop loss price
                                  else
                                      Print("The order name " + order.Name + " stop price is currently " + order.StopPrice);
                              }
                   
                   
                              // Process profit target orders
                              if (profitTargetTokens.Contains(order.Token))
                              {
                                  // Check order for terminal state
                                  if (order.OrderState == OrderState.Filled && targetSent == false)
                                  {
                                      // Print out information about the order
                                      if (Performance.RealtimeTrades.Count > 0) 
                                          {     
                                              // Get the last completed real-time trade (at index 0) 
                                              Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
                   
                                              if (lastTrade != null)
                                              Print("The last trade profit is " + (lastTrade.ProfitPoints >= 0 ? "+" + Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints/4)));
                                              SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Target Filled " + order.AvgFillPrice + ": +" + lastTrade.ProfitPoints, "");
                                              targetSent = true;
                                          }
                                      if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)
                                      {    
                                      // Remove from collection
                                      profitTargetTokens.Remove(order.Token);
                                          entryOrder1 = null;
                                          entryOrder2 = null;
                                      }
                                  }
                   
                                  // Print out the current stop loss price
                                  else
                                      Print("The order name " + order.Name + " limit price is currently " + order.LimitPrice);
                              }  
                          } 
                  
                  Dave
                  Last edited by dsraider; 06-14-2010, 12:22 PM.

                  Comment


                    #84
                    Interesting topic!

                    Is it also possible to send a screen-shot of the chart by mail?

                    Comment


                      #85
                      Hi Rienb,

                      Unfortunately not. For you reference here is the SendMail() parameters.
                      TimNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

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