• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Execution update event can not trigger after entry order fill...

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

    Execution update event can not trigger after entry order fill...

    Hello,

    Here is the clarification;

    1. Downloaded 2016.12.01 - 2016.12.31 CL 03-17 market replay data.
    2. Connect market replay connection, put the strategy on chart CL 10 tick renko chart.
    3. After 2016.12.12 02:05:00 suddenly, i see strategy going long and there is no any stoploss and takeprofit order.
    4. Because of that without TP and SL order, position can not be close until the end of the test.

    Before talk about strategy, i want to say, i do tests for other instruments and time frames never see any problem. For example ES between 2016.12.01-2017.02.28. After see the problem i put print lines to code. Below there is an order life cycle for long position that close with loss according to output window;

    LONG ORDER SENT WITH ID : 216
    LONG ORDER FILLED WITH ID : 216
    STOP LOSS ORDER SENT WITH ID : 217
    TAKE PROFIT ORDER SENT WITH ID : 218
    STOP LOSS ORDER FILLED WITH ID : 217

    But for problematic order only printing LONG ORDER SENT WITH ID : 244 and even order filled there is no any print neither for order nor SL&TP orders. Also either data or market replay in a bad shape at the day. And suddenly take shape many bars at 1x replay...

    Here is some code parts for clarification the strategy;

    Code:
    		private Order entryOrder;
    		private Order stopLossOrder;
    		private Order takeProfitOrder;
    
    		protected override void OnBarUpdate()
    		{
    			if (Position.MarketPosition == MarketPosition.Flat)
    			{
    				if (entryOrder == null)
    				{
    					if (Check Long Condition)
    					{
    						entryOrder = EnterLongLimit(0, true, ?, ?, "Long Entry");
    						Print("LONG ORDER SENT WITH ID : " + entryOrder.Id);
    					}
    					else if (Check Short Condition)
    					{
    						entryOrder = EnterShortLimit(0, true, ?, ?, "Short Entry");
    						Print("SHORT ORDER SENT WITH ID : " + entryOrder.Id);
    					}
    				}
    				else
    				{
    					if (Check Cancel Condition)
    					{
    						CancelOrder(entryOrder);
    					}
    				}
    			}
    		}
    
    		protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
    		{
    			if (entryOrder != null && entryOrder == order)
    			{
                    if (entryOrder.OrderState == OrderState.Cancelled || entryOrder.OrderState == OrderState.Rejected)
    				{
    					entryOrder = null;
    				}
    			}
    		}
    
    		protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
    		{
    			if (entryOrder != null && entryOrder == execution.Order)
    			{
    				if (entryOrder.OrderState == OrderState.Filled || entryOrder.OrderState == OrderState.PartFilled || (entryOrder.OrderState == OrderState.Cancelled && entryOrder.Filled > 0))
    				{
    					if (Position.MarketPosition == MarketPosition.Long)
    					{
    						stopLossOrder = ExitLongStopMarket(0, true, entryOrder.Filled, ?, "Stop Loss", "Long Entry");
    						takeProfitOrder = ExitLongLimit(0, true, entryOrder.Filled, ?, "Take Profit", "Long Entry");
    						Print("LONG ORDER FILLED WITH ID : " + entryOrder.Id);
    						Print("STOP LOSS ORDER SENT WITH ID : " + stopLossOrder.Id);
    						Print("TAKE PROFIT ORDER SENT WITH ID : " + takeProfitOrder.Id);
    					}
    					else if (Position.MarketPosition == MarketPosition.Short)
    					{
    						stopLossOrder = ExitShortStopMarket(0, true, entryOrder.Filled, ?, "Stop Loss", "Short Entry");
    						takeProfitOrder = ExitShortLimit(0, true, entryOrder.Filled, ?, "Take Profit", "Short Entry");
    						Print("SHORT ORDER FILLED WITH ID : " + entryOrder.Id);
    						Print("STOP LOSS ORDER SENT WITH ID : " + stopLossOrder.Id);
    						Print("TAKE PROFIT ORDER SENT WITH ID : " + takeProfitOrder.Id);
    					}
    					
    					if (entryOrder.OrderState != OrderState.PartFilled)
    					{
    						entryOrder = null;
    					}
    				}
    			}
    			else if (stopLossOrder != null && stopLossOrder == execution.Order)
    			{
    				Print("STOP LOSS ORDER EXECUTED WITH ID : " + stopLossOrder.Id);
    				if (stopLossOrder.OrderState == OrderState.Filled || stopLossOrder.OrderState == OrderState.PartFilled)
    				{
    					Print("STOP LOSS ORDER FILLED WITH ID : " + stopLossOrder.Id);
    					if (stopLossOrder.OrderState != OrderState.PartFilled)
    					{
    						stopLossOrder = null;
    					}
    				}
    			}
    			else if (takeProfitOrder != null && takeProfitOrder == execution.Order)
    			{
    				Print("TAKE PROFIT ORDER EXECUTED WITH ID : " + takeProfitOrder.Id);
    				if (takeProfitOrder.OrderState == OrderState.Filled || takeProfitOrder.OrderState == OrderState.PartFilled)
    				{
    					Print("TAKE PROFIT ORDER FILLED WITH ID : " + takeProfitOrder.Id);
    					if (takeProfitOrder.OrderState != OrderState.PartFilled)
    					{
    						takeProfitOrder = null;
    					}
    				}
    			}
    		}
    Don't know how or why but i think NT executing long order and can not be trigger execute event. Also please tell me can we trust the market replay data for test the custom strategy? For example i see there is no data last 10 days of February 2017 and a lot of wrong data for December 2016.

    Thanks,
    Aytac
    Last edited by aytacasan; 03-06-2017, 12:55 PM.

    #2
    Thank you for this clarification and for making a separate thread for the Market Analyzer behavior you mentioned. I wanted to let you know that we received your video. For reference, the other thread this refers to is here,

    http://www.ninjatrader.com/support/f...ad.php?t=96994

    I will be addressing the Market Analyzer behavior in this thread, and the BarsRequiredToPlot behavior in thread 96994 . I will be reporting back when I have more information.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Ok Jessica,

      I was in a team that develop trading platform. Because of that i well know that one feature be in a tight relationship with other features. So i can't sure my issues related with each other or related with some other features. Because of that maybe manage my posts is not easy. Sorry about that.

      In my video (https://1drv.ms/u/s!AjeE-TTaKL0-pgx4XVU-B38jk8AT) some problems clear but some problems not. Here is clarification;

      1. Market replay data, especially CL data has big problems.
      2. Don't understand why but when i open a chart and select draw last 3 days, even we have enough data, NT doesn't draw a chart. My opinion even don't have historical data, NT must be create bars from market replay data.
      3. When i change start and/or end date range on a playback form, chart does not refreshing until click on it with mouse.
      4. When i add secondary data series on chart or change secondary data series period, NT reset strategy test results.
      5. After first bar take shape, chart can not receive new ticks. I think this is occur especially if chart have many price panel that drawing Renko charts.
      6. Sometimes when i use slider control on playback form, NT crash or freeze.

      For now, i remember these only. If i remember other issues i'll be update the list. Please don't forget maybe minute charts works ok but i used Renko charts only.

      Thanks,
      Aytac
      Last edited by aytacasan; 03-09-2017, 07:54 AM.

      Comment


        #4
        I am currently in the process of testing and reviewing this ticket. For reference, I have passed in a copy of the strategy you sent us for testing.
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Ok Jessica,

          I want to say that actually most of the issues not related with attach strategy to the chart or not. Without attach a strategy to the chart you can notice easily most of the issue. Anyway i expect news from you as soon as possible. (Talking about #3 post issue list)

          Also i'm changing my strategy codes according to my selection about order management from managed to unmanaged and i'll test same strategy with unmanaged orders and inform you about results. (Talking about #1 post issue)

          Have a good day
          Last edited by aytacasan; 03-09-2017, 06:12 AM.

          Comment


            #6
            It looks like the (reattached) strategy you sent us can not be used to place trades. Can you modify the strategy I am attaching so that it places trades the way you described in your first post? I look forward to assisting further.
            Attached Files
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Jessica,

              I do, i change your code a little bit, please check it. But i have to say that i don't understand why you are using strange code parts (for my opinion), some flags about check conditions, CurrentBar % 2 bal bla bla.

              Anyway, let say you need this code parts for testing purposes so please tell me if my fault/error/bug/bad data condition only met when enter 2016.12.12 in a flat condition and because your code, if strategy is enter the day with a position, how you'll catch the problem. I mean please don't change my code at least run it once (with same renko settings, same instrument, same strategy settings etc.) and see what is my exact problem.

              Please apply below steps;

              1. Renko 8 tick with EOD unchecked settings. (yes i know i change from 10 to 8 for increase trade frequency)
              2. Download CL 03-17 market replay data and set playback window start property to 2016.12.09.
              3. I changed code in the strategy;
              3.a. IsFillLimitOnTouch = true;
              3.b. IsExitOnSessionCloseStrategy = false;
              3.c. UnComment CheckLongCondition, CheckShortCondition and CheckCancelCondition flags
              3.d. Add simulated conditions for send long/short orders and cancel order.

              If you do exactly same thing when you test, your output window must include below lines;

              LONG ORDER SENT WITH ID : 963
              SHORT ORDER SENT WITH ID : 964
              SHORT ORDER FILLED WITH ID : 964
              STOP LOSS ORDER SENT WITH ID : 965
              TAKE PROFIT ORDER SENT WITH ID : 966
              STOP LOSS ORDER EXECUTED WITH ID : 965
              STOP LOSS ORDER FILLED WITH ID : 965
              SHORT ORDER SENT WITH ID : 967
              SHORT ORDER SENT WITH ID : 968
              SHORT ORDER FILLED WITH ID : 968
              STOP LOSS ORDER SENT WITH ID : 969
              TAKE PROFIT ORDER SENT WITH ID : 970
              STOP LOSS ORDER EXECUTED WITH ID : 969
              STOP LOSS ORDER FILLED WITH ID : 969
              SHORT ORDER SENT WITH ID : 971
              SHORT ORDER FILLED WITH ID : 971
              STOP LOSS ORDER SENT WITH ID : 972
              TAKE PROFIT ORDER SENT WITH ID : 973
              STOP LOSS ORDER EXECUTED WITH ID : 972
              STOP LOSS ORDER FILLED WITH ID : 972
              LONG ORDER SENT WITH ID : 974

              After that you have to see you are long 1 contract (even output window last line not containing LONG ORDER FILLED) and there is no any SL&TP orders. So the current contract can not be close never.

              Thanks,
              Aytac
              Attached Files
              Last edited by aytacasan; 03-11-2017, 04:58 AM.

              Comment


                #8
                Thank you for providing a working test strategy. Most of the code I added was because the actual conditions you were using were absent in the original post. Thank you for adding this information as well.

                You are correct that this code as written can never return to a flat position. I believe there may be a misunderstanding as to how the order methods are designed to work. EnterShort called when you are in a long position will not return you to a flat position, it will reverse your position to the short side of the market. If you would like to create a stop loss or profit target order, you must use ExitLong to close a Long trade, or ExitShort to close a short trade.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Jessica,

                  I sent an example code only go long/short etc. conditions missing because
                  1. The point is not the logic (put any simple logic like i do)
                  2. I can not share the logic, because i don't have permission about that.

                  Anyway you said that "You are correct that this code as written can never return to a flat position."

                  Who said that i can not return to flat? I'm saying that i'm sending an order, order will execute but OnExecuteOrder event not fired! Because of that SL&TP orders can not send to market, so position can not be close. Can you say simply "you can not return to flat", NO. Because this is not the main problem.

                  Problem is not about can't return to flat! problem is not about can't reverse! Order is an order (enter exit reverse does not matter) and when it'll execute, OnExecuteOrder event must be fired!

                  Why there is no this type issue when i test other instruments for months. For example ES test opening/closing 4K trades and there is no such an issue.

                  I have this type strange issues about NT and asked support some of them. I'm spending many hours read/write my posts, create examples etc. Even passed weeks, i can not solve issues and now this is starting to be very boring. FYI.

                  Thanks,
                  Aytac
                  Last edited by aytacasan; 03-15-2017, 03:31 PM.

                  Comment


                    #10
                    So that I may have a more complete picture of what is happening on your end, would it be possible to use the freely and publicly available screen capture software Jing, https://www.techsmith.com/jing.html , or a similar program which can record video of what is happening on your screen, so that you can show me what is occurring on your end? Please start recording before you enter a trade.


                    These quick instructions can get you started with Jing.

                    1. When you start Jing, a yellow half circle will appear near the top of your screen. Please hover over it with your mouse
                    2. A small + sign will extend out of this half circle. Please click on it
                    3. When your cursor becomes two intersecting lines, please click and drag your mouse over an area of your screen you would like to record
                    4. Please press the film strip button that appears to begin recording
                    5. When you are finished recording, please press the square stop button that appears
                    6. Please press the share button that appears. It consists of three vertical upward pointing arrows.

                    You will then have the option to view your video on screencast.com . This is the link which can help me diagnose what is happening on your end. It is possible you will need to set up a free account in order to share videos.




                    Thank you very much in advance for providing us with this information. If this procedure is not an option for you, or if there are any other questions we can answer, please let us know.
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jessica,

                      Before that;

                      1. I need to hear about that are you try to re-produce&test the problem with my steps at #7 post (http://ninjatrader.com/support/forum...60&postcount=7). If not why? if so what is the result?

                      2. I don't want to use public sharing services but before i said that if you have an account you can share publicly what i sent to you. Is it ok for you too?

                      Thanks,
                      Aytac

                      Comment


                        #12
                        I am happy to answer your questions.

                        1. I am trying to reproduce this. It will help me be able to see how you are placing trades, and a video may give me more contextual information that will help me as well. I understand this may involve displaying your code to be useful, and so

                        2. You can e-mail us privately at platformsupport[at]ninjatrader[dot]com referencing Attn:NinjaTrader_JessicaP and 1671812 in the subject line
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          After carefully reviewing this ticket I understand you were able to create trade logic that leaves you in a position. Other traders have been able to use the ExitLong and ExitShort methods successfully. I am having some trouble determining from the information presented what the limitation of NinjaTrader we should be looking for is. Could you help clarify, are any of these what we should be looking for?

                          • OnExecutionUpdate being called properly with the Playback connection
                          • OnOrderUpdate being called properly with the Playback connection
                          • Partially filled orders leaving Ninja in a correct state

                          It may help on your end if we set up Visual Studio debugging, so that you can see the exact execution path that your code takes. I have prepared this video which may help.


                          http://www.screencast.com/t/FjUps1I3bB
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Jessica,

                            Thanks for the video but it didn't help to me. I'm already know how can use i use Visual Studio for debug purposes. Please focus to my problem. I'm sure my problem and it's solution is so simple. I'm doing something wrong or there is a problem at playback connection, don't know but i want to solve my problem as soon as possible. Also i have to say that for take control completely, i changed my code from managed approach to unmanaged approach, nothing changed, problem not solved. Below there is code parts, they are only for example, contains "..." for not important parts.

                            Suppose i have some global variables;

                            Code:
                            private Order entryOrder;
                            private Order stopLossOrder;
                            private Order takeProfitOrder;
                            Suppose there is code lines in OnBarUpdate method;

                            Code:
                            if (Position.MarketPosition == MarketPosition.Flat && entryOrder == null && ...)
                            {
                            	var entryPrice = ...;
                            	entryOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, quantity, entryPrice, 0, "", "Long Entry");
                            }
                            Suppose there is a code part OnExecutionUpdate method;

                            Code:
                            if (execution.Order == entryOrder)
                            {
                            	var ocoOrderId = Guid.NewGuid().ToString("N");
                            	var stopLossPrice = ...;
                            	var takeProfitPrice = ...;
                            	stopLossOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, entryOrder.Filled, 0, stopLossPrice, ocoOrderId, "Stop Loss");
                            	takeProfitOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, entryOrder.Filled, takeProfitPrice, 0, ocoOrderId, "Take Profit");
                            }
                            So what is the possibility that entryOrder excute before entryOrder variable set? What i mean that my strategy working with no problem for many instruments and for many time frames but sometimes i see that;

                            When entryOrder executed OnExecutionUpdate method calling but because "execution.Order == entryOrder" condition is false, my related code part is not working. And strategy can not close current position because stop loss and take profit orders can not be created and so strategy can not return flat state and so can not open new positions...

                            Note : I know i can write something like that

                            if (execution.Order.Name == "Entry Order")

                            instead

                            if (execution.Order == entryOrder)

                            but what is the point that SubmitOrderUnmanaged return the Order object if i can not use it?

                            Thanks,
                            Aytac

                            Comment


                              #15
                              Jessica,

                              I have two questions in post #14;

                              1. So what is the possibility that entryOrder excute before entryOrder variable set?

                              When i check reference samples, i see below sample which is below and i see there is a high probability and because of that i have to set my order variables inside OnOrderUpdate instead use return value of SubmitOrderUnmanaged

                              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)
                              		{
                              			// Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
                              			// Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
                                          // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediately after submitting
                              			if (order.Name == "MyEntry")
                                  		{	
                                      		entryOrder = order;
                              
                                              // Reset the entryOrder object to null if order was cancelled without any fill
                                              if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                              					entryOrder = null;
                              			}
                              		}
                              2. What is the point that SubmitOrderUnmanaged return the Order object if i can not use it? This question is still active. Please explain to me what is the meaning of return value of SubmitOrderUnmanaged and in which situations we'll use it?

                              Thanks,
                              Aytac.
                              Last edited by aytacasan; 03-24-2017, 06:25 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by saltminer, Today, 05:19 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post saltminer  
                              Started by martyn73, Today, 04:18 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post martyn73  
                              Started by aprendiz, Today, 03:42 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post aprendiz  
                              Started by 1001111, Today, 09:10 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Started by usero86, Today, 06:02 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Working...
                              X