Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unique Entries?

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

    Unique Entries?

    I have a strategy with 2 unique entries: Buy_1 and Buy_2. Each uses a different set of conditions to enter. How can I specify which Entry is Long when using a condition like?

    if (Position.MarketPosition == MarketPosition.Long)

    Do something;

    thanks

    #2
    Hello kenb2004,
    Thanks for writing in and I am happy to assist you.

    Unfortunately MarketPosition will not return the position of any particular order.
    To know the state of the individual order you can compare the IOrders.

    For example:

    in variable
    Code:
    IOrder Buy_1 = null;
    IOrder Buy_2 = null;
    in OnBarUpdate
    Code:
    if (condition)
    {
      Buy_1 = EnterLong("Buy_1");
      Buy_2 = EnterLong("Buy_2");
    }
    
    if (Position.MarketPosition == MarketPosition.Long && Buy_1 != null &&  Buy_1.OrderState == OrderState.Filled)
    {
       //do something
    }
    http://www.ninjatrader.com/support/h...tml?iorder.htm

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

    Comment


      #3
      if (Position.MarketPosition == MarketPosition.Long && Buy_1 != null && Buy_1.OrderState == OrderState.Filled)

      This appears to be watching a moment in time when the entry for Buy_1 was filled but not the continued state of the Long Position of Buy_1. I am presently using "buy1entry" IOrder as the entry order for the Long Position Buy_1, but I need a condition that monitors the Long Position Buy_1 for it's duration, not just it's fill.
      thanks

      Comment


        #4
        Hello kenb2004,
        Yes, there will be a time lag till the order gets filled. However you can also create a market position field for it

        in variable
        Code:
        MarketPosition Buy_1MarketPosition = MarketPosition.Flat;
        in OnBarUpdate
        Code:
        IOrder Buy_1 = EnterLong("Buy_1");
        Buy_1MarketPosition = MarketPosition.Long;
        
        if (Buy_1MarketPosition == MarketPosition.Long)
        {
          //do something
        }
        This way you wont have any lag, but do remember to take care if the order gets cancelled/rejected etc or when the position gets flats.

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

        Comment


          #5
          Am I not understanding your code correctly? If an entry order is filled does that mean there is an open position until an exit order is filled to close the position? Or does that mean that the entry order was filled, period?
          Last edited by kenb2004; 03-26-2012, 02:59 PM.

          Comment


            #6
            Hello kenb2004,
            If an entry order (IOrder object) is in filled state it means that the order was filled, period

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

            Comment


              #7
              OK, thanks. It looks like the:

              MarketPosition Buy_1MarketPosition = MarketPosition.Flat

              is the answer to my initial question.

              Thank you...

              Comment


                #8
                Hello kenb2004,
                Glad to know you got a solution.

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

                Comment


                  #9
                  Joydeep

                  As to your last statement "remember to take care if the order gets cancelled/rejected etc", since in managed approach NinjaTrader cancels working orders INTERNALLY "from order" Buy_1, how would I make
                  Buy_1MarketPosition = MarketPosition.Flat;
                  after the trade's round trip is complete?
                  thanks
                  Last edited by kenb2004; 03-27-2012, 02:44 PM.

                  Comment


                    #10
                    Hello kenb2004,
                    After the round trip, you can reset the Buy_1MarketPosition in the OnExecution event

                    Code:
                    protected override void OnExecution(IExecution execution)
                    {
                    	
                    	if (execution.Order != null && execution.Order.OrderState == OrderState.Filled && Buy_1 != null && execution.Order == Buy_1)
                    	{
                    		Buy_1MarketPosition == MarketPosition.Flat;
                    	}
                    }
                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for your assistance but I'm confused with the duplication of Buy_1. To clarify in my strategy "buy1entry" is the IOrder and Buy_1 is the Open Long Position. In your example where would my "buy1entry" IOrder go and where would the Buy_1 Open Position which is now closed go?
                      thanks

                      Comment


                        #12
                        Hello kenb2004,
                        In my sample code Buy_1 is the IOrder object and Buy_1MarketPosition is the MarketPosition. I only demonstrated how to code it.

                        Since I am not aware of the exact naming of the objects in your strategy, please modify the code accordingly to suit your needs.

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

                        Comment


                          #13
                          below is how I am attempting to monitor Buy_1MarketPosition.

                          protectedoverridevoid OnExecution(IExecution execution)
                          {
                          #region buy1entry // *****************************************
                          // If Long set buy1entry to null
                          if (buy1entry != null && buy1entry == execution.Order) {
                          if (execution.Order.OrderState == OrderState.Filled
                          || execution.Order.OrderState == OrderState.PartFilled
                          || (execution.Order.OrderState == OrderState.Cancelled
                          && execution.Order.Filled >
                          0)){
                          if (execution.Order.OrderState != OrderState.PartFilled){
                          buy1entry =
                          null;
                          buy1target = ExitLongLimit(
                          0, true, 1, Position.AvgPrice + PT * TickSize, "Buy_1_Profit", "Buy_1");
                          buy1stop = ExitLongStop (
                          0, true, 1, Position.AvgPrice - ST * TickSize, "Buy_1_Stop", "Buy_1");
                          Buy_1MarketPosition = MarketPosition.Long;
                          // Unique entry is long
                          } } }
                          #endregion

                          But I do not see how your code can possibly make Buy_1MarketPosition Flat.

                          protected override void OnExecution(IExecution execution)
                          {

                          if (execution.Order != null && execution.Order.OrderState == OrderState.Filled && Buy_1 != null && execution.Order == Buy_1)
                          {
                          Buy_1MarketPosition == MarketPosition.Flat;
                          }
                          }

                          Isn't your code saying, "if the execution order is not a working order, because the order was filled, and the buy1entry IOrder is not a working order, and buy1entry IOrder is the execution order"......

                          How does that make Buy_1MarketPosition Flat??? It seems to me that all your code is saying is the same as mine, that "buy1entry=null". Not that Buy_1MarketPosition is Flat.

                          Thanks
                          Last edited by kenb2004; 03-29-2012, 09:27 AM.

                          Comment


                            #14
                            Hello kenb2004
                            The below code sets the buy1entry to null and resets the Buy_1MarketPosition to flat.

                            Code:
                            //if buy1entry is long and fully filled then nullify it.
                            if (execution.Order != null && execution.Order == buy1entry && Buy_1MarketPosition == MarketPosition.Long && execution.Order.OrderState == OrderState.Filled)
                            {
                              buy1entry = null;
                              Buy_1MarketPosition == MarketPosition.Flat;  //reset Buy_1MarketPosition to flat
                              
                            }
                            The above is only a demonstrates how to get the information from the Buy_1MaketPosition. Please modify it accordingly.

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

                            Comment


                              #15
                              Ok, since all I'm looking for is how to monitor the Buy_1MarketPosition, would the following code accomplish this?

                              #region OnExecution //**********************************************
                              protectedoverridevoid OnExecution(IExecution execution)
                              {
                              #region buy1entry // *****************************************
                              // If Long set buy1entry to null
                              if (buy1entry != null && buy1entry == execution.Order) {
                              if (execution.Order.OrderState == OrderState.Filled
                              || execution.Order.OrderState == OrderState.PartFilled
                              || (execution.Order.OrderState == OrderState.Cancelled
                              && execution.Order.Filled >
                              0)){
                              if (execution.Order.OrderState != OrderState.PartFilled){
                              buy1entry =
                              null;
                              buy1target = ExitLongLimit(
                              0, true, 1, Position.AvgPrice + PT * TickSize, "Buy_1_Profit", "Buy_1");
                              buy1stop = ExitLongStop (
                              0, true, 1, Position.AvgPrice - ST * TickSize, "Buy_1_Stop", "Buy_1");
                              Buy_1MarketPosition = MarketPosition.Long;
                              // Unique entry is long
                              } }
                              //if Buy_1MarketPosition WAS long and NOW filled, then Buy_1MarketPosition IS Flat
                              if (Buy_1MarketPosition == MarketPosition.Long && execution.Order.OrderState == OrderState.Filled)
                              {
                              Buy_1MarketPosition = MarketPosition.Flat;
                              //reset Buy_1MarketPosition to flat
                              }
                              }
                              #endregion

                              thanks I appreciate all your help!
                              Last edited by kenb2004; 03-29-2012, 11:36 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Lyubomir Kratinov, Yesterday, 06:36 AM
                              3 responses
                              21 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Shai Samuel, Yesterday, 02:35 AM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Lowerlevel1, 07-01-2022, 11:12 PM
                              3 responses
                              40 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by ronaldgreene828, 07-01-2022, 10:21 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by BartMan, 07-01-2022, 06:49 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X