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

Can't place several orders

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

    Can't place several orders

    In my strategy, when I got some signal, I want to enter into a position with current price and then set Take-limit-order and Stop-limit-order. I write this code:

    Code:
    EnterLongLimit(tradeParams.max, Bars.LastPrice);
    ExitLongLimit(tradeParams.max, Bars.LastPrice + TickSize * 2);
    ExitLongStopLimit(tradeParams.max, Bars.LastPrice - TickSize * 5);
    And I only get placed the first order. How to place another two?

    #2
    Hello Defake,

    The ExitLongLimit and ExitLongStopLimit would not be placed until the entry order is filled.

    Under tips at the following section of our helpguide for ExitLongLimit you will see,

    This method is ignored if a long position does not exist



    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello Defake,

      The ExitLongLimit and ExitLongStopLimit would not be placed until the entry order is filled.

      Under tips at the following section of our helpguide for ExitLongLimit you will see,

      This method is ignored if a long position does not exist



      Please let us know if you need further assistance.
      Thanks for response! And sorry for late...
      Okay, I read example from http://ninjatrader.com/support/helpG...r_handling.htm
      And try to repeat this in my strategy. But anyway I can't place exit orders even if the enter order is already filled.

      Placing enter order:

      Code:
                  if (Position.Quantity == 0 && curOrder == null)
                  {
                      
                      if (decision > 0)
                      {
                          curOrder =  EnterLongLimit(tradeParams.max, Bars.LastPrice, "EnterOrder");
                          toLongOrder = true;
                      }
                      else if (decision < 0)
                      {
                          curOrder = EnterShortLimit(tradeParams.max, Bars.LastPrice, "EnterOrder");
                          toLongOrder = false;
                      }
                  }
      And OnOrderUpdateFunction:

      Code:
              protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
              {
                  // if exited from trade, clear all remaining orders (e.g. remaining stop order)
                  if (order.Name == "ExitOrder" && orderState == OrderState.Filled)
                      Orders.Clear();
      
                  // if Enter order is filled, place exit orders
                  if (curOrder != null && order == curOrder && order.OrderState == OrderState.Filled)
                  {
                      if (toLongOrder)
                      {
                          ExitLongLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.take, "ExitOrder", "EnterOrder");
                          ExitLongStopLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.stop, "ExitOrder", "EnterOrder");
                      }
                      else
                      {
                          ExitShortLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.take, "ExitOrder", "EnterOrder");
                          ExitShortStopLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.stop, "ExitOrder", "EnterOrder");
                      }
      
                      curOrder = null;
                  }
              }
      I got the same situation with this code. Strategy can place enter orders, but when they are filled nothing happens. What am I doing wrong?

      Comment


        #4
        Originally posted by Defake View Post
        Thanks for response! And sorry for late...
        Okay, I read example from http://ninjatrader.com/support/helpG...r_handling.htm
        And try to repeat this in my strategy. But anyway I can't place exit orders even if the enter order is already filled.

        Placing enter order:

        Code:
                    if (Position.Quantity == 0 && curOrder == null)
                    {
                        
                        if (decision > 0)
                        {
                            curOrder =  EnterLongLimit(tradeParams.max, Bars.LastPrice, "EnterOrder");
                            toLongOrder = true;
                        }
                        else if (decision < 0)
                        {
                            curOrder = EnterShortLimit(tradeParams.max, Bars.LastPrice, "EnterOrder");
                            toLongOrder = false;
                        }
                    }
        And OnOrderUpdateFunction:

        Code:
                protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                {
                    // if exited from trade, clear all remaining orders (e.g. remaining stop order)
                    if (order.Name == "ExitOrder" && orderState == OrderState.Filled)
                        Orders.Clear();
        
                    // if Enter order is filled, place exit orders
                    if (curOrder != null && order == curOrder && order.OrderState == OrderState.Filled)
                    {
                        if (toLongOrder)
                        {
                            ExitLongLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.take, "ExitOrder", "EnterOrder");
                            ExitLongStopLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.stop, "ExitOrder", "EnterOrder");
                        }
                        else
                        {
                            ExitShortLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.take, "ExitOrder", "EnterOrder");
                            ExitShortStopLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.stop, "ExitOrder", "EnterOrder");
                        }
        
                        curOrder = null;
                    }
                }
        I got the same situation with this code. Strategy can place enter orders, but when they are filled nothing happens. What am I doing wrong?
        Is there any information about this in your log? Have you looked?

        Comment


          #5
          Hello Defake,

          I would suggest adding print statements to check whether your conditions are becoming true. For example I would put a print statement above if(toLongOrder), Print(“Getting to this part”);, as well as within that block to see if it’s being considered and whether the if statement is becoming true. You could also print the value of your variables as well as what you are checking them against, for example Print(order.ToString());

          I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:


          I’ve provided a link covering debugging which you may find helpful.
          Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

          Please let us know if you need further assistance.
          Alan P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by agclub, 04-21-2024, 08:57 PM
          4 responses
          18 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Irukandji, Today, 04:58 AM
          0 responses
          3 views
          0 likes
          Last Post Irukandji  
          Started by fitspressoburnfat, Today, 04:25 AM
          0 responses
          2 views
          0 likes
          Last Post fitspressoburnfat  
          Started by Skifree, Today, 03:41 AM
          1 response
          4 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by usazencort, Today, 01:16 AM
          0 responses
          4 views
          0 likes
          Last Post usazencort  
          Working...
          X