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:	93
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 TraderBCL, Today, 04:38 AM
        2 responses
        8 views
        0 likes
        Last Post TraderBCL  
        Started by martin70, 03-24-2023, 04:58 AM
        14 responses
        105 views
        0 likes
        Last Post martin70  
        Started by Radano, 06-10-2021, 01:40 AM
        19 responses
        606 views
        0 likes
        Last Post Radano
        by Radano
         
        Started by KenneGaray, Today, 03:48 AM
        0 responses
        4 views
        0 likes
        Last Post KenneGaray  
        Started by thanajo, 05-04-2021, 02:11 AM
        4 responses
        471 views
        0 likes
        Last Post tradingnasdaqprueba  
        Working...
        X