disconnect at night and Limit Order sync

Questions about MultiCharts and user contributed studies.
User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

disconnect at night and Limit Order sync

Postby siscop » 01 Mar 2011

I have a problem with my limit orders at IB. The strategies are disconnecting at night – don’t know why. Gateway itself is still connected to IB so why aren’t the strategies?
1. After restarting the strategy does the strategy realize that there are open position that they have to handle? If not how do I sync the strategy to do so? They still have to go thru the different exit strategies.
2. My Limitentries should only be valid for that day. So I set the properties to “DAY” instead of “GTC”. The problem is that one of my exitstrategies are SetProfitTartget and SetStopLos which are also only valid for the “DAY” but they shouldn’t I want them to be valid until the position is closed. How should I configure this? Or should I set it to “GTC” and let the strategies look for open Limit orders and cancel them? When yes how?

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: disconnect at night and Limit Order sync

Postby siscop » 02 Mar 2011

There has to be a way to avoid this deactivation at night (times are GMT+1).
Attachments
veraenderung.png
veraenderung.png (38.97 KiB) Viewed 500 times

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: disconnect at night and Limit Order sync

Postby TJ » 02 Mar 2011

what is your time-out setting?

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: disconnect at night and Limit Order sync

Postby siscop » 02 Mar 2011

120 sec. (default)
Is that to low? If that is the problem what would you enter as timeout?
In the logs it said something about setting change (last post pic) and not a timeout. Is it the same error msg?
Attachments
timeout.PNG
timeout.PNG (24.8 KiB) Viewed 485 times

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: disconnect at night and Limit Order sync

Postby TJ » 02 Mar 2011

you can try this as a starter
viewtopic.php?f=1&t=8190&p=38217

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: disconnect at night and Limit Order sync

Postby siscop » 02 Mar 2011

wow 24h setting is extreme, but I will try it. Thank you for that answer.

Is there a way to tell the strategy to sync with the broker for open positions? Something like… Hey look for an open AAPL order. That is yours - so deal with it.

And my second problem with the setprofittarget? It comes out as a DAY limit order but it should be valid until the position is closed. If I change it to an GTC order the limitentry would be one too and I want that entry order to be a DAY. Is there a command in powerlanguage that I can use to set the GTC to a DAY order and leave the others as default (GTC)?

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: disconnect at night and Limit Order sync

Postby TJ » 02 Mar 2011

Assume the following when autotrading:

1. The same symbol should not be traded from more than one strategy or chart. Trading the same symbol from two or more strategies/charts will cause a market position conflict between the strategy and broker.

2. The market position at the broker must be 0 at the time when auto trading is launched.

3. A trader must not trade the symbol through other means (eg. manual trading) while autotrading the same symbol through MultiCharts platform.




[edit] replaced "cannot" with "should not" in the underlined text above.

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: disconnect at night and Limit Order sync

Postby siscop » 03 Mar 2011

The timeout wasn’t the solution.
I still have the problem :-(
Attachments
zeit.PNG
zeit.PNG (25 KiB) Viewed 485 times
schliessung.PNG
schliessung.PNG (55.31 KiB) Viewed 464 times

User avatar
Henrik
Posts: 140
Joined: 13 Apr 2010
Has thanked: 25 times
Been thanked: 11 times

Re: disconnect at night and Limit Order sync

Postby Henrik » 03 Mar 2011

I have the same problem...strategy disconnect every night with IB.
Please fix it!

janus
Posts: 747
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 83 times

Re: disconnect at night and Limit Order sync

Postby janus » 06 Mar 2011

I don't think setting a really long time-out helps because IB does a reset on their servers every 24 hours during the working week leading to an event that is different from a disconnect event cause by say an internet outage. Perhaps MC distinguishes the interruptions and explains why it behaves the way it does. If this is the case, and I'm not sure if it is, then MC has to fix the issue at their end.

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: disconnect at night and Limit Order sync

Postby siscop » 08 Mar 2011

I just wanted to give a short update to this problem. It might be interesting to some people who have the same issue.
initial situation:
Gateway (4001) running,
TWS (7496) running with other username // needed for other items and position observation
Connection from Gateway and TWS live – not paper
QM connected to 4001
MC connected to 4001

HelpDesk wasn’t a big help (*1) so I have scanned my system over and over again to see where this error may have come from. One of the scans showed that the settings of QM under Interactive Brokers the port was on 4001 BUT it also had a mark on “Launch Trader Workstation at start” which didn’t make any sense with the port 4001. So I deactivated this box and closed the TWS.
It seems like when Gateway and TWS are running on the same system – even though the port setting should make a different – it comes to a conflict of some kind. The disconnect haven’t happened for 2 days. Hope it keeps on.



*1
HelpDesk downloaded my Logfiles and wrote me that I had my timeoutsettings to 120sec. I have answered that they have to check the more recent logs they downloaded where they can see the settings of timeout 86400 with the same error happening. I haven’t got an answer yet.

TWS
The TWS logout time was updated every 12h – the time of the strategy disconnect was NOT the time of the TWS logout since TWS was never offline / never log out.

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: disconnect at night and Limit Order sync

Postby arjfca » 09 Mar 2011

siscop wrote:120 sec. (default)
Is that to low? If that is the problem what would you enter as timeout?
In the logs it said something about setting change (last post pic) and not a timeout. Is it the same error msg?


Hello siscop

I use 600 sec, 5 minutes for my delay. All work fine (at least for the disconnection problem :) )

