Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Entry

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

    Order Entry

    I'm trying the following code, but I don't see any signal:
    Could you please help me?

    private IOrder entryOrder = null;

    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {


    if (EntryOrder == null && Close[0] > Open[0])
    {
    entryOrder = EnterLong();
    }

    }

    #2
    Hello,

    After a quick look: try using a small case for EntryOrder so it matches your variable elsewhere:
    if (entryOrder == null && Close[0] > Open[0])
    DenNinjaTrader Customer Service

    Comment


      #3
      I tried, but I cannot see any order.
      Following is a the code.

      I'm expecting to see the order limit in the Control Center, but I don't.
      Of course the actual price is greater than the limit price.
      Thanks.

      Code:
      protected override void OnBarUpdate() 
      { 
          if (entryOrder == null && Close[0] > Open[0]) 
              entryOrder = EnterLongLimit(1, 123.75, "test"); 
      }
      
      protected override void OnOrderUpdate(IOrder order) 
      { 
          if (entryOrder != null && entryOrder.Token == order.Token) 
          { 
              Print(order.ToString()); 
              if (order.OrderState == OrderState.Filled) 
                  entryOrder = null; 
           } 
      }

      Comment


        #4
        MAX,

        Please see your Control Center logs for any runtime errors.
        Please also add TraceOrders = true into Initialize() and see the Output Window for any hints.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks.

          What I'm trying to do is an order handling where I send a buy order (limit or stop doesn't matter) and, when filled, place a take profit of 10 ticks.
          Once the profit order has been filled, immediatly place again a buy order at the original entry price.
          I've seen some examples in the forum but I still have some doubts.

          Could you please put me on the right way?

          Thanks.

          Comment


            #6
            Hi Max, for the snippet you provided - did you check into the TraceOrder output already for debug info? It could be the order just expires after the bar, which is default behavior in NinjaScript -



            Also, for starting out it might be easier to work without IOrders, just enter a limit order when you're flat (Position.MarketPosition) and use the Set() methods for exit -

            Comment


              #7
              Thanks Bertrand. I made some test but I don't acknowledge what I need.

              The order should handle something like:

              1) Getting long.
              2) When long, put a profittarget exitorder.
              3) if the position is exited on profit (only in this case) then place again the buy order at the original level.

              I'm not sure if is easier to use the set method instead of IOrder, need some hints.
              I studied tons of examples but I'm not so familiar with C# and probably I'm missing something.

              Thanks.

              Comment


                #8
                MAX, just like Josh asked: are there any errors in the logs (right-most tab of Control Center)? What output does TraceOrders provide?
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  No. Now I can send orders properly.
                  I place a buy order and a profit target, but I need for the buy signal to reactivate at the same level only if the target is reached.

                  Comment


                    #10
                    MAX,

                    If you want the signal to become active again you need to reset your entryOrder to null at a point in time that you need to specify as appropriate.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      I've tried the following code, but the entryOrder is placed and then cancelled on starting of a new bar:


                      Code:
                      protected override void OnBarUpdate() 
                      { 
                      
                          if (start_Price > 0 && entryOrder == null)
                      		
                      		{
                              	
                      			if (start_Price + (step_Grid *1) > Close[0])
                      				{
                      				entryOrder = EnterLongStop(nCtr, (start_Price + (step_Grid * 1)), "Buy_Price_1");
                      				}
                      				else
                      				{
                      				entryOrder = EnterLongLimit(nCtr, (start_Price + (step_Grid * 1)), "Buy_Price_1");
                      				}	
                      					
                      		}	
                      		
                      }
                      
                      protected override void OnOrderUpdate(IOrder order) 
                      { 
                        // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
                      			if (entryOrder != null && entryOrder.Token == order.Token)
                      			{	
                      				// Reset the entryOrder object to null if order was cancelled without any fill
                      				if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                      				{
                      					entryOrder = null;
                      				}
                      			}  
                      }
                       protected override void OnExecution(IExecution execution)
                              {
                      			if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                      			{
                      				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                      				{
                      									
                      					// Target order 10 ticks above my entry price
                      					targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 10 * TickSize, "Target_Price1_Stop", "buy_Price1_Stop");
                      					
                      								
                      					// Resets the entryOrder object to null after the order has been filled or partially filled
                      					//if (execution.Order.OrderState != OrderState.PartFilled)
                      					//{
                      					//	entryOrder 	= null;
                      					//}
                      				}
                      			}
                      			// Reset target orders and buy order IOrder objects after my position is closed.
                      			if (targetOrder != null && targetOrder.Token == execution.Order.Token)
                      			{
                      				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                      				{
                      					entryOrder 	= null;//resets buy order only if the target has been reached
                      					targetOrder = null;
                      				}
                      			}
                      		}

                      Comment


                        #12
                        MAX, this is expected default behavior of limit orders in NinjaTrader, you would need to resubmit them on a new bar, or use the advanved overload offering the liveUntilCancelled parameter -

                        Comment


                          #13
                          I'm trying the following way, adding the condition that the entryOrder is null again only if a target order has been filled, buy now I don't see the target order placed when long.
                          What's wrong with my code? Thanks.
                          Code:
                            protected override void Initialize()
                                  {
                                      CalculateOnBarClose = false;
                          			EntriesPerDirection = 100; 
                          			TimeInForce = Cbi.TimeInForce.Day; 
                          			TraceOrders         = true; 
                                  }
                          
                                  /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                              protected override void OnBarUpdate()
                          	{
                          		if (entryOrder == null) 
                          		EnterLongLimit(nCtr, start_Price - (step * TickSize), "Buy_Test");
                              }
                          	protected override void OnOrderUpdate(IOrder order) 
                          	{ 
                              	if (entryOrder != null && entryOrder.Token == order.Token) 
                             		{ 
                                  	Print(order.ToString()); 
                                  	if (order.OrderState == OrderState.Cancelled) 
                                  	{ 
                                      // Do something here 
                                      entryOrder = null; 
                                  	} 
                              	} 
                          	}
                          	protected override void OnExecution(IExecution execution)
                              {
                          			if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                          			{
                          				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                          				{
                          									
                          					// Target order 10 ticks above our entry price
                          					targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 10 * TickSize, "Target_Price1_Stop", "Buy_Test");
                          												
                          					
                          				}
                          			}
                          			// Reset our stop order and target orders' IOrder objects after our position is closed.
                          			if (targetOrder != null && targetOrder.Token == execution.Order.Token)
                          			{
                          				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                          				{
                          					entryOrder 	= null;
                          					targetOrder = null;
                          				}
                          			}
                          		}

                          Comment


                            #14
                            MAX, please check the TraceOrders output to debug your order behavior - are you sure the Entry Limit order is filled?

                            You did not change the liveUntilCancelled setting, it would still expire at the end of the bar...

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            672 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            379 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            111 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            575 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            582 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X