Hello
I have a question about how EasyLanguage or .Net will handle the following scenario.
I am trading a breakout FX strategy with Interactive Brokers. Sometimes a trade can be in play for several days - but a new trade is placed every single day. On one day I may have a bracket order with a Entry Buy Stop, Exit Sell Limit, & Exit Sell Stop orders for 85,000 units and the entry order gets filled. The next day, I may set a Bracket Order with an Entry Sell Stop, Exit Buy Limit, & Exit Buy Stop for 65,000 units and it would get filled.
From the accounting perspective I am now net long 20,000 units but I still have my Exit Sell Limit, Exit Sell Stop, Exit Buy Limit and Exit Buy stop orders all pending so from a strategy perspective I have two trades on - one long and one short.
The first question is: Can EasyLanguage or .Net correctly handle this?
The next scenario piggy backs off of the previous one.
Lets assume everything above is exactly the same but now, on the third day I enter another Bracket Order with Entry Buy Stop, Exit Sell Limit, & Exit Sell Stop for 95,000 units and the previous two trades have still not hit their profit targets or gotten stopped out so all previous pending orders are still active and waiting to be filled. Therefore, from an accounting perspective, I am net long 115,000 units but from a strategy perspective I have 3 trades actively running - each with unique pending limit orders and pending stop loss orders. Theoretically, a similar scenario to this can carry on indefinitely.
The second question is: Can EasyLanguage or .Net correctly handle this?
I should also mention that in the above 2 scenarios, the Exit Limit and Exit Stop orders will not need to be actively managed. They will remain at their original prices until either filled, or cancelled when the other side is filled.
Here is the 3rd scenario - and may only be immediately relevant if the above 2 scenarios are not possible; but, either way, it would be interesting to know the answer to this.
Is it possible to tell EasyLanguage or .Net, "Please just place the bracket order(s) based on the strategy requirements. After that, do not touch the trade anymore - your responsibilty is ONLY to place the orders." Then, any cancelling of the orders because the entry order didn't trigger or anything else would be done manually at the end of the day or something.
The 3rd question is: Is that possible?
Thank you for your help. Please let me know if you need any clarification. I am very eager for these answers.
Have a great day!
Forex Position Management with Interactive Brokers
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Forex Position Management with Interactive Brokers
EasyLanguage is quite an extensive programming language, it can pretty well do anything you can imagine and visualize.
The devil is not in the language, but how you program it to do what you want to do. From your description, you have a major project in your hands.
The devil is not in the language, but how you program it to do what you want to do. From your description, you have a major project in your hands.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Forex Position Management with Interactive Brokers
Based on how I understand/read these details, you're asking if PowerLanguage (.NET) can place different orders tied to a position and add new trades at certain moments in time (i.e., the new trade every single day requirement). Yes, that can be done. With the from entry reserved word, orders can be tied to specific entries. In PowerLanguage .NET something similar can be done.I am trading a breakout FX strategy with Interactive Brokers. Sometimes a trade can be in play for several days - but a new trade is placed every single day. On one day I may have a bracket order with a Entry Buy Stop, Exit Sell Limit, & Exit Sell Stop orders for 85,000 units and the entry order gets filled. The next day, I may set a Bracket Order with an Entry Sell Stop, Exit Buy Limit, & Exit Buy Stop for 65,000 units and it would get filled.
From the accounting perspective I am now net long 20,000 units but I still have my Exit Sell Limit, Exit Sell Stop, Exit Buy Limit and Exit Buy stop orders all pending so from a strategy perspective I have two trades on - one long and one short.
The first question is: Can EasyLanguage or .Net correctly handle this?
Isn't this the same scenario as the first, but only now with an additional entry (with accompanying orders)? So this would also work for both platforms.Lets assume everything above is exactly the same but now, on the third day I enter another Bracket Order with Entry Buy Stop, Exit Sell Limit, & Exit Sell Stop for 95,000 units and the previous two trades have still not hit their profit targets or gotten stopped out so all previous pending orders are still active and waiting to be filled. Therefore, from an accounting perspective, I am net long 115,000 units but from a strategy perspective I have 3 trades actively running - each with unique pending limit orders and pending stop loss orders. Theoretically, a similar scenario to this can carry on indefinitely.
The second question is: Can EasyLanguage or .Net correctly handle this?
Sure, you could code a strategy in both platforms as operating like "place these orders, and when the orders have been placed, don't do anything else except keeping these orders active until the end of the day (or whatever other condition)".Here is the 3rd scenario - and may only be immediately relevant if the above 2 scenarios are not possible; but, either way, it would be interesting to know the answer to this.
Is it possible to tell EasyLanguage or .Net, "Please just place the bracket order(s) based on the strategy requirements. After that, do not touch the trade anymore - your responsibilty is ONLY to place the orders." Then, any cancelling of the orders because the entry order didn't trigger or anything else would be done manually at the end of the day or something.
The 3rd question is: Is that possible?
Here's the catch: do you intend to run the platform 24/7, or do you shutdown the pc after trading each day?I should also mention that in the above 2 scenarios, the Exit Limit and Exit Stop orders will not need to be actively managed. They will remain at their original prices until either filled, or cancelled when the other side is filled.
In this latter case, your goals have become much more time consuming to achieve because then you'll need to store the open orders before closing MultiCharts, so that the next day these can be resubmitted (e.g., write them to a file and read from the file the next day).
Writing to and reading from a file in PowerLanguage requires the ELCollection add-on (search the forum for a lot more on this or see the source code of the EconomicEvents download in the User Contributed section that already implemented this). In PowerLanguage .NET you could use the already existing .NET features to read and write to files (i.e., StreamReader and StreamWriter, respectively, from the System.IO namespace).
(Note that, in the case of resubmitting your orders every day, you'll also lose your position in the order book.)
Edit: Personally, I think it's a good idea to just save the orders to a file, even if the platform runs 24/7. Then when a crash happens, you can reload the orders from the file and keep trading.
It should also be noted that the IB TWS daily reset might be a problem when you're trying to run trading strategies during that time window. But other users are more knowledgeable about that, so perhaps they can comment on that.
Re: Forex Position Management with Interactive Brokers
Thank you both for your answers.
Josh, I don't that I quite made myself clear enough - which is unfortunate because you gave a wonderfully detailed answer.
First of all, yes, scenario 2 is really simply an extension of scenario 1. But both scenarios could have far reaching consequences when attempting to code them and run them through Interactive Brokers.
Some may find it beneficial to even look at this NT thread where I am asking very much the same question and have gotten some extremely enlightening answers - which is why I am checking to see the way that MultiCharts handles this. Here is the thread: http://www.NT.com/support/foru ... hp?t=66686. The links that they provide to their documentation are also a very interesting read about the way that NT works with the code - and quite relavant to this post as well and how MC handles the same things.
The fact of the matter is, they are not multiple entries based on the same position. They are multiple entries based on the same currency pair and that is their only correlation between each other. They are completely separate trades and have nothing to do with each other. This is important to note because, I assume, that PowerLanguage/.Net require that the trades are tagged with a name in order to continue managing the trade after it is placed.
Your answer to the third scenario is very interesting and I greatly appreciate what you wrote. I would definitely restart the software & computer regularly. The followup question that I have, though, is: Can MC simply send the order to IB and leave it there? So it is active with IB but no longer managed by MC. It would show up in MC because the two are linked, but PowerLanguage/.Net will no longer have anything to do with it - it is ALL manual from that point.
Josh, I don't that I quite made myself clear enough - which is unfortunate because you gave a wonderfully detailed answer.
First of all, yes, scenario 2 is really simply an extension of scenario 1. But both scenarios could have far reaching consequences when attempting to code them and run them through Interactive Brokers.
Some may find it beneficial to even look at this NT thread where I am asking very much the same question and have gotten some extremely enlightening answers - which is why I am checking to see the way that MultiCharts handles this. Here is the thread: http://www.NT.com/support/foru ... hp?t=66686. The links that they provide to their documentation are also a very interesting read about the way that NT works with the code - and quite relavant to this post as well and how MC handles the same things.
The fact of the matter is, they are not multiple entries based on the same position. They are multiple entries based on the same currency pair and that is their only correlation between each other. They are completely separate trades and have nothing to do with each other. This is important to note because, I assume, that PowerLanguage/.Net require that the trades are tagged with a name in order to continue managing the trade after it is placed.
Your answer to the third scenario is very interesting and I greatly appreciate what you wrote. I would definitely restart the software & computer regularly. The followup question that I have, though, is: Can MC simply send the order to IB and leave it there? So it is active with IB but no longer managed by MC. It would show up in MC because the two are linked, but PowerLanguage/.Net will no longer have anything to do with it - it is ALL manual from that point.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Forex Position Management with Interactive Brokers
Sounds like you need to use the unmanaged orders from MC .NET, and if you want to (or need to) go that way, regular MultiCharts won't allow you to achieve your goal.Some may find it beneficial to even look at this NT thread where I am asking very much the same question and have gotten some extremely enlightening answers - which is why I am checking to see the way that MultiCharts handles this. Here is the thread: http://www.NT.com/support/foru ... hp?t=66686. The links that they provide to their documentation are also a very interesting read about the way that NT works with the code - and quite relavant to this post as well and how MC handles the same things.
That being said, I gladly let an official MultiCharts employee answer this topic so that I'm not misinforming you.
Re: Forex Position Management with Interactive Brokers
Thanks JoshMSounds like you need to use the unmanaged orders from MC .NET, and if you want to (or need to) go that way, regular MultiCharts won't allow you to achieve your goal.
That being said, I gladly let an official MultiCharts employee answer this topic so that I'm not misinforming you.
Do you expect that I would be able to do the "Just place the orders and the rest will be managed manually" using PowerLanguage?
The only addition that I would need to that is that if the Long Order is executed that it would automatically cancel the short order - but any of the rest of the managing of the trade I would do manually. Just use it for order entries? It would need to happen every single day and the trades could be on for multiple days so any new orders placed would not be allowed to effect the trades from the previous days.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Forex Position Management with Interactive Brokers
It's not that simple. In PowerLanguage, orders from strategies are kept active as long as they are resubmitted on every bar close (with Intrabar order generation off) or every tick (with intrabar order generation on). So if you want to do this:Do you expect that I would be able to do the "Just place the orders and the rest will be managed manually" using PowerLanguage?
The only addition that I would need to that is that if the Long Order is executed that it would automatically cancel the short order - but any of the rest of the managing of the trade I would do manually. Just use it for order entries? It would need to happen every single day and the trades could be on for multiple days so any new orders placed would not be allowed to effect the trades from the previous days.
MultiCharts cannot simply leave the order at IB, because as soon as your strategy stops resubmitting the order, the order is gone.Can MC simply send the order to IB and leave it there? So it is active with IB but no longer managed by MC. It would show up in MC because the two are linked, but PowerLanguage/.Net will no longer have anything to do with it - it is ALL manual from that point.
In the same vein, you cannot simply take manual ownership over automatically generated orders.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Forex Position Management with Interactive Brokers
Hello JGSmith,Can MC simply send the order to IB and leave it there? So it is active with IB but no longer managed by MC. It would show up in MC because the two are linked, but PowerLanguage/.Net will no longer have anything to do with it - it is ALL manual from that point.
JoshM has already provided all of the right answers, let me sum it up in regards to the last question:
- At the moment this can be done only in MultiCharts .NET using unmanaged order approach.
- In MultiCharts with PowerLanguage it will be possible once the new backtesting/auto trading engine is implemented in ver. 9.1: https://www.multicharts.com/pm/viewissu ... no=MC-1497