Martin

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 18 Nov 2011

TJ wrote:Assume the following when autotrading:

1. The same symbol cannot be traded from more than one strategy or chart. Trading the same symbol from two or more strategies/charts will cause a market position conflict between the strategy and broker.

2. The market position at the broker must be 0 at the time when auto trading is launched.

3. A trader must not trade the symbol through other means (eg. manual trading) while autotrading the same symbol through MultiCharts platform.


Hi TJ,

I saw the below and am just starting to use MC live next week. I have a question or two re. the below.

Firstly, I figured out that using more than one strategy on the same chart (and symbol) risked causing a mess, especially as my exits check for Marketposition<>0.

However, would you kindly explain Point 1 above a bit more? E.g. one symbol I plan on trading uses 4 strategies (now on 4 different charts to avoid the above problem). You make it sound like this could be a problem, so how should one do this i.e. what MC EL words/functions to use so as not to confuse positions across strategies?

Finally, if I follow what I write above, I will have something like 16 charts that could each hold a position. It seems to be a bit of a pain to manually reconcile open positions at the start of each day (many of these may hold overnight). So do/would you trust MC to run all week? If so, would the position syncing with IB work OK if I only do a manual IB TWS restart once/day?

thank you for your insights

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: disconnect at night and Limit Order sync

Postby TJ » 18 Nov 2011

thutch wrote:
TJ wrote:Assume the following when autotrading:

1. The same symbol cannot be traded from more than one strategy or chart. Trading the same symbol from two or more strategies/charts will cause a market position conflict between the strategy and broker.

2. The market position at the broker must be 0 at the time when auto trading is launched.

3. A trader must not trade the symbol through other means (eg. manual trading) while autotrading the same symbol through MultiCharts platform.


Hi TJ,

I saw the below and am just starting to use MC live next week. I have a question or two re. the below.

Firstly, I figured out that using more than one strategy on the same chart (and symbol) risked causing a mess, especially as my exits check for Marketposition<>0.

However, would you kindly explain Point 1 above a bit more? E.g. one symbol I plan on trading uses 4 strategies (now on 4 different charts to avoid the above problem). You make it sound like this could be a problem, so how should one do this i.e. what MC EL words/functions to use so as not to confuse positions across strategies?

re: so how should one do this?

ans: don't do it.

Trading more than one strategy on the same symbol is like multiple chefs cooking the same broth. If the left hand does not know what the right hand is doing, you are going to have a soup that is too salty to drink.

If you want to trade multiple strategies, be prepared for multiple surprises. There is no single MC EL words/functions silver bullet that can save you from mass confusion and complication. The key is -- you have to program intelligent into your strategies so that your left hand knows what the right hand is doing at all times.

If you insist on trying it out, I would suggest you to first draw up a flowchart, which should detail every permutation and every scenario of what could happen with your strategies, and your solution to such situations.

thutch wrote:Finally, if I follow what I write above, I will have something like 16 charts that could each hold a position. It seems to be a bit of a pain to manually reconcile open positions at the start of each day (many of these may hold overnight). So do/would you trust MC to run all week? If so, would the position syncing with IB work OK if I only do a manual IB TWS restart once/day?

thank you for your insights

re: So do/would you trust MC to run all week?

Even big investment/trading houses would not leave an autotrade unattended. They have all the professional programmers and professional computer scientists and professional traders who can design a fail-safe system, and they would still not leave it alone !!! Should you?

