Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendMail with Price?

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

    #61
    Bertrand,

    Thank you for that. Luckily, it compiled, but I keep running into one other issue. For whatever reason, my strat seems to freeze and sometimes not take trades. This example is a simple 20/50 cross, so I'm sure it's not that. Still, I can't figure out why. Does the following mean anything to you?:


    5/27/2010 1:04:20 AM Entered internal PlaceOrder() method at 5/27/2010 1:04:20 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Cross2050' FromEntrySignal=''
    5/27/2010 1:04:20 AM Enter Short

    5/27/2010 1:04:20 AM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Sim101' Name='Profit target' State=Working Instrument='YM 06-10' Action=Sell Limit price=10053 Stop price=0 Quantity=1 Strategy='Cross2050' Type=Limit Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='8f0317777a2a4849bc3b5e273d135e4c' Gtd='12/1/2099 12:00:00 AM'
    The order name Profit target limit price is currently 10053
    The order name Profit target limit price is currently 10053
    5/27/2010 1:04:20 AM Cancelled pending exit order, since associated position is closed: Order='NT-00001/Sim101' Name='Stop loss' State=Working Instrument='YM 06-10' Action=Sell Limit price=0 Stop price=10002 Quantity=1 Strategy='Cross2050' Type=Stop Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='4364528086664b73b3177426c7b30ed7' Gtd='12/1/2099 12:00:00 AM'
    The order name Stop loss stop price is currently 10002
    The order name Stop loss stop price is currently 10002
    The order name Stop loss stop price is currently 10002
    The order name Stop loss stop price is currently 10002
    The order name Stop loss stop price is currently 10002
    The order name Profit target limit price is currently 9931
    The order name Profit target limit price is currently 9931
    The order name Profit target limit price is currently 9931
    entryOrder2 = null
    5/27/2010 1:04:20 AM Cancelled pending exit order, since associated position is closed: Order='NT-00006/Sim101' Name='Profit target' State=Working Instrument='YM 06-10' Action=BuyToCover Limit price=9931 Stop price=0 Quantity=1 Strategy='Cross2050' Type=Limit Tif=Gtc Oco='NT-00002' Filled=0 Fill price=0 Token='c1c43079daa040dba0fd0c2f7939925f' Gtd='12/1/2099 12:00:00 AM'
    The order name Profit target limit price is currently 9931
    The order name Profit target limit price is currently 9931
    Order='NT-00005/Sim101' Name='Stop loss' State=Filled Instrument='YM 06-10' Action=BuyToCover Limit price=0 Stop price=10002 Quantity=1 Strategy='Cross2050' Type=Stop Tif=Gtc Oco='NT-00002' Filled=1 Fill price=10011 Token='43bb98ddd489437c83e6cced24455a9c' Gtd='12/1/2099 12:00:00 AM'
    5/27/2010 1:04:20 AM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00006/Sim101' Name='Profit target' State=Cancelled Instrument='YM 06-10' Action=BuyToCover Limit price=9931 Stop price=0 Quantity=1 Strategy='Cross2050' Type=Limit Tif=Gtc Oco='NT-00002' Filled=0 Fill price=0 Token='c1c43079daa040dba0fd0c2f7939925f' Gtd='12/1/2099 12:00:00 AM'

    That's what I get in the output window the instant I start my strat. Then.....nothing. I can't seem to figure out why it sometimes happens and sometimes doesn't.

    Dave

    Comment


      #62
      Hi Dave, looks ok to me from afar - the oco'ed target for example is cancelled as your stop is filled..please comment out anything else besides the pure signal generation in the strategy and then recheck if this works as you would expect, then you can add complexity from this point on and recheck at each step.

      Comment


        #63
        Ahhhhhh, good idea. Can you call my boss and tell him I'm going to be very late today? On thing, though.....the date says 5/27 and this is from yesterday, 5/31. Does that mean anything???

        Thanks, Bertrand.

        Dave
        Last edited by dsraider; 06-01-2010, 05:20 AM.

        Comment


          #64
          Okay, as far as defining a variable is concerned, this works:


          PHP Code:
          Variables
          private Trade     lastTrade; 
          
          The rest is weird. I changed lastTrade to lastTrade.ProfitPoints in SendMail() and it's brought my strat to a hault. Anyone know why?

          Also, the first entry works as it's supposed to but after that, the entries no longer email or print. Is there anything wrong with what I have?

          PHP Code:
          {
          if (entryOrder1 != null && entryOrder1.Token == order.Token
                        && entryOrder1.OrderState == OrderState.Filled
                          && longSent == false)
                  {
                  SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Long " + entryOrder1.AvgFillPrice, "");
              Print("Sendmail: " + Instrument.MasterInstrument.Name + " Cross2050 Long " + entryOrder1.AvgFillPrice);
              longSent = true;
              }
          } 
          
          Thanks,
          Dave
          Last edited by dsraider; 06-01-2010, 08:10 PM.

          Comment


            #65
            Hi dsraider,

            Is your code meeting and entering the condition? Do you reset the bool longSet anywhere?
            TimNinjaTrader Customer Service

            Comment


              #66
              Hi Tim,

              It trades every time like it should but I just stop getting the emails/print. Is longSent == false and longSent == true (in my posted code) not enough to reset?

              Thanks,
              Dave

              Comment


                #67
                Hi dsraider,

                Make sure you code is entering and executing the condition, I don't see where you reset the bool back to false.
                Last edited by NinjaTrader_Tim; 06-02-2010, 06:22 AM.
                TimNinjaTrader Customer Service

                Comment


                  #68
                  Hello again,

                  It's the last line of the following:

                  PHP Code:
                  { 
                  if (entryOrder1 != null && entryOrder1.Token == order.Token 
                                && entryOrder1.OrderState == OrderState.Filled 
                                  && longSent == false) 
                          { 
                          SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Long " + entryOrder1.AvgFillPrice, ""); 
                      Print("Sendmail: " + Instrument.MasterInstrument.Name + " Cross2050 Long " + entryOrder1.AvgFillPrice); 
                      longSent = true; 
                      } 
                  } 
                  
                  Maybe I did it wrong?

                  Comment


                    #69
                    Hi dsraider,

                    Where is the bool set back to false?
                    TimNinjaTrader Customer Service

                    Comment


                      #70
                      Well, here's my relevant variables code:

                      PHP Code:
                      Variables
                      private bool     longSent                 = false; 
                      
                      Should I change or add something?

                      Thanks,
                      Dave

                      P.S. Should I post the strat?
                      Last edited by dsraider; 06-02-2010, 07:00 AM.

                      Comment


                        #71
                        Hi dsraider,

                        I see the bool is initially set to false in the variables, but do you ever reset it to false after you set it to true for the first time the condition is met?
                        TimNinjaTrader Customer Service

                        Comment


                          #72
                          Ahh...no, sir, I do not. Would this work?

                          PHP Code:
                          {  
                          if (entryOrder1 != null && entryOrder1.Token == order.Token  
                                        && entryOrder1.OrderState == OrderState.Filled  
                                          && longSent == false)  
                                  {  
                                  SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Long " + entryOrder1.AvgFillPrice, "");  
                              Print("Sendmail: " + Instrument.MasterInstrument.Name + " Cross2050 Long " + entryOrder1.AvgFillPrice);  
                              longSent = true;  
                          longSent = false;
                              } 
                          
                          or would that just end up causing multiple emails?

                          Thanks,
                          Dave

                          Comment


                            #73
                            Hi dsraider,

                            Your condition includes a bool check...
                            Code:
                            if (... && longSent == false)
                            if you reset...

                            longSent = false;

                            the condition may repeat itself.

                            You may want to reset the bool in your next entry.
                            TimNinjaTrader Customer Service

                            Comment


                              #74
                              Bingo! Entries now email each and every time. Thanks for that.

                              Okay, for (what I hope is) the last piece, any idea why:

                              PHP Code:
                              SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Stop Filled " + order.AvgFillPrice + ": " + lastTrade, ""); 
                              
                              works (though it posts "ES Stop Filled 1085:"? and...

                              PHP Code:
                              SendMail("", "[email protected]", Instrument.MasterInstrument.Name + " Cross2050 Stop Filled " + order.AvgFillPrice + ": " + lastTrade.ProfitPoints, ""); 
                              
                              not only doesn't work but shuts my strat down completely?

                              Also, since I'd like to add "+" to positive trades, is there anyway to include the following into my SendMail() code? It works perfectly with Print():

                              PHP Code:
                              Print("The last trade profit is " + (lastTrade.ProfitPoints >= 0 ? "+" + Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints))) 
                              
                              Thank you,
                              Dave

                              Comment


                                #75
                                Hi dsraider,

                                What are you trying to accomplish with lastTrade.ProfitPoints? Have you tried lastTrade.ProfitPoints.ToString()

                                Have you tried setting this to a variable before the SendMail()

                                var1 = (lastTrade.ProfitPoints >= 0 ? "+" + Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints))

                                Then including it in the SendMail?
                                TimNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, Yesterday, 10:06 AM
                                0 responses
                                17 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                16 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                14 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                9 views
                                0 likes
                                Last Post TheRealMorford  
                                Started by Mindset, 02-28-2026, 06:16 AM
                                0 responses
                                36 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X