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:	158
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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        47 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        23 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        33 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        51 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Working...
        X