I know this is not the answer you wish to hear from me. If you still want to trade 16 charts/strategies but don't know how to do it, may I suggest you speak to a professional programmer for assistance.
These users thanked the author TJ for the post (total 2):
thutchJoshM

PricePuzzle
Posts: 38
Joined: 21 Aug 2011
Has thanked: 14 times
Been thanked: 16 times

Re: disconnect at night and Limit Order sync

Postby PricePuzzle » 18 Nov 2011

thutch wrote:Finally, if I follow what I write above, I will have something like 16 charts that could each hold a position. It seems to be a bit of a pain to manually reconcile open positions at the start of each day (many of these may hold overnight).

The idea is to store your value (position) in seperated text file for each chart. And read/restore it back when you start auto trading. Try to search for "Global Variables"

Then you have to adjust your position on charts by
1) http://www.multicharts.com/discussion/viewtopic.php?f=1&t=9206
==========================================
34. ChangeMarketPosition (This i am not sure, check again, i believe one of new keyword can help)

Places the order with set name and price on the chart. Though when auto trading is off the order will not be sent to a broker.
Notes
Can be used as a mean of synchronization of strategy market position with a broker
==========================================
Personally i manually input since i do it once a week.

2)The easiest way is to use "Print" keyword and keep the output in file. But you still have to input manually one by one when start autotrading.

Avoid to use more than 1 strategy in 1 chart because you will get too complicate position i.e. 1 short + 1 long = flat position.
These users thanked the author PricePuzzle for the post:
siscop

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 19 Nov 2011

Thanks to both of you for your replies.

I will investigate both ways further i.e. flowchart & combining strategies in a single chart, and storing positions in a file.

Initially manually inputting positions each day should suffice I believe. Specifically, if each strategy & chart knows its position, the MarketPosition check will be against that chart (I'm not programming it to check MP with broker) so that should work to keep each strategy independent, shouldn't it?

User avatar
Henry MultiСharts
Posts: 8397
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2686 times

Re: disconnect at night and Limit Order sync

Postby Henry MultiСharts » 21 Nov 2011

Yes that is correct. If you know the exact position for the strategy on each chart-you can assign the market position before turning on the auto trading, and it will keep each strategy independent.

Please do the following:
Format-> Strategy properties-> Auto trading-> Assign the initial market position at the broker setting->Show the assign the initial market position at the broker dialogue-> Show always-> Ok.
When you start the auto trading - a dialogue window will appear where you can set the position for the strategy.
These users thanked the author Henry MultiСharts for the post (total 3):
siscopthutchJoshM

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 21 Nov 2011

Henry Multicharts wrote:Yes that is correct. If you know the exact position for the strategy on each chart-you can assign the market position before turning on the auto trading, and it will keep each strategy independent.

Please do the following:
Format-> Strategy properties-> Auto trading-> Assign the initial market position at the broker setting->Show the assign the initial market position at the broker dialogue-> Show always-> Ok.
When you start the auto trading - a dialogue window will appear where you can set the position for the strategy.


Hi Henry,

I think I will start out this way and will look into the other contributors' suggestions shortly.

One last point for clarification: if there are >1 contracts traded for each of the strategies / charts, and let's say that these are limit orders so you can't be sure they will all fill, will MC position tracking work equally correctly? I.e. will the chart know that 2 out of 3 contracts was filled, and equally when unwinding the position at some future time will the correct number of contracts be reversed?

thank you

User avatar
Henry MultiСharts
Posts: 8397
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2686 times

Re: disconnect at night and Limit Order sync

Postby Henry MultiСharts » 21 Nov 2011

Unfortunately you cannot assign a partially filled position.
You need to wait until the position will be filled and then turn on auto trading.

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 21 Nov 2011

Henry Multicharts wrote:Unfortunately you cannot assign a partially filled position.
You need to wait until the position will be filled and then turn on auto trading.


I'm not sure I follow you. Would you clarify 'partially filled position"? I see that when assigning an initial position you can choose to enter the number of contracts you are long or short. But that is not what you mean?

Here is an example that may help clarify what I would like to know:

If autotrading is turned on when the position is flat, and subsequently 2 of 3 limit order contracts get filled which are to be exited during the same session... what happens? E.g. here are the entry and exit lines in power language..

... sellshort 3 contracts next bar at Close limit; (entry)
... buytocover next bar at Close limit; (exit)

Does buytocover know you are covering 2 contracts rather than the initial 3 you tried to enter? I.e. will the SA mode track this?

thank you

PS to be 100% sure there is no confusion, as per my original post I'm talking about tracking positions on the same symbol over different charts, each of which has its own strategy. Will 'marketposition' handle this or do I need the new "marketposition_at_broker_for_the_strategy", or?
Last edited by thutch on 22 Nov 2011, edited 2 times in total.

User avatar
Henry MultiСharts
Posts: 8397
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2686 times

Re: disconnect at night and Limit Order sync

Postby Henry MultiСharts » 22 Nov 2011

Partially filled position means that 2 of 3 orders are filled at the broker and you are assigning the market position at this moment.

When autotrading is assigned with the flat position, and the strategy buys 2 of 3 limit order contracts, MultiCharts knows that it should buytocover 2 contracts.

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 22 Nov 2011

Henry Multicharts wrote:Partially filled position means that 2 of 3 orders are filled at the broker and you are assigning the market position at this moment.

When autotrading is assigned with the flat position, and the strategy buys 2 of 3 limit order contracts, MultiCharts knows that it should buytocover 2 contracts.


Thanks for clarifying. As my final question, would you please respond to my PS of the last post?

User avatar
Henry MultiСharts
Posts: 8397
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2686 times

Re: disconnect at night and Limit Order sync

Postby Henry MultiСharts » 22 Nov 2011

Do you mean-which of the words will help to automatically reconcile open positions for each chart at the start of trading?

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 22 Nov 2011

Henry Multicharts wrote:Do you mean-which of the words will help to automatically reconcile open positions for each chart at the start of trading?


I'll try to be as clear as I can:

1) Intraday trading

