Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order History for an Instrument in a Multi-Instrument Strategy

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

    Order History for an Instrument in a Multi-Instrument Strategy

    I have a Multi Instrument Strategy. I am trying to retrieve if a instrument has traded today. If so was it a long or short. I have done little reading up on the TradeCollection. To get the Date I would need the Execution object. I am having a hard time coding this up. Is there code examples that I can look at?

    #2
    Hello [email protected], and thank you for your questions.

    I am trying to retrieve if a instrument has traded today
    Attached is a code sample that accomplishes this goal. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.

    If so was it a long or short
    You can modify the code sample I presented using information about the Execution object from the help guide.

    http://ninjatrader.com/support/helpG.../execution.htm

    I have done little reading up on the TradeCollection. To get the Date I would need the Execution object.
    The TradeCollection available to your strategy will only contain all the trades placed by your strategy itself, not all the trades placed across strategies. This is why the sample code uses the Account object and checks its Executions instead. If you would like to check TradeCollection values, replace the execution you are looking at by Trade.Entry.

    Our checking function in this case (in a strategy instead of an indicator like I have attached) would look like

    Code:
                foreach(Trade Trade in SystemPerformance.AllTrades)
                {
                    if (Trade.Entry.Instrument.FullName == InstrumentToCheck)
                    {
                        return true;
                    }
                }
                return false;
    Please let us know if there are any other ways we can help.
    Attached Files
    Last edited by NinjaTrader_JessicaP; 03-16-2017, 10:37 AM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thank your very much for your help. I still have the question on how to tell if the trade is one from today and if it is long or short trade.

      IS this code anywhere close to what I would need?

      bool LongTraded = false;
      foreach(Trade Trade in SystemPerformance.AllTrades)
      {
      if (Trade.Entry.Instrument.FullName.CompareTo(BarsArray[BarsInProgress].Instrument)
      && Trade.Entry.Time.Date.CompareTo(ToDay)
      && Trade.Entry.Quantity > 0 )
      {
      LongTraded = true;
      }
      }

      Comment


        #4
        I want to reiterate that SystemPerformance.AllTrades only refers to trades your strategy has placed directly. With this in mind, you can see when a trade has been placed with Execution.Time. If you want to ensure a trade has been place today, you can use

        Code:
        ToTime(Trade.Entry.Time) <= ToTime(Time[0]) && ToDay(Trade.Entry.Time) == ToDay(Time[0])
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Thank-you very much. How would to tell if it was a short or a long trade?

          Comment


            #6
            Execution.MarketPosition, in your case Trade.Entry.MarketPosition, will be one of MarketPosition.Long or MarketPosition.Short depending on the direction of the trade.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Thank-you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bowling, Today, 06:16 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by systemtrader4, Today, 01:54 AM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by Futurestrader00, Today, 01:54 AM
              1 response
              25 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by timmbbo, Today, 01:40 AM
              2 responses
              10 views
              0 likes
              Last Post NT-Roland  
              Started by BGWTEX, Yesterday, 07:20 PM
              0 responses
              7 views
              0 likes
              Last Post BGWTEX
              by BGWTEX
               
              Working...
              X