NexusFi: Find Your Edge


Home Menu

 





Keeping MC synced with the broker (MarketPosition_at_Broker, etc)


Discussion in MultiCharts

Updated
    1. trending_up 3,740 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 9 posts
    2. attach_file 4 attachments




 
Search this Thread

Keeping MC synced with the broker (MarketPosition_at_Broker, etc)

  #1 (permalink)
jesse514
Montreal, QC
 
Posts: 11 since Apr 2014
Thanks Given: 5
Thanks Received: 6

I've found that if I'm running a strategy and holding a position, but then I restart MC or the strategy, MC gets out of sync with the broker. For example if I'm +1 (long) on an "always in" strategy, and the strategy should short, it sells 1 contract and makes me flat instead of selling 2 to reverse positions to -1, since it's not taking MarketPosition_at_Broker into consideration.

So far my research tells me that doing something like this would likely fix it:
 
Code
variables:
vMktPos( MarketPosition_at_Broker ), 
vMktPosStrat( MarketPosition_at_Broker_for_The_Strategy );

If vMktPos = vMktPosStat then <buy or sell like I usually would do> ;

if vMktPos=1 and vMktPosStrat=0 then <on sell signal, sell short 2 contracts instead of 1>;

and so on...
But are there easier ways to achieve this that require less customized code for each strategy? Off the top of my head:

1) Being able to set MarketPosition_at_Broker_for_The_Strategy to equal MarketPosition_at_Broker would fix this

2) Maybe there is a command to buy/sell short which changes the position based on what MarketPosition_at_Broker is. So for example I could then "Sellshort so that position = -1" and it wouldn't matter if I'm flat or at +1 or at +2, etc, it would just sell the necessary number of contracts so that the position becomes -1.

Any ideas/suggestions? Thanks!

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

jesse514,

what settings are you using in the last part of the Strategy Properties "Auto Trading" tab?

You could also try the build in !From Strategy To Broker MP Synchronizer! and !From Broker To Strategy MP Synchronizer! signals.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
jesse514
Montreal, QC
 
Posts: 11 since Apr 2014
Thanks Given: 5
Thanks Received: 6


Great! I added the "!From Broker To Strategy MP Synchronizer!" signal and it seems to be exactly what I needed. Thanks again!

As for my signal settings on the Auto-Trading tab, I've attached a screenshot. Would you have me change anything?

Attached Thumbnails
Click image for larger version

Name:	Auto-trading_tab.PNG
Views:	302
Size:	21.4 KB
ID:	144420  
Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

jesse514,

you are welcome. Your automation settings look okay.

If you want you can try out "Async" mode and see how this effects the issue you are currently having.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
  #5 (permalink)
jesse514
Montreal, QC
 
Posts: 11 since Apr 2014
Thanks Given: 5
Thanks Received: 6

ABCTG,

"!From Broker To Strategy MP Synchronizer!" with the default settings of TimeOutMS=250 and LatencyMS=500 has turned out to be behave strangely. Every single trade is doubled in MC's performance report. See attached screenshots of MC history vs the broker's history.

This is simply a MACD always-in reversal system I'm testing. Without the synchronizer it works fine. The strategy began when the broker was +1, so I expected one initial internal sync trade, after which things would function normally since the broker and the strategy were in sync. Would you have any idea of why it is instead behaving like this?

thanks again.

Attached Thumbnails
Click image for larger version

Name:	syncing.png
Views:	204
Size:	44.4 KB
ID:	144471   Click image for larger version

Name:	syncing2.png
Views:	207
Size:	7.0 KB
ID:	144472  
Reply With Quote
  #6 (permalink)
jesse514
Montreal, QC
 
Posts: 11 since Apr 2014
Thanks Given: 5
Thanks Received: 6

According to this thread, it is likely a latency issue: https://www.multicharts.com/discussion/viewtopic.php?f=5&t=9905

However this thread also mentions ChangeMarketPosition which is perhaps what I should be using. Something like this:

 
Code
if MarketPosition_at_Broker <> MarketPosition_at_Broker_for_The_Strategy then
ChangeMarketPosition( MarketPosition_at_Broker, etc ..........

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

jesse514,

you might want to limit the ChangeMarketPosition execution to once when you start (restart) the signal. Also using this check means you should avoid trading the same market from more than one chart.

Regards,
ABCTG


jesse514 View Post
According to this thread, it is likely a latency issue: https://www.multicharts.com/discussion/viewtopic.php?f=5&t=9905

However this thread also mentions ChangeMarketPosition which is perhaps what I should be using. Something like this:

 
Code
if MarketPosition_at_Broker <> MarketPosition_at_Broker_for_The_Strategy then
ChangeMarketPosition( MarketPosition_at_Broker, etc ..........


Follow me on Twitter Reply With Quote
Thanked by:
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

jesse514,

did you try using the assign the initial market position at broker dialog?



This gives you the ability to align the chart position with the broker position.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #9 (permalink)
jesse514
Montreal, QC
 
Posts: 11 since Apr 2014
Thanks Given: 5
Thanks Received: 6

Ah, the "assign the initial market position at broker dialog" definitely seems like a simple solution! I'll only bother with the more complicated coded solutions if I find scenarios where the strategy and broker get out of sync on their own.

I suppose if a bracket order gets triggered during a disconnection from the broker things would get out of sync. It would be nice if there was a simple setting to always assign market position based on broker, not only when starting strategy, and not through a dialog. But I guess that requires some code.

Thanks again ABCTG.

Reply With Quote
  #10 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


jesse514,

we could gather a couple of scenarios of what could happen and how to deal with it. This should be of general interest to many.

Your situation with the bracket order and disconnection would be something to try out in a simulated environment. When you get a disconnection that turns your strategy automation off, there is not much you can do from the strategy code anymore anyway.

Regards,
ABCTG

Follow me on Twitter Reply With Quote




Last Updated on April 22, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts