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.NullReferenceExceptionObject reference not set to an instance of an object.
       
    at NinjaTrader.Cbi.Account.CreateOrder(Instrument instrumentOrderAction actionOrderType orderTypeTimeInForce timeInForceInt32 quantityDouble limitPriceDouble stopPriceString ocoString nameCustomOrder customOrder

    Account Initialization

    PHP Code:
    account Account.All.FirstOrDefault(=> 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(Low5)[0] + 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:	94
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 jaybedreamin, Today, 05:56 PM
        0 responses
        3 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        9 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Working...
        X