Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

EnterLong and EnterShort mecanism

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

    EnterLong and EnterShort mecanism

    Hi
    I have a strategy and in a specific tick, i want to enter long or enter short. I need to know whether enter long work in just one tick or it continues trying to trade.


    Suppose that in the 3th tick, the strategy enters long if it does not success to buy, does it continue trying in the 4th tick and 5th tick and ..... or it stops buying at the next tick automatically.

    #2
    When you call EnterLong() or EnterShort() these methods result in a market order being sent to your broker.

    So, you have to consider network latency and other factors for how long it takes to execute.

    Whether 0 or 1 tick goes by between your EnterLong/Short and the execution of your order, or if 100 ticks or a 1000 ticks go by, it really depends on the volatility of the market (and your network latency).

    But yes, EnterLong/Short are not affected by these subsequent ticks that "fly by" after you enter your market order -- your broker must receive the order, validate your order against their margin rules & account requirements, etc, then send it to the exchange for execution --- none of which should be affected by subsequent ticks coming through (unless there are gabillions of other market orders all coming in within mere milliseconds of each other -- like I said, your order execution can be affected by extreme market volatility -- because your market order gets queued up for execution, and waits in line, perhaps behind those gabillion other orders, or perhaps in the middle, or the front, it just depends -- when your order reaches the exchange, it adds your order to the queue for that instrument, and how big that queue is when your order is added, well, I don't know how to know that -- but the point is: the depth of that queue is immaterial to how EnterLong/Short works in NinjaTrader).
    Last edited by bltdavid; 05-20-2018, 06:27 PM. Reason: Clarify EnterLong/Short sends market orders

    Comment


      #3
      How should i cancel the order? Suppose that i EnterLong in the first tick and i want to do that just for 1 tick. I'm aware of the network latency and .... but for example i want to EnterLong for the special tick and after that i want to do nothing (I mean no order), so what should i do? should i ExitLong()?
      Last edited by amiralimadadi; 05-21-2018, 01:45 AM.

      Comment


        #4
        Originally posted by amiralimadadi View Post
        How should i cancel the order? Suppose that i EnterLong in the first tick and i want to do that just for 1 tick. I'm aware about the network latency and .... but for example i want to EnterLong for the special tick and after that i want to do nothing (I mean no order), so what should i do? should i ExitLong()?
        Use CancelOrder to cancel your order.

        Be prepared to handle overfills, this sounds like a situation where they may occur.

        Also, IMHO, be aware that what you are trying is not guaranteed. For example, say you call EnterLong() but while it's busy doing its thing, X ticks go by, and then it returns. Your code won't know about these X ticks while they are happening because the NinjaTrader thread is inside EnterLong, and it hasn't returned control back to your code yet.

        Now, finally EnterLong returns, and you save the IOrder reference it gives you.

        Ok, so you detect that these X ticks went by while EnterLong was busy, and your code decides that since X > 1 it should now cancel the order. So, you pass the IOrder reference returned by EnterLong to CancelOrder -- and it is here that you might see overfill errors (an overfill is when an order returns "Filled" or "PartFilled" after the order was already marked for cancellation).

        Anyways, this is a very advanced area of programming. It sounds to me like you have a lot of reading to do, I recommend you become expert with the material here,

        Last edited by bltdavid; 05-21-2018, 04:19 AM.

        Comment


          #5
          Hello amiralimadadi,

          Thank you for your note.

          Both EnterLong() or EnterShort() are going to submit market orders, which should be filled upon submission assuming the market is open and the order is not rejected. If submitted and the order is not filled, likely the order was rejected (check the log tab).

          Unless your script resubmits an EnterLong call, the method EnterLong is not going to continue trying to buy on future ticks.

          Please let us know if you need further assistance.
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            Thank you.
            I have a multi frame strategy which is tracking 3 data series in 1 tick time period. Under some conditions we will EnterLong() the conditions are checked in OnBarUpdate() event. EnterLong would happen in any of these 3 data series and because OnBarUpdate is called in every tick, it may call EnterLong very much.

            First question : see this OnBarUpdate code
            if(BarsInProgress == 1 && conditions == True) EnterLong();
            if(BarsInProgress == 2 && conditions == True) EnterLong();
            now suppose that first if() is correct and EnterLong() is run, after that when OnBarUpdate is called with BarsInProgress = 2 and Conditions = True, i want to know that second EnterLong() is executed or it waits for the first EnterLong to be finished.

            Second question is do these 3 data series have their own thread? i mean for example i call enter long in the first data series, does the OnBarUpdate continue working or the thread is sleep until the EnterLong is finished?

            The third question: Is there any way better to send order request in multi frame strategy?
            Last edited by amiralimadadi; 05-21-2018, 02:26 AM.

            Comment


              #7
              Hello amiralimadadi,

              You could use entry handling and entries per direction to control how many positions the strategy will take total or per unique signal.

              Please see the following section of our helpguide,



              OnBarUpdate would continue working after your first EnterLong is submitted.

              Please let us know if you need further assistance.
              Alan P.NinjaTrader Customer Service

              Comment


                #8
                Thanks.
                But i didn't understand the concept well. i call EnterLong() in OnBarUpdate() for a tick period, but only the first one is submitted and all others are ignored. how can i handle it.

                I want to submit many EnteLong orders and i do not know the count of the orders.

                Comment


                  #9
                  Hello amiralimadadi,

                  You could set entries per direction to the max number of EnterLong calls you want to be executed.

                  For example,

                  Code:
                  if (State == State.SetDefaults)
                      {
                          EntriesPerDirection = 50;
                          EntryHandling = EntryHandling.AllEntries;
                      }
                  Would allow the strategy to enter 50 different entries.

                  Please let us know if you need further assistance.
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks. and how can i understand whether the order is filled or not

                    Comment


                      #11
                      Hello amiralimadadi,

                      There would be several ways you could check if an order was filled.

                      You could check in OnPositionUpdate,



                      Check if an order was filled in OnOrderUpdate,


                      Or within OnExecutionUpdate,


                      Please let us know if you need further assistance.
                      Alan P.NinjaTrader Customer Service

                      Comment


                        #12
                        does OnOrderUpdate returns the quantity of orders filled? I mean how can i know whether the order is fully filled or partially filled.

                        Comment


                          #13
                          Hello amiralimadadi,

                          Yes, you could check the fill quantity within OnOrderUpdate.

                          For example,

                          Print(order.Filled.ToString());

                          To check whether an order was completely filled or part filled, you could check the OrderState.

                          For example OrderState.Filled or OrderState.PartFilled.

                          Please see the following section of our helpguide which includes a sample of how you could check the orderstate of an order,



                          Please let us know if you need further assistance.
                          Alan P.NinjaTrader Customer Service

                          Comment


                            #14
                            Can i get it in OnExectionUpdate instead?

                            Comment


                              #15
                              Hello Amiralimadadi,

                              Yes you can.

                              You could copy paste the example out of the helpguide into a strategy, then put a “.” After the OrderState Object and you’ll see the different states you can check in OnExecutionUpdate.

                              OnExecutionUpdate HG:


                              Please see the attached screen shot.

                              Please let us know if you need further assistance.
                              Attached Files
                              Alan P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CortexZenUSA, Today, 12:53 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by CortexZenUSA, Today, 12:46 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post CortexZenUSA  
                              Started by usazencortex, Today, 12:43 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post usazencortex  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              168 responses
                              2,262 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X