Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing strategy activity/order data

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

    Accessing strategy activity/order data

    I am currently writing a mechanism that allows me to be emailed if an order is being executed. I assume this is pretty trivial for regular orders but I have the following questions:
    • Does NT have a special library for sending emails or do I need to bind in a default C# lib?
    • How can I derive the current strike price of the underlying when an order is being triggered?
    • Is there a log of all current/recent orders of my strategy and positions that I can access programatically?
    • Can I somehow determine if there is an open position right now?
    • How can I be alerted when an 'automated' ExitOnClose happens? After all I can do this programatically (and have the code for that) but prefer to use the strategy flag for that.
    Any input would be greatly appreciated.

    Thanks!

    Michael

    #2
    Hi Michael,

    1. You can use SendMail() - http://www.ninjatrader-support.com/H...SendMail1.html

    2. Unfortunately we don't support options trading.

    3. You can take a look at the TradeClass - http://www.ninjatrader-support.com/H...radeClass.html

    4. You can check with Position.MarketPosition or Positions if in a MultiTime/Instrument context.

    5. Unfortunately not.

    Comment


      #3
      Perfect

      Responses below:
      1. Perfect!
      2. I misspoke - I was actually referring to the current price of the futures contract - just want to log at which spot price I'm buying/selling.
      3. This looks interesting - but can I get a whole list of, let's say, the last 10 orders or only the last one?
      4. Perfect. I assume I get a null if there is none?
      5. I guess I have to sling my own code then.
      Thanks Bertrand :-)

      Comment


        #4
        Hi Michael,

        2. You can use OnMarketData() for this and use the type 'Last' - http://www.ninjatrader-support.com/H...arketData.html

        3. For this use the TradesCollection class then - http://www.ninjatrader-support.com/H...tionClass.html

        4. You can check for MarketPostion.Flat

        Comment


          #5
          Thanks!

          That should get me going - appreciate the help Bertrand

          Comment


            #6
            One more

            I just realized that the stop loss order is being handled internally as well by NT6. Is there a way to hook into that, so I can send myself an email when a stop loss order is being executed?

            Thanks!

            Michael

            Comment


              #7
              Sure you could work with the IOrder object directly for that - http://www.ninjatrader-support.com/H...V6/IOrder.html

              Comment


                #8
                Details?

                Originally posted by NinjaTrader_Bertrand View Post
                Sure you could work with the IOrder object directly for that - http://www.ninjatrader-support.com/H...V6/IOrder.html
                Okay, I'm not sure what I would have to do here. I'm setting my stop loss order like this:

                SetStopLoss("", CalculationMode.Ticks, StopLoss, false);

                Now, all I want is to send myself an email when that one is being executed. I've done enough Java coding (15 years) that I understand the concept of an interface and that this is probably somehow thread driven and can be hooked into. But so that I don't have to spend another six hours on this - if you have an example of how to do this quickly and simply with some pseudo-code I would appreciate it.

                Thanks,

                Michael

                Comment


                  #9
                  Michael,

                  In OnExecution() method. When you receive an IExecution from an order with a string of "Stop loss" then you know this order was filled. You can then send yourself an email.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Say what?

                    Originally posted by NinjaTrader_Josh View Post
                    Michael,

                    In OnExecution() method. When you receive an IExecution from an order with a string of "Stop loss" then you know this order was filled. You can then send yourself an email.
                    I don't know this method. Can you PLEASE post a rough example? I don't know what else I have to do in order to make this work. Would really appreciate your help as I'm hoping to get this done over the weekend.

                    Thanks!!

                    Michael

                    Comment


                      #11
                      Michael,

                      You can find an example in the reference samples section of the forums. http://www.ninjatrader-support2.com/...ead.php?t=7499

                      Now it doesn't do what you want exactly, but should be enough to give you leeway into the matter. You just want to check the IExecution's name.

                      Code:
                      if (execution.Order.Name == "Stop loss")
                      {
                           SendMail(...);
                      }
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Doesn't work

                        Originally posted by NinjaTrader_Josh View Post
                        Michael,

                        Code:
                        if (execution.Order.Name == "Stop loss")
                        {
                             SendMail(...);
                        }
                        Well, the problem is that this doesn't work with backtesting. I'm setting my entry order like this:

                        Code:
                        entryOrder = EnterShort(1, DefaultQuantity, "Short Position");
                        In my OnExecution method I do have a flag that checks for open orders:

                        Code:
                        if (entryOrder != null)
                        {
                        Log("Got here", LogLevel.Information);
                        ...
                        }
                        Well, my log is never hit - I have to put it outside the if statement for it to work.

                        Is there something I'm missing? I'm trying to replicate the SampleOnOrderUpdate strategy but this does not seem to work.

                        Comment


                          #13
                          molecool,

                          SendMail() never works in backtest. It is a real-time only method. If your Log() is never reached it would mean you are never getting in there. Add a print outside of it to see if you are even going into OnExecution().
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Josh View Post
                            molecool,

                            SendMail() never works in backtest. It is a real-time only method. If your Log() is never reached it would mean you are never getting in there. Add a print outside of it to see if you are even going into OnExecution().
                            Thanks Josh - that's not what I was asking but I found out what prevented my log to be hit. However, your comment is very valuable as this was something I had been wondering about. If I use SendMail() and perform a backtest - am I going to get dozens/hundreds of emails? Based on your comment it seems you guys are preventing this from happening. Can you confirm that this is correct?

                            Comment


                              #15
                              Correct Michael, SendMail will work in realtime not in the backtest.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              574 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              333 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X