I'm primarily concerned that positions are correctly assigned to strategies during the trading day when I have 3 charts live each with its own strategy on the same symbol. And each of these 3 strategies could trade >1 contract using limit orders, which requires broker synchronisation to know how many contracts got filled from any particular limit order. I got the impression that the different strategy positions may cause confusion as the broker will only report one total position for each symbol (they have only one total position for the 3 strategy positions). Because each of my strategies (in Powerlanguage) needs to do its own, independent position check, I don't want to run the risk of the different strategy positions getting mixed up.

If each strategy uses "marketposition" to know whether a position is on, would MC be able to distinguish between the different strategies and their respective positions in SA mode? If not, how can this be done?

2) Positions on MC restart

This is a lesser concern, however it would be nice not to have to manually input the initial position each day for each strategy. If there is a way to automatically reconcile and assign positions to different strategies on restart (for the 3 strategy case described above), please let me know how.

thank you

User avatar
Henry MultiСharts
Posts: 8397
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2686 times

Re: disconnect at night and Limit Order sync

Postby Henry MultiСharts » 23 Nov 2011

1) "marketposition" and "marketposition_at_broker_for_the_strategy" are indicating the position at the broker only for the filled orders.
"marketposition_at_broker" are indicating the current position at the broker.
If you want to use the current position at the broker for the scripts trading on the same symbol-you need to calculate the current position for the script in your code.
2) There is no way to automatically reconcile and assign positions to different strategies on restart. You need to manually input the initial position each day for each strategy.
These users thanked the author Henry MultiСharts for the post (total 2):
thutchJoshM

thutch
Posts: 52
Joined: 16 Sep 2011
Has thanked: 16 times
Been thanked: 10 times

Re: disconnect at night and Limit Order sync

Postby thutch » 18 Jul 2012

TJ wrote:
thutch wrote:Finally, if I follow what I write above, I will have something like 16 charts that could each hold a position. It seems to be a bit of a pain to manually reconcile open positions at the start of each day (many of these may hold overnight). So do/would you trust MC to run all week? If so, would the position syncing with IB work OK if I only do a manual IB TWS restart once/day?

thank you for your insights

re: So do/would you trust MC to run all week?

Even big investment/trading houses would not leave an autotrade unattended. They have all the professional programmers and professional computer scientists and professional traders who can design a fail-safe system, and they would still not leave it alone !!! Should you?


Thought I would go back to this and mention that I have now been running MC all week long (Sunday eve -> Friday eve) for about 2 months. I have only had one problem, and that was due to a server crash. I use IB with TWSstart.
These users thanked the author thutch for the post (total 2):
TJJoshM


Return to “MultiCharts”