Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SendMail with Price?

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

    #31
    Hi dsraider,

    What CalculateOnBarClose settings are you using?

    If set to false, the condition, and the SendMail() could be executed more than once.

    You can use Print() statements to debug to verify that the conditions are indeed being met multiple times.
    TimNinjaTrader Customer Service

    Comment


      #32
      Hi Tim,

      My CalculateOnBarClose is set to false but my EntriesPerDirection = 1 so I'm only getting one trade at a time. That's why I'm not following you guys about multiple emails. Still, someone on another site suggested using a flag like Ben did, so I'm currently working on the code. He also suggested using "entryOrder1.AvgFillPrice" and "exitOrder2.AvgFillPrice" and those worked perfectly.

      For target and stop, how do I get it to filter as an IOrder? Adding "private IOrder target = null;" was easy enough but NT didn't like "target = SetProfitTarget("", CalculationMode.Ticks, 80);" and I'm assuming using a breakeven and trail has its own complications.

      Thanks,
      Dave

      Comment


        #33
        Hi dsraider,

        If you want to use Set() method to modify the price as a Stop Loss and Profit Target, please see this sample - http://www.ninjatrader.com/support/f...ead.php?t=3222
        There you'll see a breakeven approach.

        To monitor Profit Target and Stop Losses, please see - http://www.ninjatrader.com/support/f...ead.php?t=5790

        More info on IOrders - http://www.ninjatrader-support.com/H...de.html?IOrder
        TimNinjaTrader Customer Service

        Comment


          #34
          Well,

          I've been working hard on this but have the following issues:

          1. Sometimes it enters upon a cross. Sometimes it doesn't.
          2. Sometimes it emails on entry and exit. Sometimes it doesn't.
          3. My exit signal will only work if my stop loss is moved to breakeven. Otherwise, it is ignored.
          4. Filling of Target or Stop Loss results in no email.
          5. Filling of Exit results in "ES Long Exit Filled 1170: 0" (instead of actual profit/loss).
          6. In the output window, lastProfit only works with the first trade and doesn't change thereafter.

          My guess is that some things are resetting after the first trade and some thing aren't but I'm currently at a loss. If you have a few minutes, would you mind taking a look around?

          Thanks,
          Dave
          Attached Files

          Comment


            #35
            Hello,

            I am sorry, we don't debug systems for people. Try going here to narrow it down and post a specific question so we can help you:
            DenNinjaTrader Customer Service

            Comment


              #36
              Fair enough, Ben. Thanks for the link.

              Dave

              Comment


                #37
                Okay, I have a specific question. I can't seem to get my stops or targets to email me when filled. As I assume they are similar in code, this is what I have for stop:

                Variables
                private bool stopSent = false;
                private ArrayList stopLossTokens = new ArrayList();

                protected override void OnBarUpdate() <---using this for breakeven/trail
                SetStopLoss("Name", CalculationMode.Ticks, 12, false);

                protected override void OnOrderUpdate(IOrder order)
                if(order.OrderState == OrderState.PendingSubmit)
                {
                if(order.name == "Name")
                stopLossTokens.Add(order.Token);
                }

                if(stopLossTokens.Contains(order.Token))
                {
                if(order.OrderState == OrderState.Filled && stopSent == false)
                {
                SendMail("", [email protected], Instrument.MasterInstrument.Name + " Name Stop Filled " + order.AvgFillPrice, "");
                stopSent = true;
                stopLossTokens.Remove(order.Token);
                }
                }

                It's the same for targets. While both submit orders and work fine, I'm just not getting the emails. Any suggestions?

                Thanks,
                Dave

                Comment


                  #38
                  Hi dsraider,

                  First, you need a valid "From email address" field, you can use [email protected]

                  Also, keep in mind this will only work in real time.

                  More info at - http://www.ninjatrader-support.com/H...html?SendMail1
                  TimNinjaTrader Customer Service

                  Comment


                    #39
                    Hi Tim,

                    Actually, "" works just fine as it emails me my entries and when my stop moves to even. Same for exits. It's just the stops and targets that won't work.

                    Is there something wrong with my code?

                    Thanks.

                    Comment


                      #40
                      Hi dsraider,

                      Have you used Print() to ensure your condition...
                      Code:
                      if(order.OrderState == OrderState.Filled && stopSent == false)
                      is being met and entered?

                      From there, you may need to debug your list that stores the token to ensure you are accessing the ones you expect.
                      TimNinjaTrader Customer Service

                      Comment


                        #41
                        Funny you should mention that. My output window stopped working yesterday. It shows up in the task bar but refuses to open on my screen. I've tried restarting NT and my computer but nothing happened. Before that, though, I did use Print(). Nothing printed, so I'm not sure which step to take next.

                        I use "entryOrder1 = ..." and exitOrder1 = ..." for entry and exit. Both work fine. Do I need to code this way for stops and targets and add private IOrders under Variables? Nothing I've tried seems to work so I scoured the sample strats and came up with what I posted. I'm sure there has to be a way to have a strat email when its stop or target is filled but I just can't seem to find the missing piece.

                        Thanks,
                        Dave

                        Comment


                          #42
                          Hi dsraider,

                          It sounds like it may have gotten hidden somewhere, please try the following.

                          Right click it on the Windows Taskbar, and select "Move" (if grayed out, left click then right click once more).
                          Now, use the arrows keys for a few seconds, now move the mouse until the window comes in to view.


                          If you reference the incorrect token, you will not get the Print()

                          After that consider simplifying your code without the lists for monitoring the Stops and Target for your tests.
                          TimNinjaTrader Customer Service

                          Comment


                            #43
                            Tim,

                            Thanks for the tip in reference to the output window. I'll have to try that when I get home as I am currently at the office.

                            With respect to the code, I'd be happy to simplify but just don't know how. Do you have an example to which you can point me? The problem I ran into was that stopOrder = SetStopLoss() caused an error, as did the same for target. So, I ended up reading whatever I could find and came across the stop/target monitor code.

                            Thanks,
                            Dave

                            Comment


                              #44
                              Hi dsraider,

                              Please refer to the reference sample - http://www.ninjatrader.com/support/f...ead.php?t=5790
                              TimNinjaTrader Customer Service

                              Comment


                                #45
                                Good news: the output window now shows. Thanks for that.

                                Bad news: I've already been through that Sample Strat and have tried to incorporate it into mine but it didn't help (or I did it wrong). Can you take a look at the code I posted again and see if I made an error?

                                Thanks,
                                Dave

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, Yesterday, 10:06 AM
                                0 responses
                                20 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                18 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
                                38 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X