Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Account.Orders does not collect orders during Strategy Analyzer runs

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

    Account.Orders does not collect orders during Strategy Analyzer runs

    When my custom strategy runs in Historical or Market Replay data, it can use Account.Orders to see the collection of orders, as I would expect.
    However, when running in Strategy Analyzer, Account.Orders stays empty.
    This happens while running managed and unmanaged orders.

    1. Is this as designed? I cannot find this restriction documented anywhere.
    2. Is there any way for a strategy running in Strategy Analyzer to access to the collection of orders?

    thanks, in anticipation.
    Ralph

    Here is my test code, running in a new simple strategy builder created strategy

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Generate orders - If it is a Tick - go long, if a Tock - go short
    if (CurrentBar % 2 == 0) // Tick
    EnterLong(Convert.ToInt32(DefaultQuantity), @"EnterLong");
    else // Tock
    EnterShort(Convert.ToInt32(DefaultQuantity), @"EnterShort");

    // Code to display the no orders collected for all accounts.
    Print(String.Format("NinjaTrader.Cbi.Account.All.C ount={0}", NinjaTrader.Cbi.Account.All.Count));
    foreach (Account TheAccount in NinjaTrader.Cbi.Account.All)
    {
    Print(String.Format("TheAccount.Name={0}. TheAccount.Orders.Count={1}.", TheAccount.Name, TheAccount.Orders.Count));
    foreach (Order ThisOrder in TheAccount.Orders)
    {
    Print(String.Format("ThisOrder.Name={0}. ThisOrder.ThisOrder={1}.", ThisOrder.Name, ThisOrder.OrderState));
    }
    }

    // Alternate code demonstrating the problem using the "Account"
    //Print(String.Format("Account.Name={0}", Account.Name));
    //Print(String.Format("Account.Orders.Count={0}.", Account.Orders.Count));
    //foreach (Order ThisOrder in Account.Orders)
    //{
    // Print(String.Format("ThisOrder.Name={0}. ThisOrder.ThisOrder={1}.", ThisOrder.Name, ThisOrder.OrderState));
    //}
    }


    #2
    Hello Ralph.au,

    That is correct. Historical (backtest) orders are not submitted to an account in real-time. This is by design.
    Instead, historical orders are filled using historical data and a historical back fill algorithm.



    Orders from a strategy are in the Strategy Performance for complete trades.
    SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Entry is the entry and .Exit is the exit order for that trade.



    You can also track orders by assigning them to variables (or arrays) in OnOrderUpdate().

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your help clarifying that Chelsea.

      May I suggest that this historical behaviour be noted in the online Account.Orders documentation?

      I have decided to hide the difference from my strategy code by implementing methods that know whether the strategy is running backtest or not,
      and builds and uses a simulated orders collection when backtesting, or uses the NinjaTrader one when running realtime.

      Regards
      Ralph\

      Comment


        #4
        Hello Ralph,

        I've sent a request for a change to the help guide to state orders placed when State is State.Historical orders are not submitted in real-time to an account.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        18 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        44 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        180 views
        0 likes
        Last Post jeronymite  
        Working...
        X