Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unique Entries?

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

    #31
    This is just becoming way too complicated for something that should be very simple.
    1. 2 unique orders Buy_1 and Buy_2.
    2. Each have 2 separate conditions for entry.
    3. Only one can be open at a time.
    4. Each has a profit target
    5. Each has a stop loss
    6. Each has a dummy indicator to view as a dashed line for the profit target price
    7. Each has a dummy indicator to view as a dashed line for the stop loss price
    8. Each entry has it's own IOrder representing Buy_1's order set
    9. Buy_1's Order set is Buy_1, Buy_1_Profit, Buy_1_Stop
    10. Buy_1's IOrder set is buy1entry, buy1target, buy1stop

    As to Thread 15, as per Josh's SampleCancelOrder.cs when buy1entry is filled as monitored in the OnExecution, buy1target and buy1stop are highly recommended to be launched from here. My question in Thread 15 was, "is this where I should say that Buy_1MarketPosition=Long since I just launched my "buy1target" and "buy1stop", since I'm assuming that Buy_1 is long at this point.

    "An order is not updated or executed as frequently as OnBarUpdate and thus you are only getting the Prints in OnBarUpdate"

    As to this statement above, if I do NOT put "Buy_1MarketPosition=Long" in the OnBarUpdate with the entry order and I DO put it in EITHER OnOrderUpdate or OnExecution, it DOES NOT Print.

    Let me know if you need any further clarification as to my objectives.

    Comment


      #32
      By the way in Thread 15 Long and Flat have 2 different conditions, so they are NOT reset immediately.

      Comment


        #33
        Hello kenb2004,
        You are setting the Buy_1MarketPosition to MarketPosition.Long if buy1entry position is filled/part-filled/cancelled.


        Code:
        #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
        } }

        Now say the buy1entry gets filled (thus Buy_1MarketPostion is set to long), then on the next part of the code you are resetting the Buy1MarketPosition to MarketPosition.Flat.


        Code:
        //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

        Please debug your code accordingly.
        JoydeepNinjaTrader Customer Service

        Comment


          #34
          I don't know if you read Thread 31 or not. You asked for specifcs, I gave you specifics. Based on my specifics where does
          Buy_1MarketPosition == MarketPosition.Long go and where does
          Buy_1MarketPosition == MarketPosition.Flat go?

          Comment


            #35
            Hello kenb2004,
            Do you want to place market entry orders or limit entry orders? If it is limit orders and the orders are not filled immediately then how do you handle such situation?

            I look to assist you further.
            JoydeepNinjaTrader Customer Service

            Comment


              #36
              I only use limit orders. That's what we've been talking about for days. If a limit order does not get filled it is Cancelled by the next entry order. I guess what I'm not understanding is the functionality of IOrders. I only started using IOrders because Ninja does NOT allow reversing with limit orders because NinjaTrader Internal Order Handling Rules forbid it. So I make sure to Cancel any Profit or Stop Limit orders and Entry Orders in the opposite direction before reversing. Again way too complicated for a very standard operation in trading.

              As you may already have guessed I am not a programmer by choice. I am a trader.
              Last edited by kenb2004; 04-02-2012, 02:22 PM.

              Comment


                #37
                Hello kenb2004,
                I do not see any cancellation criteria here. Nor do I could see any handling rules (like how to handle, if limit orders are filled etc).

                1. 2 unique orders Buy_1 and Buy_2.
                2. Each have 2 separate conditions for entry.
                3. Only one can be open at a time.
                4. Each has a profit target
                5. Each has a stop loss
                6. Each has a dummy indicator to view as a dashed line for the profit target price
                7. Each has a dummy indicator to view as a dashed line for the stop loss price
                8. Each entry has it's own IOrder representing Buy_1's order set
                9. Buy_1's Order set is Buy_1, Buy_1_Profit, Buy_1_Stop
                10. Buy_1's IOrder set is buy1entry, buy1target, buy1stop
                I would suggest you contact any of our NinjaScript consultants. You can get the list of our NinjaScript consultants from here http://www.ninjatrader.com/partners#...pt-Consultants

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

                Comment


                  #38
                  No, It is not necessary for me to give you any more specifics. It is irrelevent. I have explained over and over to you. I ask you questions and you answer my question with more questions. How I handle Cancellations is not relevant to my question.

                  Where does
                  Buy_1MarketPosition == MarketPosition.Long
                  go and where does
                  Buy_1MarketPosition == MarketPosition.Flat
                  go?

                  Your answer to putting the long position state in the entry condition has to be incorrect because it generates the wrong time stamp.

                  Yes all my entries and exits are limit orders. If you cannot answer this simple question please refer this thread to Josh or one of the other Customer Service reps that are more knowleable concerning this matter, especially since you have told me that Josh's code is wrong. I am not interested in consultants, just an answer to my original question. How to track the state of a unique entry.

                  thanks

                  Comment


                    #39
                    Hello,

                    This is Brett responding for Joydeep.

                    There is no exact place I would tell you where to put it, you can use it in OnOrderUpdate() or OnBarUpdate. Market position is normally used inside of OnBarUpdate() for most strategies however telling you were to place code would be more trading / strategy building advice again it just depends on how often you need to check it and when you need to make a decision to run some section of code. For most users I would recommend OnBarUpdate() as price movement is when you need to decide to place your orders anyways and this is what this variable is intended to prevent or allow you from doing so since almost all order decisions come out of OnBarUpdate().

                    Furthermore variables have scope, you would need to insure that your variables has a the scope needed so that you can access the variable if you choose to access the variable from outside of the method that created it. You do this by making sure the variable is declared in the variables section at the top of the code so all methods have access too it. Not sure if you are running into issue here or not.

                    Furthermore we will attempt to simplify this thread as much as possible here if you have further questions. To do this we will transform this thread into a basic question/answer thread with no more trading or coding advice. You ask a specific question we will give a specific answer as you request. This is how we are able to support you in the best manner possible, any coding advice would need to be done by a NinjaScript consultant however I would not mention that again as I believe you understand how far we are able to support at this point.

                    -Brett

                    Comment


                      #40
                      Brett

                      Thanks for responding.
                      Question
                      1. Have you read this thread in it's entirety?

                      Comment


                        #41
                        Originally posted by kenb2004 View Post
                        Brett

                        Thanks for responding.
                        Question
                        1. Have you read this thread in it's entirety?

                        Yes I have.

                        Comment


                          #42
                          Using the Managed Approach, is
                          MarketPosition == MarketPosition.Long
                          MarketPosition == MarketPosition.Short
                          MarketPosition == MarketPosition.Flat
                          internally generated by NinjaTrader?

                          Comment


                            #43
                            Originally posted by kenb2004 View Post
                            Using the Managed Approach, is
                            MarketPosition == MarketPosition.Long
                            MarketPosition == MarketPosition.Short
                            MarketPosition == MarketPosition.Flat
                            internally generated by NinjaTrader?
                            Correct for the ENTIRE strategy and specifically is is not just MarketPosition.(I believe you just quoted pseudo code but just in case)

                            It is:

                            Position.MarketPosition == MarketPosition.Long

                            As referenced here:



                            -Brett

                            Comment


                              #44
                              Correct, my apologies
                              Position.MarketPosition == MarketPosition.Long
                              Position.MarketPosition == MarketPosition.Short
                              Position.MarketPosition == MarketPosition.Flat

                              Since these position states are internally generated, and I am using 2 unique entries that generate limit orders and inturn generate Target and Stop Limit orders, I need to know how to Externally generate the equivilant states for my Unique Long, Short, Flat order positions.

                              2. How do you Externally generate the equivilant market postion states for Unique Long, Short, Flat order positions from limit orders?
                              Last edited by kenb2004; 04-03-2012, 08:50 AM.

                              Comment


                                #45
                                Correct, in this case you needed to track it yourself and essentially start submitting your own stop loss and profit target and really move out of the managed code we provide to make this simple.

                                This gets a little tricky and you need to have some coding experience to understand the concepts since NinjaTrader is setup primary for 1 position per strategy.

                                I have taken the extra time to create a sample for you as you seem interested in getting this to work. Please see the attached sample, I have only created the code for PositionA, you would need to add the code and duplicate for PositionB. It should at least show you what you would need to do instead of explaining it again as Joydeep has already done.

                                This code is not meant to be plug and play this is just for demonstration purposes only.

                                Let me know if any questions.
                                Attached Files
                                Last edited by NinjaTrader_Brett; 04-03-2012, 10:06 AM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by geotrades1, Today, 10:02 AM
                                0 responses
                                1 view
                                0 likes
                                Last Post geotrades1  
                                Started by rajendrasubedi2023, Today, 09:50 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post rajendrasubedi2023  
                                Started by ender_wiggum, Today, 09:50 AM
                                0 responses
                                4 views
                                0 likes
                                Last Post ender_wiggum  
                                Started by bmartz, Today, 09:30 AM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by geddyisodin, Today, 05:20 AM
                                3 responses
                                24 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X