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

VB.NET Q: Difference between LIMIT for ENTRY and LIMIT for EXIT...?

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

    VB.NET Q: Difference between LIMIT for ENTRY and LIMIT for EXIT...?

    Okay here is the problem I am running into....

    Please note that I am programming in VISUAL BASIC and not with the ninja script. So I am limited to using the API commands found at http://www.ninjatrader-support.com/H...tml?Functions2

    I am specifically calling the .command() function to place these orders, as it seems to be the only one that works.

    Say I want to place a LIMIT order to sell on a resistance line. Ok so I use the "LIMIT" command as order type, instead of using "MARKET", and I place the order on the resistance line. Well, let's say the market price doesn't go up to touch the entry price for a while, but the market price comes up to within 10 pips of it.... and then my program notices that the resistance line has moved a little bit, so I would like to update my current order, and adjust my entry limit spot, to be where the resistance line is now at...

    Now, I'm looking at the command "PLACE", which is what I would have used to initially put in my "LIMIT" order, for entry into the market. I now want to adjust the location of that entry point somewhat, and I see that there is another option instead of "PLACE", I can use "CHANGE"... which I could call, and supply the new limit price....

    MY QUESTION: if I call "CHANGE" on an order that is not yet in a live trade, and supply the new limit price, which I intended to be a new price for ENTRY INTO THE TRADE, and just as I'm doing that the market jumps up and touches my entry limit spot, and the trade becomes active... the just that instant, ninja trader receives my "CHANGE" command, which includes a new value for limit price, would not ninja trader think that I was placing a LIMIT FOR EXIT as opposed to a LIMIT FOR ENTRY order, and thereby ninja trader would put in a limit to EXIT the order right on top of where I just got into the trade, which would instantly exit me out of the trade with a loss of spread pips?

    If this is the case, then what is the best method for changing a LIMIT FOR ENTRY order, where the program could never mistake it for a LIMIT FOR EXIT order? Should the LIMIT FOR ENTRY order be completely canceled, and a new LIMIT FOR ENTRY order be placed in its stead? I'm sure that would work, however there is the risk that the market could move suddenly while the order cancellation is being processed, and the new order being placed, which would mean that there could be some additional lag and potential loss to do things that way... which lag could be reduced if there is a way to "CHANGE" the order's entry price, without it being potentially confused as an exit price.

    I know that's a complicated scenario. If anyone can let me know what the best method for doing this is, I would appreciate it. Thanks!

    Aaron

    #2
    I noticed...

    I noticed one of the ninja trader script experts on here (Josh) said that LIMIT and STOP (for exit) orders are entirely seperate orders, not directly attached to your order for entry. He said that on this thread: http://www.ninjatrader-support.com/v...ead.php?t=6339

    I want to verify that does NOT mean that I will be placing then two trades, and being charged double spread/commissions, just to get out of my order, after having gotten into it. That seems dumb.

    Comment


      #3
      Any order placed is a single separate order. There is no marking of entry or exit.

      If you submit a limit to sell order to enter a short position.
      Then change this limit price but in that split second, this order is filled, NT will ignore the request to change.
      RayNinjaTrader Customer Service

      Comment


        #4
        reply

        Ok but the question remains, is my broker (GAIN) going to think that I now had two trades going, because I placed two seperate orders? And/or is GAIN going to charge my the spread fee twice? Because I placed one order to buy, with no exit. Then placed another order to sell, with no exit. I now have two orders currently in the market, one selling, and one buying. Ninja trader might show that I have no active trades, but is that what GAIN would think?

        And finally... I need to know the exact difference in the command calls to update the order entry price, as opposed to updating the order exit price.

        Here is the command to place the order origonally:

        Ninja.Command("PLACE", Account, Symbol, "BUY", Quantity, "LIMIT", Limit_Price, 0, "", "", OrderID, "", "")

        I'm then thinking that, PRIOR to the order being filled, I would use the following command to update the order entry price as needed....

        Ninja.Command("CHANGE", "", "", "", 0, "LIMIT", Limit_Price, 0, "", "", OrderID, "", "")

        Which would change the limit price for that OrderID.

        Then, however, my confusion is that once the order is filled, I now want to add onto it a LIMIT for EXIT... (which yes, you said was a whole different order)...

        SO I could call...

        Ninja.Command("CHANGE", "", "", "", 0, "LIMIT", Limit_Price, 0, "", "", OrderID, "", "")

        Again?

        Now this is very frustrating to me because the same command simply cannot be used to place both LIMIT FOR ENTRY and LIMIT FOR EXIT orders. That is illogical and downright stupid and dangerous.

        So I'm assuming that both these two commands are not both used, identically, to place both those types of orders. Since you say that the LIMIT to EXIT order is a different order, would that not mean that it would require a different OrderID?

        And if it needs a new orderID, then wouldn't it be charging me seperate commission/spread with my broker? This is frustrating me.

        Aaron

        Comment


          #5
          answers...

          I had a chat with GAIN support and they answered my question about paying the spread twice...

          Now my only question remaining is, since the LIMIT order is a seperate order, I'm assuming it will need it's own unique Order ID? In the .command() call? (This applies to the API)

          You are now chatting with 'TJ'
          TJ: Hello and welcome to FOREX.com. How may I assist you?
          Aaron: I was wondering if stop loss orders are considered entirely separate orders, or if they are considered part of the original order?
          Aaron: the reason I ask is, I'm using ninja trader to place trades with GAIN, and they are telling me that their stop loss orders are completely seperate orders, and I was wondering if GAIN will then charge me the spread fees twice
          TJ: Ok.
          TJ: What other order are you placing in addition to the Stop?
          Aaron: The way I'm getting into the trade is with a limit order
          Aaron: when the market moves down, for a buy limit order, then it taps me in when it hits my buy limit price
          Aaron: I then place a stop order, supposedly to get me out of that trade... and I'm concerned that instead of getting me out, it simply places another order
          Aaron: to sell
          Aaron: I realize you may not know how ninja trader works, and that's ok.. but if you could tell me how GAIN handles stop loss orders, and if they are considered separate or not, that would help me
          TJ: Buying or selling an open position will either increase, reduce, or square the position.
          TJ: Orders don't pay out the spread unless they're already in a position. Stop loss orders can either be separate (single) or associated to a position.
          TJ: You pay the spread when you open the position - not when you close the position.
          Aaron: ok that's very helpful...

          Comment


            #6
            Unfortunately I really don't understand your questions...They seem like they should be directed to GAIN since you are asking me what they think

            I can answer questions on order submission.

            This is correct syntax for changing:


            Ninja.Command("CHANGE", "", "", "", 0, "", Limit_Price, 0, "", "", OrderID, "", "")

            Once filled, you could either

            - Submit a new sell limit order using the "PLACE" parameter or, you possibly leave/change the original sell limit you had in place

            With GAIN orders, there is NO concept of SELL or SELLSHORT. Orders just go in as a SELL. Maybe this is the area of confusion. This is actually true for every broker technology we support at this time. Most brokers take care of "marking" orders (when it is required by the exchange) with either a sell or sell short.

            Any clarification you need on how this may be handled or if it is even an issue you need to ask GAIN.
            RayNinjaTrader Customer Service

            Comment


              #7
              ...

              I am beginning to figure out how all this works...

              So can you verify to me that AFTER a LIMIT order is filled and executes the trade LIVE in the market, if I was to make any further attempts to use the...

              Ninja.Command("CHANGE", "", "", "", 0, "", Limit_Price, 0, "", "", OrderID, "", "")

              ...command on that same order ID that is now an active trade, to change the limit price, then that command will be automatically ignored or fail, because the trade is currently now active and live in the market?

              If that's true, then I'll be happy and all my problems and complaints are solved.

              I can understand if you are confused by my questions. In order to understand my questions, you have to think really hard.

              I was confused in thinking that the "CHANGE" command could both update an order and also potentially place a new order, because I thought that both limit for entry, and limit for exit, could be stacked on the same Order ID. But if you will deliver me from this thought, and tell me that once an order is live in a trade it can no longer accept any "CHANGE" commands to edit it's limit, and that any futher limit orders must then be placed with a new "PLACE" command on a new Order ID, then I'll go away and be very happy. lol.

              Comment


                #8
                ...command on that same order ID that is now an active trade, to change the limit price, then that command will be automatically ignored or fail, because the trade is currently now active and live in the market?

                >>> Correct.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  problems...

                  This is straight from Wikipedia on their "order" encyclopedia page:

                  A buy limit order can only be executed by the broker at the limit price or lower.

                  So why then is the program telling me, when I attempt to place a BUY limit order on the GBP/USD, when the current price displayed on the chart is currently around 1.9835, and I attempt to place a BUY limit order at the price of 1.9824, it says "Cannot place limit order above current ask price. Order affected: Buy @ 1.9824" (or something like that). This is in the simulation mode by the way. Where on earth does this program exactly think the ASK price is? 1.9824 is 11 pips below 1.9835, and the GBP/USD shouldn't be more than about 3 or 4 pips difference between ask/bid.

                  But I realize that it's trying to simulate the ask price, because I figure it doesn't really know what the ask/bid is, since I'm connecting to the e-signal data feed, meaning all it really knows is the candlestick data from e-signal charts, which doesn't give ask/bid? Well anyway, but the main problem is not so much that it's rejecting my perfectly good orders, but...

                  It's popping up this huge ugly error box when it does it!!! And I'm concerned about that error box, because I'm wondering if that error box will cause NJ to ignore all further orders, because maybe the error box locks it up some how until I click the OK button? Because I noticed that even though I had ran my system all night, it showed no more orders had been placed after that order had been rejected. This is with NJ 6.0, i'm trying it now on 6.5 to see if the problem goes away.

                  Comment


                    #10
                    grrrr!!

                    lol now I'm testing 6.5 and it says .marketposition(symbol, account) = 1 when I'm currently not in any trade. In other words, I buy, and then it says .marketposition (symbol, account) = 1, and then I see my order in the "positions" tab in NJ. Then I sell, and there are now no orders in the "positions" tab anymore, and I call .marketposition(symbol, account) and it returns a value of 1 still.

                    Because .marketposition(symbol, account) is the only way I know of to determine if I am in a trade or not. If that function is malfunctioning, then I have no way to inform my program when I have flattened my position!!! Because if I call the .OrderStatus() function, it simply returns "filled", but that can mean that I'm in the trade, or that the trade is over, that doesn't tell me my position. Ahhh!
                    Last edited by behealed; 04-02-2008, 09:02 AM.

                    Comment


                      #11
                      when...

                      I was running my program in debug mode when I posted my last post about the problem with the marketposition() function. So I was actually stopping the execution of my program right on the marketposition() call and observing exactly what ninja trader was sending back to my program, which was the incorrect value of 1.

                      Anyway, then in the course of time I ended up needing to restart my program again, in debug mode... and then .marketposition() was returning a value of zero, though nothing had changed. The only thing that restarting my program could have conceivable done was to disconnect the connection between my program and NJ, which maybe reset something within NJ and caused it to fix itself, so that it started to send correct information. That is not good, because I can't be needing to shut my program down and restart it every few minutes in order to find out what has happened to my position status in the market...

                      Comment


                        #12
                        hmm well..

                        Hmm well... everything now seems to be working correctly. Maybe it was just a one time problem

                        Comment


                          #13
                          Glad it worked out. If you have more problems please feel free to post it.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            subscribe market data

                            Well actually yes there are some bugs in the program :P

                            Like the .subscribemarketdata() function is totally messed up. If you call it, and go straight into a loop waiting for it to finish subscribing to the market data, constantly checking to see if .marketdata() returns anything other than zero, and the instant that .marketdata() gives you some data, you grab it and try to use it... God only knows what kind of crazy market price you will end up with. I've had it return figures that were over 60 pips above or below where the market was, in normal market conditions, and this is in the simulation mode where I am subscribed to esignal data.

                            Just to note: I do not know if the fact that I grab the data really quickly has anything to do with the problem. I only mention that because that's what I'm doing, and I want to make sure that you know I'm accessing the data that quickly. I take the data the instant that .marketdata() shows anything other than a value of zero, after calling the subscribemarketdata() function.

                            How about another bug...

                            If you don't call .unsubscribemarketdata() pretty soon after you use .subscribemarketdata(), then NJ seems to just quit getting new data from esignal, and the prices of where the market is at, and all the PnL of all active trades, just comes to a stop. lol. You then have to shut down NJ, and restart it, in order for it to begin downloading data from esignal correctly again. This applies to 6.0 NJ.

                            Fact is, it seems like .subscribemarketdata() is an unnecessary step, if NJ is already in an active trade on that symbol, it already should know what the market data is, and in that case if that function is called, then NJ should not open up a second connection to esignal.

                            Comment


                              #15
                              bugs...



                              Notice the blue arrow way up there.

                              Need I say anymore?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fx.practic, 10-15-2013, 12:53 AM
                              5 responses
                              5,403 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by Shai Samuel, 07-02-2022, 02:46 PM
                              4 responses
                              94 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by DJ888, Yesterday, 10:57 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by MacDad, 02-25-2024, 11:48 PM
                              7 responses
                              158 views
                              0 likes
                              Last Post loganjarosz123  
                              Started by Belfortbucks, Yesterday, 09:29 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post Belfortbucks  
                              Working...
                              X