MC6 beta 1: MarketPosition_At_Broker always 0

Questions about MultiCharts and user contributed studies.
cyberdad
Posts: 36
Joined: 10 Aug 2009

MC6 beta 1: MarketPosition_At_Broker always 0

Postby cyberdad » 05 Jan 2010

MarketPosition_At_Broker does not work for me.
I am using an IB paper trading account to test this on EURUSD.
The pseudo-strategy I am using does generate trades correctly but the MarketPosition_At_Broker is always 0.

I am using the print command to watch MarketPosition and MarketPosition_At_Broker.
This is the kind of data I get in the output window:

Code: Select all

1/5/2010 9:36:15 AM : MarketPosition_at_Broker = 0
1/5/2010 9:36:15 AM : MarketPosition = -1
1/5/2010 9:38:00 AM : MarketPosition_at_Broker = 0
1/5/2010 9:38:00 AM : MarketPosition = -1
1/5/2010 9:40:05 AM : MarketPosition_at_Broker = 0
1/5/2010 9:40:05 AM : MarketPosition = -1
1/5/2010 9:42:01 AM : MarketPosition_at_Broker = 0
1/5/2010 9:42:01 AM : MarketPosition = -1
1/5/2010 9:44:03 AM : MarketPosition_at_Broker = 0
1/5/2010 9:44:03 AM : MarketPosition = 0


As you can see a trade does take place correctly and MC correctly calculates the position internally but the position at the broker is never updated.
This is the pseudo-strategy I am using:

Code: Select all

SetStopPosition;

value1 = AverageFC( C, 9 ) ;

if C > var0 and C[1] < value1 then Buy next bar market;

if C < var0 and C[1] > value1 then sellshort next bar market;

if marketposition = -1 and C > value1 then buytocover next bar market;
   
if marketposition = 1 and C < value1 then sell next bar market;

setstoploss(50);
setprofittarget(50);

print(datetimetostring(computerdatetime) + " : MarketPosition_at_Broker = " + NumToStr(MarketPosition_at_Broker,0));
print(datetimetostring(computerdatetime) + " : MarketPosition = " + NumToStr(MarketPosition,0));


The reason I need to have a correct indication of the actual position at the Broker is simple yet crucial. No matter how good MC is, there are always connection problems possibly resulting to errors. One simple way to manage these errors would be to compare the internally calculated position to the actual one and take action accordingly.

With MarketPosition_At_Broker always equal to 0 there is no way to write some failsafes that imo are necessary.
Is this is a bug of some sort or is it because of the paper-trading account I am using to test it?.
Can anyone please confirm the correct function of MarketPosition_At_Broker with a real account?

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 05 Jan 2010

I tried following on MC 6 beta2 on IB Simulated Trading and it works for me:

I think it's a good practice not to call functions directly in to print statements.


Code: Select all


Value1=MarketPosition_at_Broker;
Value2=MarketPosition;

print(datetimetostring(computerdatetime) + " : MarketPosition_at_Broker = " + NumToStr(Value1,0));
print(datetimetostring(computerdatetime) + " : MarketPosition = " + NumToStr(Value2,0));


05/01/2010 11:30:54 : MarketPosition_at_Broker = 0
05/01/2010 11:30:54 : MarketPosition = 0
05/01/2010 11:31:03 : MarketPosition_at_Broker = 0
05/01/2010 11:31:03 : MarketPosition = 0
05/01/2010 11:32:03 : MarketPosition_at_Broker = 1
05/01/2010 11:32:03 : MarketPosition = 1
05/01/2010 11:33:02 : MarketPosition_at_Broker = 1
05/01/2010 11:33:02 : MarketPosition = 1
05/01/2010 11:34:03 : MarketPosition_at_Broker = 1
05/01/2010 11:34:03 : MarketPosition = 1

cyberdad
Posts: 36
Joined: 10 Aug 2009

Postby cyberdad » 05 Jan 2010

Interesting. I am gonna install MC 6 beta 2 right away and try to assign the values to variables prior to using them in the print command. Will post the results shortly.

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 05 Jan 2010

It has been fixed in Beta 2. It was true for FIA accounts.

cyberdad
Posts: 36
Joined: 10 Aug 2009

Postby cyberdad » 05 Jan 2010

No, it wasn't the version or the the fact that I was using MarketPosition_At_broker directly in the Print command.

As it seems the problem is the fact that my paper-trading account is an advisor paper-trading account. I tested again using a real personal account and for the first time I was able to get the actual position. BUT, I did not get a value of 1/-1/0. Instead I got the amount bought/sold eg 50,000.

In the documentation about Marketposition_At_Broker I read:

Code: Select all

Marketposition_At_Broker

Returns a numerical value, indicating the type of the specified position at the broker for the symbol.
A value of 1 indicates a long position, -1 indicates a short position, and 0 is returned only if the current position is specified and indicates that the current position is flat.


This is not the case. I didn't get an indication of the type of the position. Instead I got the amount traded. Could tssupport clarify that please? What exactly is Marketposition_At_Broker returning?

