Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StrategyBase.Orders.Count == 0 in SA

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

    StrategyBase.Orders.Count == 0 in SA

    NT8 release version 8.0.1.0
    StrategyBase.Orders is a collection of all orders that the managed order entry API maintains.
    I find this collection is populated and I can find the last filled order with this code:
    Code:
    IEnumerable<Order> myLongEntryOrders = OrdersFilled( "LE", OrderAction.Buy);
    
    public IEnumerable<Order> OrdersFilled(String strOrderName, OrderAction orderAction)
          {
             return m_ninjaStrategy.Orders.Where(o => o.Name == strOrderName && o.OrderAction == orderAction && o.Filled > 0);
    
          }
    This works fine in realtime ( in Replay or live ).

    However it doesn’t work in the Strategy Analyzer (SA). When run in SA I find that

    Code:
    Position.MarketPosition != Position.Flat && Orders.Count == 0
    In other words, even though the strategy has entered a position, the Orders collection remains empty ( in SA only ).

    Is the SA considering the Orders collection to be a part of the Performance object and only populating it at the end of the run?

    I wrote my strategy to use the Orders property/object rather maintain my own orders collection. But if SA doesn’t populate it then I can’t use the Orders collection at all. By the time I finish developing a strat that must use my own Orders collection I would not bother to switch back to the StrategyBase version of it when running live.

    I attached a screen shot showing MarketPosition.Postiion == MarketPostiion.Long.
    I also attached the strategy I used to demonstrate.
    You can run it in SA as well as in Replay and you'll see the difference in the output window.


    Can you confirm and log as a bug?
    Attached Files

    #2
    Order collection

    Jumping ahead I've fixed this problem by maintaining my own collection as follows:

    Code:
       public class MyNinjaStrategyBase : Strategy
       {
          protected Collection<Order> m_orders = new Collection<Order>();
          public [B]new[/B] Collection<Order> Orders { get { return m_orders; } }
          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
          {
             base.OnOrderUpdate(order, limitPrice, stopPrice, quantity, filled, averageFillPrice, orderState, time, error, comment);
             if (order.OrderState == OrderState.Submitted)
                m_orders.Add(order);
          }
       }
    You can put this in a separate file and derive your own strategy from this instead of the Ninja Strategy.class. As always,if you override OnOrderUpdate in your derived class make sure you call base.OnOrderUpdate( ... ) otherwise this code won't run.

    There's still a bug in the Ninja code but this gets around it for now.

    Comment


      #3
      Hello,

      Thank you for the post.

      I would be happy to look into this further, can you provide a sample that does not reference your third party indicators and instead uses stock items for testing purposes?

      It looks like there is logic associated with GWTriDiffNT8 and AtsADXVMA, unfortunately it seems there is logic revolving around these items, so I would be unable run the same test as you are.

      For testing, could you eliminate these two items reduce the code to only what is needed to show the collection question? If other indicators are needed to demonstrate the question at hand, could you replace the custom items with stock items such as the SMA so this can be tested on other PC's other than your own?

      I look forward to being of further assistance.

      Comment


        #4
        Hi Jesse,
        See attached for new version that eliminates those indicators.
        Attached Files

        Comment


          #5
          Hello,

          Thank you for providing this test I am able to run this version.

          I do see that you are using the Order collection, but I do not see any documentation for this property leading me to believe this is possibly used for internal reasons. I will post a question to development to see if this item can be used for NinjaScript uses and if so, what stipulations this property has surrounding its use.

          To locate the prior orders, you could either collect the orders yourself as you had previously described or use the TradeCollection items where you can to locate trades: http://ninjatrader.com/support/helpG...collection.htm

          When I have further details on the specific Orders collection I will reply back.

          I look forward to being of further assistance.

          Comment


            #6
            Hello,

            To reply on this item, this collection was not intended to be used by users and was not documented. This is used for internal items only.

            It would instead be suggested to create your own collection and only use that as this collection has no expectations and may work differently than you expect in actual trading scenarios.

            Please let me know if I may be of further assistance.

            Comment


              #7
              Thanks Jesse,
              I'm keeping my own collection now using the technique I posted. Seems to be working fine.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              66 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              141 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              76 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              47 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              51 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X