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

Forex Position Management with Interactive Brokers

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

    Forex Position Management with Interactive Brokers

    In one of my fx swing trading strategies, I am often long and short the same currency pair.

    So one day I may enter Long the EURAUD with 95,000 units and the next day I may be going short with 75,000 units leaving me net long with 20,000 units. Then, the next day I may go long another 85,000 units giving me a net long position of 105,000 units. Which is the way that IB handles these types of orders. But, from a strategy point of view, I am long 95,000 EURAUD; Short 75,000 EURAUD, & Long 85,000 EURAUD.

    This poses a few questions as I am working on coding this strategy into NinjaScript.

    if, in the OnBarUpdate(), I have

    if (XYZ)
    EnterLongStop(PositionSize, EntryPrice, "breakoutEntryLong");

    if(XYZ123)
    EntryShortStop(PositionSize, EntryPrice, "breakoutEntryShort");

    How will this effect order management for my two long positions?

    For example, I would want a sell stop price and a sell limit price to get out with a loss or profit. But, if both orders are titled "LongBreakout", will this not cause both of them to exit at the same price when, normally, they would be exiting at different prices?

    The answer to this will effect the direction to my other questions so I will wait until this is answered before I start posing the next ones.

    Thank you for your help

    Edited - Additional Question
    There is no need for me to adjust the orders when the trade is active (such as moving the stop price or limit price). Is it better for me to use an IOrder in this situation or just something like above using the EnterLongStop, etc?
    Last edited by jg123; 06-10-2014, 08:14 AM.

    #2
    Hello jg123,

    Thanks for you post and questions.

    To help me understand how best to help you, I have the following questions:

    1. Are you using more than one account to be both long and short?
    2. Are you syncing your account and strategy positions?
    3. Are your prior orders placed with "EnterLongStop(PositionSize, EntryPrice, 'LongBreakout');"

    I look forward to your response.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul

      Thank you for getting back to me

      1.) No, it is all in one account. I know that is probably a bit confusing which is why I tried to express it in Net Units. But my stop & limit orders remain thus making it like a hedge.
      2.) I would assume that this is answered in the previous answer.
      3.) Currently they are placed that way, but I am not sure if I should be using IOrder or not.

      Should I also mention that I am a money manager and so I do have multiple accounts that I manage at Interactive Brokers, but it is not a separate account that holds the Long positions from the Short positions. All positions are placed in all accounts.

      Does that help you a bit? Let me know if you need more clarity.

      Thanks!

      Comment


        #4
        Any updates on this? Thanks for your help!

        Comment


          #5
          jg123, sorry for our late reply here. Generally your NinjaScript strategy instance will only have one strategy position, just like your account position. It would only express basically the net units you refer to. It would not matter which entries you take or in which succession, at each point after execution the strategy position would update to the new net position. The IOrders interface will give you just a higher level of readonly detail as far as your orders / executions go.

          You can definitely process multiple signals in one script, here's a sample showing the concepts at play - http://www.ninjatrader.com/support/f...ead.php?t=3225

          If you want to scale out of positions later in the trade, it would be important to scale in first (when using the managed approach in NT) -



          The main point here is, that in all circumstances > you will only have one overall strategy position per instrument traded.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thank you very much for getting back to me.

            So a bit more to clarify.

            In my IB account, when I set an Enter Buy Stop order is triggered and I am long, then there are 2 other orders that are then waiting to be triggered - an Exit Sell Limit and Exit Sell Stop. Then when I go short with the Entry Sell Short the same, and opposite, orders are pending. Meanwhile, the original long orders are still there pending.

            So to clarify, will NinjaScript trade it exactly this way for long and short?

            And, in fact, this strategy could also have, theoretically, unlimited positions going in one direction - all with different exiting prices. So the first example that you gave will allow me to do that?

            Just want to make sure that I really understand your answer very clearly.

            Thanks again for your help. You guys are always so great!!

            Comment


              #7
              You're welcome, thanks for the kind words.

              'In my IB account, when I set an Enter Buy Stop order is triggered and I am long, then there are 2 other orders that are then waiting to be triggered - an Exit Sell Limit and Exit Sell Stop. Then when I go short with the Entry Sell Short the same, and opposite, orders are pending. Meanwhile, the original long orders are still there pending.

              So to clarify, will NinjaScript trade it exactly this way for long and short?'

              Unfortunately not, as in our managed approach you would need to consider the internal order handling rules - https://www.ninjatrader.com/support/...d_approach.htm (bottom section of this page please). Those are true per all non market orders, so if you're issueing orders to reverse those could get ignored with the exits protecting the other 'side' position. Best is getting used to working with our TraceOrders feature closely as this would definitely help in debugging the order issue process seen under the hood for your script - http://www.ninjatrader.com/support/f...ead.php?t=3627

              Our unmanaged mode in contrast would not be safeguarded by those rules, but for that freedom your script will need to manage orders with an increased responsibility then.

              In the same direction, you can enter any amount of positions correct - the EntryHandling would define the boundaries - https://www.ninjatrader.com/support/...ryhandling.htm
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Okay, Thanks!

                So this may require some real creativity to make it all work.

                Is there a way to say, "NinjaTrader, please place this Bracket Order (buy stop for entry, sell limit for exit, & sell stop for exit [just doing long for sake of example]) and then no longer manage this trade."

                That way, it could just simply automatically place my orders for me and then it is through with its work on the trade and the orders stay with in Interactive Brokers and not managed by NinjaTrader. Then, the next day, regardless of what orders or positions are in Interactive Brokers, NinjaTrader would simply see the market condition and place the Bracket Order and then, again, be completely done with managing it the trade.

                Comment


                  #9
                  Hello jg123,

                  Thank-you for your post and questions. There are two way to accomplish "... 'NinjaTrader, please place this Bracket Order (buy stop for entry, sell limit for exit, & sell stop for exit [just doing long for sake of example]) and then no longer manage this trade.'

                  Approach 1 is to use unmanaged orders, this will provide you with the flexibility to place bracket OCO orders but you will need more coding to handle the orders and there are many considerations that you must account for. The unmanaged order information can be found here: http://www.ninjatrader.com/support/h...d_approach.htm

                  Approach 2 is a combination of your ninjascript developed entry method and utilize an ATM strategy to handle the profit target and stop(s). The benefit of such an approach is that you can use the NinjaScript strategy to generate automated entry signals and once entered, you can delegate exit management to an ATM strategy which allows you degrees of manual control over how to close out of a trade. You will need to ensure that your ninjascript has conditions to test when and when not to trade otherwise you may end up in multiple positions. Please see the help guide section: http://www.ninjatrader.com/support/h...gy_methods.htm

                  Please let us know if we can be of further assistance.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    This is very good information. Thank you

                    I am not a "very experienced programmer," as it mentions i the unmanaged order information, in fact, I am not even really an "experienced programmer" bur I am always up for the challenge.

                    Initially I would think that the second option would then be the best in order to keep the code simpler, but you used the phrase "degrees of manual control over how to close out of a trade." The problem is, I will not be around in order to manually set the stop and limit orders.

                    Before deciding which approach to start taking, I need one more item clarified. But first, a little about the strategy:

                    The strategy is based on a measuring a premarket open range that develops. From here, I will either go long or go short as it breaks out of that range. The stop is the placed on the other side of the range and the limit order is placed at a multiple of that range (1x the size of the range or 3.5 x the size of the range, etc).

                    What I need to know is, will I, through NinjaScript, be able to measure the distance of the range and then, through ATM, place the stop and limit orders?

                    I have watched the ATM training video and haven't seen this type of functionality there - but it may be because it is a more advanced feature with in it. If this is possible, then I will go with using the ATM, if it is not possible, then I will have to go with the unmanaged approach.

                    Comment


                      #11
                      Hello jg123,

                      With the 2nd option you need to understand that your ATM strategies would be predefined, so in that regard you could create multiple strategies and then through your ninjascript decision making, employ the appropriate template for your situation.

                      Strategy programming, especially unmanaged, can be a complex process. Here is a link to 3rd party programmers that you might want to consider: http://www.ninjatrader.com/Ecosystem/NonBroker.php#81

                      Please let us know if we can be of further assistance.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you for that list.

                        To be honest, I am struggling with this a little bit (no judgement and not upset - just really needing to think through this). After testing out this software and using it to learn how to code, I was literally within 2 weeks of finally purchasing it and going with the lifetime license. This is now pushing me back a little ways if I can't really work through. In general, I don't really want to pay someone else to code this for me which is why I have been investing all of the time in to learning how to write the code for this strategy and another one.

                        Okay, venting over - next question.

                        A very plausible solution, and one that would even inspire me to purchase the software next week or the week after would be if I could even just get Post #8 to work.

                        So, if I understand you correctly, the only two ways of utilizing NinjaTrader to only place the orders for me and not continue to manage them after that is by going with the Unmanaged approach or by splitting the task with NinjaScript and ATMs? Am I understanding you correctly?

                        Again, all I need is that it would place a bracket order with a Enter Buy Stop/Exit Sell Limit/Exit Sell Stop and/or Enter Sell Stop/Exit Buy Limit/Exit Buy Stop. Then, the only other thing that I would ask of it is that if one of the Entry orders are executed then it would automatically cancel the other one.

                        Initially, I am very happy to control all of the rest of it manually - it is just imperative that I can get the Bracket Order placement automated on a daily basis. I will start needing to be gone during the time of day that I need to place the orders and therefore I am looking for this solution.

                        Thank you very much for your help
                        Last edited by jg123; 06-12-2014, 07:49 AM.

                        Comment


                          #13
                          Hi jg123, thanks for the detailed follow up and we understand you've invested a lot learning the framework and now wanting to complete the programming yourself. A consultant might still be a good consideration, since you would still get 'your' code for review, learning and as potential starting point for next projects, a thought oftentimes I feel forgotten.

                          For trading in this manner, you would not want the managed mode rules for sure - that's correct in understanding. For the ATM's you would need to consider that you could not back-test their operation (just in replay or simulation) and that this wouldn't be an atomic operation, so the exit orders protecting the position would only be seen / send once the initial entry has filled. The advantage here is that the UI defined exit template / stop strategies could be employed directly.

                          For Unmanaged you would really have the flexibility to submit any orders / sequence you desire and there would be no rules govern any submission - this would include OCO'ed orders in entry or exit.

                          We generally do not advise to consider letting the setup operate as a black box though, so leaving for example an automated operation unattended in operation during the day session for extended periods of time. So regular supervision would still be needed and recommended.

                          All the best.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Thank you very much!

                            It is okay, in the first phase, that I am not able to backtest. Running it in Replay and Simulation will suffice for the current needs. If the code is working correctly, the strategy works fine as it is what I am currently trading.

                            I am sure that it has been clearly answered on here, but I am still just a little fuzzy in my understanding. Without using a unmanaged approach, is it possible to have NinjaTrader just automatically place my Long & Short Bracket Orders and cancel, for example, the Short bracket order if the Long one is triggered & filled? The rest would be handled manually. The distance between the entry and the stop, and the entry and the target, will be different every single day so I could not preprogram an ATM strategy.

                            In a future phase I will probably go with an unmanaged approach. Also, that is a great thought about getting the professional help and then using that to help teach me about the code. I will definitely utilize that idea.

                            Comment


                              #15
                              Hello Jg123,

                              Thank you for your reply.

                              Bracket orders are only possible with the Unmanaged approach in NinjaScript.
                              This kind of flexibility allows you to place your bracket orders with a OCO ID attached to them and let them go knowing that the other will get cancelled when the other is filled.

                              Additionally, we have a reference sample on how to detect the execution and then place protective orders for your open position, and again attach and OCO ID to the orders. You will also have the flexibility to change your orders if you want to move your protective orders around with the market.

                              Note that this uses the Managed approach for example but follows the same IOrder tracking that you need for getting the Order Object and its fill.
                              http://www.ninjatrader.com/support/f...ead.php?t=7499

                              Please let me know if I can be of further assistance.
                              Cal H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, Today, 10:57 PM
                              0 responses
                              2 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, Today, 09:29 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post Belfortbucks  
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              151 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Working...
                              X