Trading one instrument, multiple charts  [SOLVED]

Questions about MultiCharts and user contributed studies.
Xyzzy
Posts: 162
Joined: Mar 19 2011
Has thanked: 43 times
Been thanked: 79 times

Jul 23 2013

I have two different strategies (different logic for entries and exits) that I'd like to autotrade simultaneously in SA mode. It would be more convenient for me to trade each one from a different chart so that one strategy's logic doesn't get "mixed up" with the other. I've reviewed this wiki page, which is quite helpful:

http://www.multicharts.com/trading-soft ... Instrument

Each strategy can go either long or short on a given day, but neither one will trade in both directions on the same day. E.g., Strategy A might trade from a long position (with exits through profit targets, stop losses or time exits), while Strategy B might trade from a short position. However, Strategy A won't place a long order and then do a stop-and-reverse into a short position, which is the situation discussed on the wiki page.

In this situation, is there a risk of the strategies getting out of sync? E.g., let's assume that the following occurs:

1. Strategy A opens a long position on the first chart and sets profit target/stop loss exits. Broker position is +1.

2. Strategy B opens a short position on the second chart, also with a with a profit target/stop loss. Broker position is flat.

3. The price rises, and Strategy A exits on the chart through the long profit target. Will the broker position now be -1?

4. Strategy B doesn't hit either price exit, so it eventually exits the short position on the chart through a time exit. Will the broker position now be flat again?

This is what I would like to happen. However, I'm concerned about whether the order execution engine might get out of sync, particularly given the multiple profit targets and stop losses.

Thanks in advance for any clarification.

User avatar
TJ
Posts: 7763
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2232 times

Jul 23 2013

I have two different strategies (different logic for entries and exits) that I'd like to autotrade simultaneously in SA mode. It would be more convenient for me to trade each one from a different chart so that one strategy's logic doesn't get "mixed up" with the other. I've reviewed this wiki page, which is quite helpful:
http://www.multicharts.com/trading-soft ... Instrument
Each strategy can go either long or short on a given day, but neither one will trade in both directions on the same day. E.g., Strategy A might trade from a long position (with exits through profit targets, stop losses or time exits), while Strategy B might trade from a short position. However, Strategy A won't place a long order and then do a stop-and-reverse into a short position, which is the situation discussed on the wiki page.
In this situation, is there a risk of the strategies getting out of sync? E.g., let's assume that the following occurs:
1. Strategy A opens a long position on the first chart and sets profit target/stop loss exits. Broker position is +1.
2. Strategy B opens a short position on the second chart, also with a with a profit target/stop loss. Broker position is flat.
3. The price rises, and Strategy A exits on the chart through the long profit target. Will the broker position now be -1?
4. Strategy B doesn't hit either price exit, so it eventually exits the short position on the chart through a time exit. Will the broker position now be flat again?
This is what I would like to happen. However, I'm concerned about whether the order execution engine might get out of sync, particularly given the multiple profit targets and stop losses.
Thanks in advance for any clarification.
What happens depends on how you code your strategy, and depends on whether you are using SA or AA. What you have posted above is not sufficient information to determine a conclusion.

If you want your autotrade to be smart, you have to build in self-checking intelligence. ie. get MultiCharts to check the broker position before starting new orders. It's not that difficult, it just takes time to code and to do the testing.

ps. You cannot hold a long and a short at the same time, the broker will always net your orders.

User avatar
t-rader
Posts: 139
Joined: Feb 02 2011
Location: Australia
Has thanked: 11 times
Been thanked: 27 times

Jul 24 2013

Xyzzy, I'm like you and would rather not combine my signals together as its much simpler keeping them separate. I can also backtest, tweak, improve and have the performance report for each separate.

At the moment I've simply opened another account with my broker and trade these in separate accounts.

I'd really like to know though how the scenario you posted would play out. I think TJ is correct that your position will be netted at your broker but what happens at the MC end if you are set to SA mode?
1. Strategy A opens a long position on the first chart and sets profit target/stop loss exits. Broker position is +1.

2. Strategy B opens a short position on the second chart, also with a with a profit target/stop loss. Broker position is flat.
After 1 and 2, at this point does MC think Strategy A is still in a long position to execute your 3rd point as follows:
3. The price rises, and Strategy A exits on the chart through the long profit target. Will the broker position now be -1?
My assumption is that Strategy A would do point 3 because even though the position was updated at the broker SA mode states 'Entries/Exits are based on the 'execution confirmation' by the broker (Sync)' so because Strategy A didn't execute the change in the position at the broker it's still under the belief of its original position. If that makes sense or am I explaining things terribly :S

User avatar
furytrader
Posts: 354
Joined: Jul 30 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Jul 24 2013

