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

CreateOrder / StartArmStrategy

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

    CreateOrder / StartArmStrategy

    Hello NinjaTrader Customer Service,

    I would like to place a simple Order using this code just for testing:

    ...
    public class X01ALLTest1 : Strategy
    {
    private Account accountPlayback101;
    private Instrument instrumentMNQ;
    private Order entryOrder;
    ...
    if (BarsInProgress == 0)
    {
    accountPlayback101 = Account.All.FirstOrDefault(a => a.Name == "Playback101");
    instrumentMNQ = Instrument.GetInstrument("MNQ");
    entryOrder = accountPlayback101.CreateOrder(instrumentMNQ, OrderAction.Buy, OrderType.Market, TimeInForce.Day, 1, 0, 0, string.Empty, "Entry", null);
    NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy("ATM_MNQ", entryOrder);
    ...

    But I'm getting this error:

    Strategie 'X01ALLTest1': Fehler beim Aufruf 'OnBarUpdate' Methode bei Bar 4458: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    Deaktivieren der NinjaScript Strategie ´X01ALLTest1/196030662´


    I have created a simple ATM strategy (Attachment).

    Can you help me? Tank you.

    Thomas


    #2
    Hello,
    Thank you for the post.

    The error relates to an object being null when you tried to use it " The object reference was not set to an object instance. ".

    From the given syntax this could be the Account object or also the Order you created, you will likely need to add some prints to find out what was null before continuing.

    Code:
    accountPlayback101 = Account.All.FirstOrDefault(a => a.Name == "Playback101");
    Print("accountPlayback101 is null: " + (accountPlayback101 == null));
    
    instrumentMNQ = Instrument.GetInstrument("MNQ");
    Print("instrumentMNQis null: " + (instrumentMNQ== null));
    You could do this for each object you have used to find out more about the problem.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I have now created the order via AtmStrategyCreate() and it works. But if I answer the status during the order is working I get always "Filled" for status[2].
      Why is this status not "Working" during the order is running?

      I run a CustomEvent() script for printing the current state:

      ...
      private void CustomEvent(object volume)
      {
      if (State != State.Realtime)
      return;


      Print("isOrderCreated: " + NinjaTrader.NinjaScript.Strategies.X01ALLTest1.isO rderCreated);




      if (NinjaTrader.NinjaScript.Strategies.X01ALLTest1.is OrderCreated == true)
      {
      string[] status = GetAtmStrategyEntryOrderStatus(NinjaTrader.NinjaSc ript.Strategies.X01ALLTest1.orderId);

      // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
      if (status.GetLength(0) > 0)
      {

      Print("status[0]: " + status[0]);
      Print("status[1]: " + status[1]);
      Print("status[2]: " + status[2]);

      ...

      Comment


        #4
        Hello teafortwo,

        In general the atm system in NinjaScript is not as accurate as the managed or unmanaged approach for reporting. You may see discrepancies in reporting from the various ATM methods during different use cases, this is because you are watching an external strategy from your strategy. The status you see will depend on the external ATM and what it is reporting. I could suggest testing the SampleATMStrategy script that comes with NinjaTrader to see if you also see the same when using the known working structure where it reports its status. Otherwise if you need more accurate information from the strategy or orders I would highly suggest moving to the managed or unmanaged approach.

        Please let me know if I may be of additional assistance.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Ok, thank you. But how is the way to see if a order is active at the moment if it has not been completed? I only can see "Filled" with order.OrderState even if I use StartAtmStrategy().

          Comment


            #6
            Hello teafortwo,

            You would use GetAtmStrategyEntryOrderStatus, I just tried the SampleATMStraetgy and see the following output while the entry is not filled:

            Code:
            The entry order average fill price is: 0
            The entry order filled amount is: 0
            The entry order order state is: Working
            The current ATM Strategy market position is: Flat
            The current ATM Strategy position quantity is: 0
            The current ATM Strategy average price is: 0
            The current ATM Strategy Unrealized PnL is: 0
            I would suggest comparing what you created with that sample to check for differences. If the entry order is filled it will show filled as you had reported.

            One other item I noted is that you are using the Addon framework ATM methods which are different than the strategy based ATM methods. Please see the SampleATMStraetgy example for the correct way to use ATM's from a NinjaScript strategy. If you are creating a tool which is not specifically a Strategy and needed to use ATM's you could use the addon framework for that case.

            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mmenigma, Today, 02:22 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frankthearm, Today, 09:08 AM
            9 responses
            35 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by NRITV, Today, 01:15 PM
            2 responses
            9 views
            0 likes
            Last Post NRITV
            by NRITV
             
            Started by maybeimnotrader, Yesterday, 05:46 PM
            5 responses
            26 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by quantismo, Yesterday, 05:13 PM
            2 responses
            21 views
            0 likes
            Last Post quantismo  
            Working...
            X