Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issues with Market Order

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

    Issues with Market Order

    Hey NT Support,

    I am running into a issue with a strategy that is not firing a market order when I want it to. The code scales out of a position based on a signal ("sorry not going to say what it is") multiple times as the trend develops. The same code fires for each trade except sometimes it just does not fire.

    (See attached image)



    The system goes short 10 CL ##-## (market replay) and scales out a total of 5 contracts in 3 trades just as I wanted it too. However, the fourth trade to scale out 2 more contracts it does not fire. The bars are painted to show when it should be firing and the text Fire 2 is right next to the exitShort logic to show me that the code is running properly.

    Here is the code that has the ExitShort syntax:

    Code:
    if(Position.Quantity > ShortQty)
    	{
    	        int newposition = Position.Quantity - ShortQty;
    	        //exitShort = ExitShort(newposition);
    	        exitShort = ExitShort(newposition,"Buy to Close","Sell to Open");
    	        if(exitShort == null)
    			{
    				DrawText("Qty2","Fire " + newposition,3,Low[0],Color.White) ;
    			} else DrawText("Qty2","Not Null",3,Low[0],Color.White) ;	
    		}
    				
    		if(Position.Quantity == 1 && exitShortStop != null && BarsSinceExit() > 1)
    		{
    			exitShort = ExitShort("Buy to Close","Sell to Open");
    		}
              }
    if you look at the chart again, you will also see that all my IOrder objects are properly set to null except for the stop, which is expected.

    I can't see any logical reason why Ninjatrader is skipping exit logic, so I need your help to see if someone has ran into this before.

    FYI, this is using the Managed approach IOrder with on execution.

    Cheers,

    Sody
    Attached Files

    #2
    Sody,

    Thank you for your post.

    Please place TraceOrders = true; in the intialize() method.

    This will print out the order placement or ignored orders to the Output window (Tools -> Output Window)

    This will get you what exactly is occurring with the orders and why it it is not getting placed, filled or ignored.

    http://www.ninjatrader.com/support/h...raceorders.htm
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I added the Trace Order and found where the issues is occurring:

      10/3/2012 8:59:59 AM Entered internal PlaceOrder() method at 10/3/2012 8:59:59 AM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy to Close' FromEntrySignal='Sell to Open'

      10/3/2012 8:59:59 AM Ignored PlaceOrder() method: Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=Buy to Close' FromEntrySignal='Sell to Open' Reason='There already is a matching, filled exit order in place'
      But, no trade actually takes place.

      Comment


        #4
        Sody,

        Are there any other orders being placed before that time or any Set() orders in place?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Trace Log

          Attached is the trace file & new chart.

          This run it failed on the 3rd trade.
          Attached Files

          Comment


            #6
            Originally posted by NinjaTrader_Cal View Post
            Sody,

            Are there any other orders being placed before that time or any Set() orders in place?
            Cal,

            Not on this replay, It sells short 10 contracts, then the code sells out small amounts along the way (using the same code that I attached on my original post).

            This replay this is the only trade executed,

            Sody

            Comment


              #7
              Originally posted by NinjaTrader_Cal View Post
              Sody,

              Are there any other orders being placed before that time or any Set() orders in place?
              Cal,

              Not on this replay, It sells short 10 contracts, then the code sells out small amounts along the way (using the same code that I attached on my original post).

              This replay this is the only trade executed,

              Here is my stop code:

              Code:
              if(Position.MarketPosition == MarketPosition.Short)
              			{
              				if( exitShortStop != null && Position.Quantity == 1 && BarsSinceEntry("Sell to Open") == 1 && FirstTickOfBar && RiskS[0] > (Position.AvgPrice + ((Math.Round(GetAccountValue(AccountItem.CashValue),2)*EquityAtRisk)/Instrument.MasterInstrument.PointValue)))
              					{
              						ow.Print("Symbol: "+sSymbol+" - Time: "+ ToTime(Time[0])+"Reset Risk to Risk Management",Color.Red);
              						exitShortStop = ExitShortStop((Position.AvgPrice + ((Math.Round(GetAccountValue(AccountItem.CashValue),2)*EquityAtRisk)/Instrument.MasterInstrument.PointValue)),"Buy to Close","Sell to Open");
              					}
              				else if(exitShortStop != null && exitShortStop.StopPrice > RiskS[0] && Close[0] < (RiskS[0]-ATR(periodFast)[0]))
              					{
              						exitShortStop = ExitShortStop(RiskS[0],"Buy to Close","Sell to Open");
              					}
              					
              				else if(exitShortStop != null)
              					{
              						exitShortStop = ExitShortStop(exitShortStop.StopPrice,"Buy to Close","Sell to Open");
              					}
              			}
              Sody

              Comment


                #8
                I hate to just badger you with posts, but

                Cal,

                This is a log that I create separate from the Ninjatraders Output order..

                It may help clarify whats going on (maybe):

                Symbol: 'CL' - Time: 06:10:45 - Order: Pyramid 1 - Enter Short Limit - Limit Price: 91.15 - Qty: 10 - Filled Qty: 2 - Status: PartFilled - Order has been part filled at 91.22
                Symbol: 'CL' - Time: 06:10:45 - Order: Pyramid 1 - Enter Short Limit - Limit Price: 91.15 - Qty: 10 - Filled Qty: 8 - Status: PartFilled - Order has been part filled at 91.22
                Symbol: 'CL' - Time: 06:10:45 - Order: Pyramid 1 - Enter Short Limit - Limit Price: 91.15 - Qty: 10 - Filled Qty: 10 - Status: Filled - Order has been filled at 91.22
                Symbol: 'CL' - Time: 61200Qty mismatch
                Symbol: 'CL' - Time: 06:10:45 - Order: Exit Short Stop - Stop Price: 91.4 - Qty: 10 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 06:10:45 - Order: Exit Short Stop - Stop Price: 91.4 - Qty: 10 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:27:00 - Order: Exit Short Stop - Stop Price: 91.39 - Qty: 10 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 07:27:00 - Order: Exit Short Stop - Stop Price: 91.39 - Qty: 10 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:30:01 - Order: Exit Short Stop - Stop Price: 91.38 - Qty: 10 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 07:30:01 - Order: Exit Short Stop - Stop Price: 91.38 - Qty: 10 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:33:00 - Order: Exit Short Stop - Stop Price: 91.37 - Qty: 10 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 07:33:00 - Order: Exit Short Stop - Stop Price: 91.37 - Qty: 10 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:36:00 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 10 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 07:36:00 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 10 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short at Market - Qty: 2 - Status: PendingSubmit - An order has been submitted
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short at Market - Qty: 2 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short at Market - Qty: 2 - Status: Working - An order is working at the exchange
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 10 - Status: PendingCancel - An order cancellation request has been submitted
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short - Qty: 2 - Filled Qty: 2 - Status: Filled - Order has been filled at 90.6
                Symbol: 'CL' - Time: hh:mm:ssss No Stop, Adding Stop
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 8 - Status: PendingSubmit - An order has been submitted
                Symbol: 'CL' - Time: 07:40:23 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 8 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short at Market - Qty: 2 - Status: PendingSubmit - An order has been submitted
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short at Market - Qty: 2 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short at Market - Qty: 2 - Status: Working - An order is working at the exchange
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short - Qty: 2 - Filled Qty: 1 - Status: PartFilled - Order has been part filled at 90.5
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short - Qty: 2 - Filled Qty: 2 - Status: Filled - Order has been filled at 90.5
                Symbol: 'CL' - Time: 74500Qty mismatch
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 07:43:56 - Order: Exit Short Stop - Stop Price: 91.36 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:30:00 - Order: Exit Short Stop - Stop Price: 91.34 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:30:00 - Order: Exit Short Stop - Stop Price: 91.34 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:33:03 - Order: Exit Short Stop - Stop Price: 91.31 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:33:03 - Order: Exit Short Stop - Stop Price: 91.31 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:36:00 - Order: Exit Short Stop - Stop Price: 91.26 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:36:00 - Order: Exit Short Stop - Stop Price: 91.26 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:39:01 - Order: Exit Short Stop - Stop Price: 91.24 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:39:01 - Order: Exit Short Stop - Stop Price: 91.24 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:42:01 - Order: Exit Short Stop - Stop Price: 91.22 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:42:01 - Order: Exit Short Stop - Stop Price: 91.22 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:45:00 - Order: Exit Short Stop - Stop Price: 91.21 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:45:00 - Order: Exit Short Stop - Stop Price: 91.21 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:51:00 - Order: Exit Short Stop - Stop Price: 91.2 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:51:00 - Order: Exit Short Stop - Stop Price: 91.2 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:54:00 - Order: Exit Short Stop - Stop Price: 91.19 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:54:00 - Order: Exit Short Stop - Stop Price: 91.19 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 08:57:00 - Order: Exit Short Stop - Stop Price: 91.16 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 08:57:00 - Order: Exit Short Stop - Stop Price: 91.16 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker
                Symbol: 'CL' - Time: 09:00:00 - Order: Exit Short Stop - Stop Price: 91.11 - Qty: 6 - Status: PendingChange - An order change request has been submitted
                Symbol: 'CL' - Time: 09:00:00 - Order: Exit Short Stop - Stop Price: 91.11 - Qty: 6 - Status: Accepted - Order has been acknowledged by the broker

                Comment


                  #9
                  Originally posted by SodyTexas View Post
                  Attached is the trace file & new chart.

                  This run it failed on the 3rd trade.
                  So you are entering with just one order, then scaling out?

                  Comment


                    #10
                    Exactly,

                    Sody

                    Comment


                      #11
                      Originally posted by SodyTexas View Post
                      Exactly,

                      Sody
                      No can do. More or less an acknowledged bug that will not be fixed in this iteration. Read these threads for all the gory details.

                      ref: http://www.ninjatrader.com/support/f...54704#poststop


                      For the Cliff Notes version, you may want to just read this particular post: http://www.ninjatrader.com/support/f...977#post323977 by the Product Manager.

                      Comment


                        #12
                        Sody,

                        Here is what is going on.

                        You are submitting the same signal name over and over which the NinjaTrader will ignore since there was a previous order with the same name that was filled.

                        You will need to use unique signal names for your exit orders so to avoid the error message of -
                        Code:
                        10/3/2012 8:59:57 AM Ignored PlaceOrder() method: Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=Buy to Close' FromEntrySignal='Sell to Open' Reason='There already is a matching, filled exit order in place'
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Cal,

                          Thank you so much, I have been trying to figure this out for over a day.. I should have come to you sooner!!

                          SOLVED!!

                          Code:
                          if(Position.Quantity > ShortQty)
                          		{
                          			int newposition = Position.Quantity - ShortQty;
                          			string barstring = CurrentBar.ToString();
                          			//exitShort = ExitShort(newposition);
                          			exitShort = ExitShort(newposition,"Buy to Close" + barstring,"Sell to Open");
                          			if(exitShort == null)
                          			{
                          				DrawText("Qty2","Fire " + newposition,3,Low[0],Color.White) ;
                          			} else DrawText("Qty2","Not Null",3,Low[0],Color.White) ;	
                          				}
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by funk10101, Today, 12:02 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post funk10101  
                          Started by gravdigaz6, Yesterday, 11:40 PM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by MarianApalaghiei, Yesterday, 10:49 PM
                          3 responses
                          10 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by XXtrader, Yesterday, 11:30 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post XXtrader  
                          Started by love2code2trade, 04-17-2024, 01:45 PM
                          4 responses
                          28 views
                          0 likes
                          Last Post love2code2trade  
                          Working...
                          X