So, Marketposition_At_Broker works in a real personal account but it still does not work in an advisor account. Even with the simplest setup of using "Single Account Allocation" in the IB plugin settings. This must be a bug because all other stuff works ok except the correct reporting of the open position.

Thank you SUPER, even if it wasn't what you suggested, you pointed me to the direction needed.
To TSSupport, please check this incorrect behavior and let us know if it is indeed a bug and please clarify the usage of Marketposition_At_Broker function. Thank you.

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 05 Jan 2010

You are correct about the bug, I tested it out on IB simulated account with two contracts and here's what I get with Marketposition_At_Broker or i_Marketposition_At_Broker:

05/01/2010 16:53:03 : MarketPosition_at_Broker = 0
05/01/2010 16:53:03 : MarketPosition = 0
05/01/2010 16:54:03 : MarketPosition_at_Broker = -2
05/01/2010 16:54:03 : MarketPosition = -1

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 05 Jan 2010

"MarketPosition_at_Broker_for_The_Strategy" or
"MarketPosition_at_Broker_for_The_Strategy" yields incorrect output:

05/01/2010 17:01:50 : MarketPosition_at_Broker = 0
05/01/2010 17:01:50 : MarketPosition = 0
05/01/2010 17:02:03 : MarketPosition_at_Broker = 0
05/01/2010 17:02:03 : MarketPosition = 0
05/01/2010 17:03:03 : MarketPosition_at_Broker = -2
05/01/2010 17:03:03 : MarketPosition = -1

cyberdad
Posts: 36
Joined: 10 Aug 2009

Postby cyberdad » 05 Jan 2010

SUPER,

I just did. Using this code

Code: Select all

value1 = MarketPosition_at_Broker;
value2 = MarketPosition;
value3 = i_MarketPosition_at_Broker;

print(datetimetostring(computerdatetime) + " : MarketPosition_at_Broker = " + NumToStr(value1,0));
print(datetimetostring(computerdatetime) + " : MarketPosition = " + NumToStr(value2,0));
print(datetimetostring(computerdatetime) + " : i_MarketPosition_at_Broker = " + NumToStr(value3,0));


I get this when a new long position opens:

Code: Select all

1/5/2010 7:00:00 PM : MarketPosition_at_Broker = 0
1/5/2010 7:00:00 PM : MarketPosition = 1
1/5/2010 7:00:00 PM : i_MarketPosition_at_Broker = 0


So, to summarize.
Using a paper-trading FA account, MarketPosition_at_Broker and i_MarketPosition_at_Broker do not work. Even in MC6 beta 2.
Using a real personal account, MarketPosition_at_Broker works but not as expected. It indicates the amount traded (ie 50,000) and not the type of position (1,-1,0).

This is a lot of inconsistency. And it is too hard to test everything right without proper paper-trading anyway. I hope we get an official answer on this.
I can probably do my job without some features, but it is too hard to do it with inconsistent features.

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 05 Jan 2010

The explanation does not match the output results, however we may be able to use the output by checking for > or < 0 to indicate long or short position....just a work around untill the bug is fixed.

It would be good idea to rename this function as "Contracts/Shares_at_Broker" as it gives the contract/share position at broker.

cyberdad
Posts: 36
Joined: 10 Aug 2009

Postby cyberdad » 05 Jan 2010

Yes, as I said above, I can live with it if I know how it works. A workaround is usually possible in most cases. But what if it changes back to what it was supposed to be in the next beta? I mean, one needs to be careful.

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 05 Jan 2010

I get this when a new long position opens:

Code:
1/5/2010 7:00:00 PM : MarketPosition_at_Broker = 0
1/5/2010 7:00:00 PM : MarketPosition = 1
1/5/2010 7:00:00 PM : i_MarketPosition_at_Broker = 0




cyberdad,

you should test automation in SA mode or use If LastBarOnChart then.......your code.... so that your marketposition matches with broker. In your case the marketposiotion in first few lines of your test is your historical position on your chart.

cyberdad
Posts: 36
Joined: 10 Aug 2009

Postby cyberdad » 05 Jan 2010

I do test the automation in SA mode and I also do use If LastBarOnChart then ... (even if i did not write it in the example above). So, my results should be ok.

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 05 Jan 2010

I do test the automation in SA mode and I also do use If LastBarOnChart then ... (even if i did not write it in the example above). So, my results should be ok.



Don't you think it would be more productive if you posted actual test code that you are using for testing so that others can compare apples with apples. If I had know that you have tested under SA mode and have used lastbaronchart then I would not have wasted my time in above post.

cyberdad
Posts: 36
Joined: 10 Aug 2009

Postby cyberdad » 05 Jan 2010

SUPER,
Sorry I wasted your time.

TSSupport,
Is it a bug in version MC 6.0 the fact that MarketPosition_At_Broker does not update correctly?
Is the description of MarketPosition_At_Broker in the documentation erroneous or not?


Return to “MultiCharts”