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

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:	101
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.
    Brandon H.NinjaTrader Customer Service

    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.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by leojimenezp, Today, 08:40 AM
        2 responses
        8 views
        0 likes
        Last Post leojimenezp  
        Started by mtamaku, Yesterday, 11:08 AM
        11 responses
        25 views
        0 likes
        Last Post mtamaku
        by mtamaku
         
        Started by ZeroKuhl, Today, 10:22 AM
        0 responses
        3 views
        0 likes
        Last Post ZeroKuhl  
        Started by gyilaoliver, Today, 03:31 AM
        4 responses
        19 views
        0 likes
        Last Post gyilaoliver  
        Started by vit007, Today, 05:09 AM
        3 responses
        28 views
        0 likes
        Last Post backtester831  
        Working...
        X