Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest account raises Exceptions when creating Order

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

    Backtest account raises Exceptions when creating Order

    I'm trying to backtest a strategy, I'm neither using the managed or unmanaged order submission. I am currently trying to submit directly against the backtest account, to backtest my strategy which I'm running in the StrategyAnalyzer but I keep getting NullpointerException. I have verified that the account object has been properly initialized

    Exception

    all values are set except CustomOrder which I have as null
    PHP Code:
    System.NullReferenceException: Object reference not set to an instance of an object.
       at NinjaTrader.Cbi.Account.CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, TimeInForce timeInForce, Int32 quantity, Double limitPrice, Double stopPrice, String oco, String name, CustomOrder customOrder) 
    

    Account Initialization

    PHP Code:
    account = Account.All.FirstOrDefault(a => a.Name == "Backtest");
    if (account != null) {
    LOGGER.Debug("Adding events listeners to  " + account);
    account.ExecutionUpdate += OnExecutionUpdate;
    account.OrderUpdate += OnOrderUpdate;
    account.PositionUpdate += OnPositionUpdate;
    } 
    

    Order Creation and Submission

    PHP Code:
    double tickBreakLong = SMA(Low, 5)[0] + 5 * TickSize;
    
    entryOrder = account.CreateOrder(Instrument,
    OrderAction.Buy,
    OrderType.StopMarket,
    TimeInForce.Gtc,
    1,
    0,
    tickBreakLong,
    string.Empty,
    "Long_Entry",
    null);
    
    
    account.Submit(new []{entryOrder});
    //LOGGER.Debug("Submitted Order " + entryOrder); 
    
    Click image for larger version

Name:	image.png
Views:	155
Size:	342.8 KB
ID:	1234089
    Last edited by psytopy; 02-04-2023, 10:55 PM.

    #2
    Hello psytopy,

    Thanks for your post.

    Backtest orders are virtual and are not submitted to an account. Further, there is no specific account for backtests since they are not submitted to an account.​

    Instead, you could consider submitting orders to the Sim101 account.

    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks for you response NinjaTrader_BrandonH​,
      is there a way of using account.CreateOrder approach and be able to run it through strategy analyzer and see the performance? I tried using the Sim101 account it didnt show any data.

      -Thanks

      Comment


        #4
        Hello psytopy,

        Thanks for your note.

        When using Account.CreateOrder() to submit orders, testing the script could be done by using the Playback connection instead of the Strategy Analyzer. This is because the Playback connection uses a Playback101 account for submitting orders to and the Strategy Analyzer does not submit orders to any account.

        Playback: https://ninjatrader.com/support/help...connection.htm

        Please let me know if Imay assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        59 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X