One way to avoid confusion is to use some kind of tracking variable to keep track of whether you're long or short. You would have to build in some kind of logic that determines whether you should have been filled, and if so, set your tracking variable accordingly.

For example, let's say that you are trading a breakout strategy, and consequently, you work an order to buy 100 shares of IBM at a price of 200. And let's say that if you're filled, you will work a stop at 198.

After you place the order, you have your program see if the high of subsequent bars is at or above 200. If it is, your tracking variable is set to +1 because you will have been filled on your stop at 200. You then place your protective stop. If the subsequent bar has a low equal to or less than 198, you were obviously stopped out, and so your tracking variable is set back to 0, and on and on.

The point here is that instead of relying on MultiCharts to tell you whether you're long or not, you just check the subsequent price action and determine that yourself.

The only area where this could be problematic is when you're using limit orders, and you can't be sure that you're filled or not at a particular price level.

User avatar
t-rader
Posts: 139
Joined: Feb 02 2011
Location: Australia
Has thanked: 11 times
Been thanked: 27 times

Jul 24 2013

Furytrader I don't believe thats the safest way to do it as you're basically 'assuming' you were filled. There's a few other things you're not catering for with your example as well like slippage and if you use the option to 'cancel market order after x seconds'.

Regardless though the OP is asking if its possible to run 2 strategies from 2 different charts on 1 account and not have them get mixed up and out of sync.

Xyzzy
Posts: 162
Joined: Mar 19 2011
Has thanked: 43 times
Been thanked: 79 times

Jul 24 2013

Thanks all. It's certainly possible to rewrite the strategies so that they both trade from the same chart. However, I'm a believer in the "keep it simple, stupid" method of coding -- the longer and more complicated your code becomes, the greater the likelihood that Murphy's Law will strike, regardless of how much you test it in advance.

Concerning t-rader's and furytrader's points, the problem is that I'm entering through limit orders, so I won't know in advance which orders get filled, or when they get filled. (Same for exits.) I could manually keep track of which orders are currently open by using keywords like PosTradeEntryName and PosTradeEntryPrice, but that gets back to my Murphy's Law point.

My original question is basically asking about a variation on what's discussed in the wiki article. If someone from MultiCharts could weigh in, I'd really appreciate it.

User avatar
Henry MultiСharts
Posts: 9165
Joined: Aug 25 2011
Has thanked: 1264 times
Been thanked: 2958 times

Jul 26 2013

I have two different strategies (different logic for entries and exits) that I'd like to autotrade simultaneously in SA mode. It would be more convenient for me to trade each one from a different chart so that one strategy's logic doesn't get "mixed up" with the other. I've reviewed this wiki page, which is quite helpful:

http://www.multicharts.com/trading-soft ... Instrument

Each strategy can go either long or short on a given day, but neither one will trade in both directions on the same day. E.g., Strategy A might trade from a long position (with exits through profit targets, stop losses or time exits), while Strategy B might trade from a short position. However, Strategy A won't place a long order and then do a stop-and-reverse into a short position, which is the situation discussed on the wiki page.

In this situation, is there a risk of the strategies getting out of sync? E.g., let's assume that the following occurs:

1. Strategy A opens a long position on the first chart and sets profit target/stop loss exits. Broker position is +1.

2. Strategy B opens a short position on the second chart, also with a with a profit target/stop loss. Broker position is flat.

3. The price rises, and Strategy A exits on the chart through the long profit target. Will the broker position now be -1?

4. Strategy B doesn't hit either price exit, so it eventually exits the short position on the chart through a time exit. Will the broker position now be flat again?

This is what I would like to happen. However, I'm concerned about whether the order execution engine might get out of sync, particularly given the multiple profit targets and stop losses.

Thanks in advance for any clarification.
Hello Xyzzy,

Two separate strategies will work exactly as you have described above. The order execution engine should not get out of sync. Each chart is holding its own market position and is capable of managing multiple exits, even in the situation you have described when long and short positions were filled and net broker position is flat.

Unexpected out of sync is possible if an order is placed by a strategy during auto trading but it doesn't receive its final status (e.g. Cancelled, Filled). In such case the strategy considers the order to be not executed. In fact the order may be executed at broker end, what leads to position mismatch.

That is also important to differentiate the MarketPosition reserved words if they are used in the code:
MarketPosition_at_Broker – net number of contracts and the type of position at the broker for the symbol.
MarketPosition_at_Broker_for_the_Strategy - number of contracts and the type of position at the broker for the strategy.
MarketPosition - current strategy position for a given chart.

Xyzzy
Posts: 162
Joined: Mar 19 2011
Has thanked: 43 times
Been thanked: 79 times

Jul 26 2013

Thanks Henry. This is quite helpful.