Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unique Entries?

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

    #16
    Hello kenb2004,
    Yes you can use the code. However I will not put the code
    Code:
    Buy_1MarketPosition = MarketPosition.Long; // Unique entry is long
    Instead I will assign it while putting the entry order.

    Also, OrderState.Cancelled or OrderState.Rejected is not updated in OnExection event. They are triggered in OnOrderUpdate event.


    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #17
      The following code is from SampleCancelOrder.cs. I'm confused, is this sample not applicable to my coding, because it includes "OrderState.Cancelled" in the OnExecution? Also if "Instead I will assign it while putting the entry order", wouldn't that only be watching the status of the buy1entry IOrder and not the Buy_1MarketPosition?

      thanks

      protectedoverridevoid OnExecution(IExecution execution)
      {
      /* We advise monitoring OnExecution() to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
      which ensures your strategy has received the execution which is used for internal signal tracking.

      This first if-statement is in place to deal only with the long limit entry. */
      if (entryOrder != null && entryOrder.Token == execution.Order.Token)
      {
      // This second if-statement is meant to only let fills and cancellations filter through.
      if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
      {
      // Simple stop and target
      stopOrder = ExitLongStop(0, true, 1, execution.Price - 20 * TickSize, "stop", "long limit entry");
      targetOrder = ExitLongLimit(
      0, true, 1, execution.Price + 40 * TickSize, "target", "long limit entry");

      // Resets the entryOrder object to null after the order has been filled
      if (execution.Order.OrderState != OrderState.PartFilled)
      {
      entryOrder =
      null;
      }
      }
      }

      Comment


        #18
        Hello kenb2004,
        Thanks for pointing out the bug. The OrderState.Cancelled event dont get triggered in the OnExecution event. We will update the SampleCancelOrder code accordingly.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #19
          Also if "Instead I will assign it while putting the entry order", wouldn't that only be watching the status of the buy1entry IOrder and not the Buy_1MarketPosition?

          Comment


            #20
            Hello kenb2004,
            A basic code will be like

            Code:
            if (entry condition)
            {
            buy1entry = EnterLong(....);
            Buy_1MarketPosition = MarketPosition.Long;
            //rest of the codes
            }
            This way you are coding and tracking the MarketPosition from when the order was submitted till it gets filled.

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #21
              That's what I thought. That will not work, because your code only launches the buy order. It does not ensure it's fill, especially with limit orders.

              You mentioned that "The OrderState.Cancelled event dont get triggered in the OnExecution event", where in your reference material would I find the properties of these events, both OnOrderUpdate and OnExecution? I looked in the user guide, but the properties were not listed.
              Thanks

              Comment


                #22
                Hello kenb2004,
                Cancellation will be updated in OnOrderUpdate but not in OnExectuion.

                I thought you wanted a custom position state till the order gets submitted and the order gets filled. Please let me know if this is not the case.

                I look forward to assisting you further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #23
                  "Cancellation will be updated in OnOrderUpdate but not in OnExectuion." Where do you get this information and is it available for us users?
                  thanks

                  Comment


                    #24
                    Hello kenb2004,
                    Please refer to this help file for more details on OnOrderUpdate. Please refer to the example which demonstrates a sample code regarding cancellation.



                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #25
                      I've tried the 3 following codes, but only the OnBarUpdate entry code works, why is that? Since if I am using Limit Orders there is no guarantee that the buy1entry will be filled and Buy_1 is long?
                      *******************************************
                      protected override void OnOrderUpdate(IOrder order)
                      {
                      if (buy1entry != null && buy1entry == order){
                      if (order.OrderState == OrderState.Filled){ // If buy1entry is filled
                      Buy_1MarketPosition = MarketPosition.Long; // Buy_1 is long
                      } } }
                      *******************************************
                      protected override void OnExecution(IExecution execution)
                      {
                      if (buy1entry != null && buy1entry == execution.Order
                      && execution.Order.OrderState == OrderState.Filled){ // If buy1entry is filled
                      Buy_1MarketPosition = MarketPosition.Long; // Buy_1 is long
                      } }
                      *******************************************
                      protected override void OnBarUpdate()
                      {
                      if (Condition){ // If entry condition is true...
                      buy1entry = EnterLongLimit(0, true, 1, Close[0] + EntryOffset * TickSize, "Buy_1"); // buy1entry order is Working...
                      Buy_1MarketPosition = MarketPosition.Long; // Buy_1MarketPosition MIGHT BE FILLED
                      } }

                      Comment


                        #26
                        Hello kenb2004,
                        To assist you further please tell me what you are trying to do? What are your specific requirements?
                        I look forward to assisting you further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #27
                          The following code is one example. I need to be able to individually track whether Buy_1 or Buy_2 are long or flat. In this case if I used the generic "MarketPosition = MarketPosition.Long" I would be drawing 2 dashed lines when I only want to draw a single dashed target line for the applicable market position, either Buy_1 or Buy_2, but not both.
                          ***************************************
                          if (Buy_1MarketPosition = MarketPosition.Long)
                          {
                          buy1target = ExitLongLimit(0, true, 1, Position.AvgPrice + PT * TickSize, "Buy_1_Profit", "Buy_1");
                          BuyTarget(0).Value.Set(Position.AvgPrice + PT * TickSize); // Draw Dashed Lines for dummy indicator at target1 price
                          }
                          if (Buy_2MarketPosition = MarketPosition.Long)
                          {
                          buy2target = ExitLongLimit(0, true, 1, Position.AvgPrice + PT_2 * TickSize, "Buy_2_Profit", "Buy_2");
                          BuyTarget_2(0).Value.Set(Position.AvgPrice + PT_2 * TickSize); // Draw Dashed Lines for dummy indicator at target2 price
                          }

                          Comment


                            #28
                            Hello kenb2004,
                            If you submit a limit order then the same may not be filled immediately.

                            Code:
                            protected override void OnBarUpdate()
                            {
                            	
                            	if (entry condition)
                            	{
                            		buy1Entry = EnterLong();
                            		Buy_1MarketPosition = MarketPosition.Long)
                            	}
                            }
                            
                            protected override void OnExecution(IExecution execution)
                            {
                            	
                            	if (execution.Order != null && execution.Order == buy1Entry && execution.Order.OrderState == Filled && Buy_1MarketPosition == MarketPosition.Long)
                            	{
                            		//reset market position
                            		Buy_1MarketPosition == MarketPosition.Flat;
                            		//do other stuffs
                            	}
                            }
                            The OrderState property of the order will let you know if the order is filled or not.

                            Please let me know if I can assist you any further.
                            JoydeepNinjaTrader Customer Service

                            Comment


                              #29
                              I put a print command in the OnBarUpdate:
                              if (Buy_1MarketPosition = MarketPosition.Long) Print(Time[0] + " - Buy_1 is Long");

                              In thread 25 I showed 3 different code locations. My question remains, why is the OnBarUpdate entry location the only place that generates the print command, when it is the least correct? The way I see it, that location only says the entry condition is "true", not that the Buy_1MarketPosition is Long.

                              I'm sorry that we keep going over this but I'm having a hard time getting you to answer my very specific question? How do you momitor the state of a unique entry position whether it is Long, Short, or Flat? As you have stated in thread 28 "If you submit a limit order then the same may not be filled immediately.", why would you put your monitoring code with the entry condition code in OnBarUpdate, when at that point, the Buy_1MarketPosition is NOT Long, it just "may not be filled immediately"?

                              Thanks again

                              Comment


                                #30
                                Hello kenb2004,
                                OnBarUpdate event triggers on each incoming tick (if CalculateOnBarClose is set to false) or at the end of the bar (if CalculateOnBarClose is set to true).

                                OnOrderUpdate event will trigger only when an order gets updated. Similarly OnExecution event will get triggered only when there is an execution. An order is not updated or executed as frequently as OnBarUpdate and thus you are only getting the Prints in OnBarUpdate.

                                Well I am not still clear about what you are trying to do. In post 15 you are setting the market position to long and restting to flat immediately. It fails to fulfill any purpose. If you need to track the market position then please clarify the objective for it.

                                I look forward to assisting you further.
                                JoydeepNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by burtoninlondon, Today, 12:38 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post burtoninlondon  
                                Started by AaronKoRn, Yesterday, 09:49 PM
                                0 responses
                                14 views
                                0 likes
                                Last Post AaronKoRn  
                                Started by carnitron, Yesterday, 08:42 PM
                                0 responses
                                11 views
                                0 likes
                                Last Post carnitron  
                                Started by strategist007, Yesterday, 07:51 PM
                                0 responses
                                14 views
                                0 likes
                                Last Post strategist007  
                                Started by StockTrader88, 03-06-2021, 08:58 AM
                                44 responses
                                3,983 views
                                3 likes
                                Last Post jhudas88  
                                Working...
                                X