Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IOrder

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

    IOrder

    Hi
    I am trying to finish a strategy that places up to 3 orders if the same condition (a crossover) is met.I am using IOrder method from SampleCancelOrder.The exits are working as expected I am however having trouble creating individual entry orders (IOrder entryOrder1 ,IOrder entryOrder2, IOrder entryOrder3) Because the entry condition is the same for each, once entryOrder1 is filled and set back to null in OnExecution if the second cross over occurs entryOrder1 is again used for the second entry and not IOrder entryOrder2.I would greatly appreciate any pointers as to get around this.
    Thanks

    #2
    Originally posted by ohjob View Post
    Hi
    I am trying to finish a strategy that places up to 3 orders if the same condition (a crossover) is met.I am using IOrder method from SampleCancelOrder.The exits are working as expected I am however having trouble creating individual entry orders (IOrder entryOrder1 ,IOrder entryOrder2, IOrder entryOrder3) Because the entry condition is the same for each, once entryOrder1 is filled and set back to null in OnExecution if the second cross over occurs entryOrder1 is again used for the second entry and not IOrder entryOrder2.I would greatly appreciate any pointers as to get around this.
    Thanks
    Same question: same answer.

    Comment


      #3
      Someone could tell me does IOrder works on Strategy Analyzer? Please give me some sample program that could help on this IOrder using multiple entry. I am using it with 3 contracts does it mean that I will a IOrder entry1, IOrder entry2, IOrder entry3 and also IOrder stop1, IOrder stop2, IOrder stop3 as well as with the targets? So that it will move correct? I am totally new to IOrder. I am using a strategy template in some of my projects but I found it hard on testing matters because it will not work on strategy analyzer. Someone could help on this one? I have read and check some custom examples of Ninja but it does only 1 contract.
      Last edited by edward_bell; 11-11-2012, 09:31 PM.

      Comment


        #4
        Thanks
        Sorry I must of missed the original post,I am still having trouble getting it working properly can you take a look at my code and see where I might have gone wrong.I think it has something to do with setting the orders to null I've tried it a number of different ways which changes the entry's but not to the correct order.





        Code:
         if (Position.MarketPosition == MarketPosition.Flat)
        		        entryOrder1 == null;  entryOrder2 == null;  entryOrder3 == null;
        					     	
        		  {	
        				
        	    	if (entryOrder1 == null);
        			
        		    if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
        		    	&& movementType == SwingMovementType.HL
                        && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
        	            && Close[0] > Close[1]
        		        && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime)
        																											
        	    	{
        																	
        		        entryOrder1 = EnterLongStopLimit(0, true, lotSize,  
        							  High[0] + EntryLimit * TickSize, 
        							  High[0] + EntryLimit * TickSize, "Long1" );		
        		        DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.DarkCyan);
        		    }    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
        		        barNumberOfOrder = CurrentBar;					
        			    					
        			     // If entryOrder has not been filled within 3 bars, cancel the order.
        		    if (entryOrder1 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
        	     	    
        			{
        				// When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
        			    CancelOrder(entryOrder1);
        			}
        					
        		    else if (entryOrder2 == null) 
        				
        		    if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
        			    && movementType == SwingMovementType.HL
                        && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
        		        && Close[0] > Close[1]
        		        && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime
        			    && Close[0] > (Position.AvgPrice + 300* TickSize))																								
        			   
        			{	
        						
        		        entryOrder2 = EnterLongStopLimit(0, true, lotSize,  
        							  High[0] + EntryLimit * TickSize, 
        							  High[0] + EntryLimit * TickSize, "Long2" );		 
        		                      DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.Black);
        					
        	       	}   
        			    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
        	            barNumberOfOrder = CurrentBar;
        					
        	     	    				
        		 	    // If entryOrder has not been filled within 3 bars, cancel the order.
        		 	if (entryOrder2 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
        			   
        			{   
        			    // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
        	            CancelOrder(entryOrder2);
        			  	
        			}
        									
         		    else if (entryOrder3 == null) 
        				
        		    if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
        			    && movementType == SwingMovementType.HL
                        && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
        		        && Close[0] > Close[1]
        		        && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime	
        			    && Close[0] > (Position.AvgPrice + 600* TickSize))
        			    
        			{
        																	
        	            entryOrder3 = EnterLongStopLimit(0, true, lotSize,  
        							  High[0] + EntryLimit * TickSize, 
        							  High[0] + EntryLimit * TickSize, "Long3" );		 
        		                      DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.Green);
        					
        		    } 
        			    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
        		        barNumberOfOrder = CurrentBar;
        	 			
        					
        		        // If entryOrder has not been filled within 3 bars, cancel the order.
        		    if (entryOrder3 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
        			   
        			{ 
        			    // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
        			   CancelOrder(entryOrder3);
        				
        			}	
        			
        		  }

        Comment


          #5
          Originally posted by ohjob View Post
          Thanks
          Sorry I must of missed the original post,I am still having trouble getting it working properly can you take a look at my code and see where I might have gone wrong.I think it has something to do with setting the orders to null I've tried it a number of different ways which changes the entry's but not to the correct order.





          Code:
           if (Position.MarketPosition == MarketPosition.Flat)
                          entryOrder1 == null;  entryOrder2 == null;  entryOrder3 == null;
           
                    {    
           
                    [COLOR=blue] if (entryOrder1 == null)[SIZE=4][COLOR=red][B];[/B][/COLOR][/SIZE][/COLOR]
           
                      if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
                          && movementType == SwingMovementType.HL
                          && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
                          && Close[0] > Close[1]
                          && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime)
           
                      {
           
                          entryOrder1 = EnterLongStopLimit(0, true, lotSize,  
                                        High[0] + EntryLimit * TickSize, 
                                        High[0] + EntryLimit * TickSize, "Long1" );        
                          DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.DarkCyan);
                      }    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
                          barNumberOfOrder = CurrentBar;                    
           
                           // If entryOrder has not been filled within 3 bars, cancel the order.
                      if (entryOrder1 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
           
                      {
                          // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
                          CancelOrder(entryOrder1);
                      }
           
                      else if (entryOrder2 == null) 
           
                      if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
                          && movementType == SwingMovementType.HL
                          && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
                          && Close[0] > Close[1]
                          && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime
                          && Close[0] > (Position.AvgPrice + 300* TickSize))                                                                                                
           
                      {    
           
                          entryOrder2 = EnterLongStopLimit(0, true, lotSize,  
                                        High[0] + EntryLimit * TickSize, 
                                        High[0] + EntryLimit * TickSize, "Long2" );         
                                        DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.Black);
           
                         }   
                          // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
                          barNumberOfOrder = CurrentBar;
           
           
                           // If entryOrder has not been filled within 3 bars, cancel the order.
                       if (entryOrder2 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
           
                      {   
                          // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
                          CancelOrder(entryOrder2);
           
                      }
           
                       else if (entryOrder3 == null) 
           
                      if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
                          && movementType == SwingMovementType.HL
                          && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
                          && Close[0] > Close[1]
                          && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime    
                          && Close[0] > (Position.AvgPrice + 600* TickSize))
           
                      {
           
                          entryOrder3 = EnterLongStopLimit(0, true, lotSize,  
                                        High[0] + EntryLimit * TickSize, 
                                        High[0] + EntryLimit * TickSize, "Long3" );         
                                        DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.Green);
           
                      } 
                          // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
                          barNumberOfOrder = CurrentBar;
           
           
                          // If entryOrder has not been filled within 3 bars, cancel the order.
                      if (entryOrder3 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
           
                      { 
                          // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
                         CancelOrder(entryOrder3);
           
                      }    
           
                    }
          I have highlighted one statement in your code. It is a null statement that does nothing, and gates nothing. Is that what you intended? (The extraneous semi-colon terminates the statement, and makes it null, as there is thus no instruction following the if statement).
          Last edited by koganam; 11-12-2012, 07:46 AM.

          Comment


            #6
            Sorry first two lines of code were wrong should be as below



            Code:
             if (Position.MarketPosition == MarketPosition.Flat)
            		        entryOrder1 = null;  entryOrder2 = null;  entryOrder3 = null;

            Comment


              #7
              Hi
              I tidied the code up a bit before posting but not sure where that came from I've removed it and still have the same problem.With the code as it is, on the first entry Long1,Long2 and Long3 enter together for the second and third entry's Long1 is used.
              Thanks

              Comment


                #8
                Hello ohjob,

                Could you clarify the first if() statement, is that meant to be for all of the posted sample code?

                Originally posted by ohjob View Post
                Code:
                 [COLOR="Magenta"]if (Position.MarketPosition == MarketPosition.Flat)[/COLOR]
                		        [COLOR="DarkGreen"]entryOrder1 == null;  entryOrder2 == null;  entryOrder3 == null;[/COLOR]
                					     	
                		  {	
                				
                	    	if (entryOrder1 == null)[SIZE="5"][B];[/B][/SIZE]
                			
                		    if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
                		    	&& movementType == SwingMovementType.HL
                                && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
                	            && Close[0] > Close[1]
                		        && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime)
                																											
                	    	{
                																	
                		        entryOrder1 = EnterLongStopLimit(0, true, lotSize,  
                							  High[0] + EntryLimit * TickSize, 
                							  High[0] + EntryLimit * TickSize, "Long1" );		
                		        DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.DarkCyan);
                		    }    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
                		        barNumberOfOrder = CurrentBar;					
                			    					
                			     // If entryOrder has not been filled within 3 bars, cancel the order.
                		    if (entryOrder1 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
                	     	    
                			{
                				// When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
                			    CancelOrder(entryOrder1);
                			}
                					
                		    else if (entryOrder2 == null) 
                				
                		    if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
                			    && movementType == SwingMovementType.HL
                                && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
                		        && Close[0] > Close[1]
                		        && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime
                			    && Close[0] > (Position.AvgPrice + 300* TickSize))																								
                			   
                			{	
                						
                		        entryOrder2 = EnterLongStopLimit(0, true, lotSize,  
                							  High[0] + EntryLimit * TickSize, 
                							  High[0] + EntryLimit * TickSize, "Long2" );		 
                		                      DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.Black);
                					
                	       	}   
                			    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
                	            barNumberOfOrder = CurrentBar;
                					
                	     	    				
                		 	    // If entryOrder has not been filled within 3 bars, cancel the order.
                		 	if (entryOrder2 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
                			   
                			{   
                			    // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
                	            CancelOrder(entryOrder2);
                			  	
                			}
                									
                 		    else if (entryOrder3 == null) 
                				
                		    if (CrossAbove(EnigmaHA4().LOW, EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal, 1)
                			    && movementType == SwingMovementType.HL
                                && EnigmaLongEntryATR(MAX(MIN(LOE), 1), 1, 0.1, 1).Signal[0] > EnigmaLongATR(MAX(MIN(LO), 1), 1, 0.1, 1).Signal[1]
                		        && Close[0] > Close[1]
                		        && ToTime(Time[0]) >= startTime && ToTime(Time[0]) <= endTime	
                			    && Close[0] > (Position.AvgPrice + 600* TickSize))
                			    
                			{
                																	
                	            entryOrder3 = EnterLongStopLimit(0, true, lotSize,  
                							  High[0] + EntryLimit * TickSize, 
                							  High[0] + EntryLimit * TickSize, "Long3" );		 
                		                      DrawDot(CurrentBar.ToString(), true, 0, High[0] + EntryLimit * TickSize, Color.Green);
                					
                		    } 
                			    // Here, we assign barNumberOfOrder the CurrentBar, so we can check how many bars pass after our order is placed.
                		        barNumberOfOrder = CurrentBar;
                	 			
                					
                		        // If entryOrder has not been filled within 3 bars, cancel the order.
                		    if (entryOrder3 != null && CurrentBar > barNumberOfOrder + BarNumCancelOrder)
                			   
                			{ 
                			    // When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
                			   CancelOrder(entryOrder3);
                				
                			}	
                			
                		  }
                With the statement after it setting all entryOrders to null is completing the first if() statement and the rest of the code is being processed on each call of OnBarUpdate.

                You may use some Print() statements to verify values are what you expect and to see how your code is being processed - Debugging your NinjaScript code.

                When tracking orders you may add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

                Happy to be of further assistance.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by ohjob View Post
                  Sorry first two lines of code were wrong should be as below



                  Code:
                   if (Position.MarketPosition == MarketPosition.Flat)
                                  entryOrder1 = null;  entryOrder2 = null;  entryOrder3 = null;
                  You have not corrected the statement that I identified in blue and red. In fact, what you post as a correction seems to be the same as the lines that you claim to have corrected.

                  Your bracketing also looks off.

                  Comment


                    #10
                    Sorry for the confusion I posted the correction of the first two line before I had realized you had posted your answer the difference was from == to =.I have attached a simplified version of the strategy with those lines removed and the semi-colon you highlighted removed also.With the simplified version only "Long1" is used for entry's regardless if it is the first second or third entry.What need's to be changed or added to get Long1 Long2 and Long3 to enter in the correct order.Thanks in advance.
                    Attached Files

                    Comment


                      #11
                      Hello ohjob,

                      The problem with you code is two different things.

                      1. Entry Handling:

                      EntriesPerDirection = 3;

                      For three different order each with there own name you would need to change it to the following:

                      EntriesPerDirection = 1;
                      EntryHandling = EntryHandling.UniqueEntries;

                      http://www.ninjatrader.com/support/h...ryhandling.htm

                      2. Make sure your to follow your if() statements with curley braces "{}" to make sure you know what the statement is effecting.

                      http://www.ninjatrader.com/support/h...sic_syntax.htm

                      You may import this version of your strategy and try it out.

                      You may want to use Print() statements to verify values are what you expect and how your NinjaScript code is being processed - Debugging your NinjaScript code.
                      Attached Files
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        Help

                        I have a program that uses the IOrder and it works fine on other chart but in renko chart it doesn't work well.

                        I have the CalculateOnBarClose to true but it will submit a total of 18 orders on the same bar and I don't understand why.

                        In the OnBarUpdate:

                        if(longentryOrder == null)
                        {
                        longentryOrder = EnterLongLimit(0, true, 3,Closes[0][0], "long entry");
                        }

                        In the OrOrderUpdate:

                        if (longentryOrder != null && longentryOrder == order)
                        {
                        // Reset the entryOrder object to null if order was cancelled without any fill
                        if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                        {
                        longentryOrder = null;
                        Print("------------------------------------------------");
                        Print("OnOrderUpdate: long entry is now null");
                        Print("Time: " +Times[0][0]);
                        Print("------------------------------------------------");
                        }
                        }

                        Comment


                          #13
                          Hello edward_bell,

                          It looks like you are using a Multi-Time Frame/Instrument Strategy.

                          Are you using BarsInProgress to check to make sure you are accessing the correct bars for your calculations?

                          OnBarUpdate will be called for each bar inside a Multi-Time Fame/Instrument Strategy so it important you know "How Bar data is Referenced", you may view the link below for more details.
                          http://www.ninjatrader.com/support/h...nstruments.htm
                          JCNinjaTrader Customer Service

                          Comment


                            #14
                            Nice catch! Okay I will try it.

                            Comment


                              #15
                              Stacking Positions

                              Hi
                              Thanks for help and the syntax link was particularly helpful.The amended strategy is not performing exactly as expected however,what I am trying to achieve is as follows.When the Trix crossover occurs for the first time only Long1 enters then If another crossover occurs and Long1 has not been stopped out Long2 enters so we are now net +2.If the Trix crosses for a third time and both Long1 and Long2 are both still live Long3 enters giving us a total of 3 long positions.I have the exits working OK I just can't get the entry orders to stack correctly in order.Any help to achieve this would be greatly appreciated. Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Vikuno1, 11-28-2023, 11:42 PM
                              13 responses
                              349 views
                              1 like
                              Last Post PaulMohn  
                              Started by Taddypole, 04-26-2024, 02:47 PM
                              5 responses
                              36 views
                              0 likes
                              Last Post eDanny
                              by eDanny
                               
                              Started by kujista, 04-23-2024, 06:23 AM
                              6 responses
                              51 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by giulyko00, 04-24-2024, 12:03 PM
                              7 responses
                              37 views
                              0 likes
                              Last Post eDanny
                              by eDanny
                               
                              Started by NM_eFe, Today, 10:13 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post NM_eFe
                              by NM_eFe
                               
                              Working...
                              X