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

New, issue with Order methods

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

    New, issue with Order methods

    Hi! I'm new, but I'm coming from a background in native Android and cross-platform mobile app development. I'm trying to learn the ninjascript library and I'm practicing using a strategy that combines indicators and order methods to understand how everything flows. I'm running into issues in Playback where I am receiving the debug info that everything is firing off, but my Poisiton and Account are both synced at 0. Also, my log tab in the Control Center is showing no errors. I've attached my OnBarUpdate() as well as the corresponding Output; note the issue doesn't seem to be the code overall but maybe my misuse of EnterShort()?

    Also to note this WAS firing off orders in Playback mode until I added the DisparityIndex(). Am I using this in the wrong context (found on line 67)?

    Thanks for the help!

    Click image for larger version

Name:	onbarupdate.png
Views:	54
Size:	38.6 KB
ID:	1288706

    #2
    Hello coreyander,

    Thank you for your post.

    I see you have added print statements, which is definitely helpful to see which blocks of code have been hit. Please also enable TraceOrders if you have not already in either State.SetDefaults or State.Configure so you can get information about whether orders are submitted, changed, canceled, rejected, or ignored in the NinjaScript Output window. More information about Trace Orders may be found on this page:


    Additionally, what color is the strategy name on the Strategies tab of the Control Center while you are testing in Playback?

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily, thanks for the response. TraceOrders was helpful, although not for my issue directly. When I attach an override:

      protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice,
      int quantity, int filled, double averageFillPrice,
      OrderState orderState, DateTime time, ErrorCode error, string comment)
      {
      Print(order.OrderState);
      Print(order.ToString());
      }​

      it does not print anything out to the log for the strategy I posted earlier today. But I figured it should, so I attached it to one of the sample strategies I had worked on before and was bombarded by 100s of orders. Of note, they seem to go back into data points that no longer exist as well as triggering an array out-of-bounds value off of BarsRequiredToTrade, which places the strategy out of sync by the time it starts. This causes the strategy name to be yellow. (I think)

      When I run the one I posted earlier today, the name is green and both Account and Position are flat with no OrderState objects in the output. Is there a way to erase these orders from the Playback101 Account and start fresh? Or instantiate a second Playback account?

      Click image for larger version

Name:	error1.png
Views:	75
Size:	57.9 KB
ID:	1288781 Click image for larger version

Name:	error2.png
Views:	46
Size:	51.9 KB
ID:	1288782

      Comment


        #4
        Follow-up: I found an order that had been hanging in OrderState.Working and resolved it with:

        Code:
        //Hanging Orders check
        if (Orders.Count > 0)
        {
        //Cancel orders still working from 5 bars ago
        if (CurrentBar <= BarsRequiredToTrade + 5)
        {
        foreach (var order in Orders)
        {
        if (order.OrderState == OrderState.Working)
        {
        CancelOrder(order);
        Print("Order canceled because current bar is five bars ago: " + order.Name);
        }
        }
        }
        }​
        I am now successfully registering orders in all strategies. It was causing an error across the entire account I suppose. Thanks for pointing me towards TraceOrders!

        Comment


          #5
          Originally posted by coreyander View Post
          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice,
          int quantity, int filled, double averageFillPrice,
          OrderState orderState, DateTime time, ErrorCode error, string comment)
          {
          Print(order.OrderState);
          Print(order.ToString());
          }​

          it does not print anything out to the log for the strategy
          Print output goes to the output window, not the log.



          Comment


            #6
            I agree, the "logs" are documented two posts up. Ty.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by lightsun47, Today, 03:51 PM
            0 responses
            5 views
            0 likes
            Last Post lightsun47  
            Started by 00nevest, Today, 02:27 PM
            1 response
            8 views
            0 likes
            Last Post 00nevest  
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            44 views
            0 likes
            Last Post futtrader  
            Started by Option Whisperer, Today, 09:55 AM
            1 response
            13 views
            0 likes
            Last Post bltdavid  
            Started by port119, Today, 02:43 PM
            0 responses
            9 views
            0 likes
            Last Post port119
            by port119
             
            Working...
            X