Can't Sync with the Broker

Questions about MultiCharts and user contributed studies.
ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

Can't Sync with the Broker

Postby ppan » 09 Dec 2009

Before auto trade is turned on, the position in the broker is -1.
After auto trade is turned on, the BUYTOCOVER cannot cover the -1 position in the broker.

The following is the signal code:
IF MARKETPOSITION_AT_BROKER = -1 THEN BEGIN
BUYTOCOVER NEXT BAR AT MARKET;
END;

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

Postby SUPER » 10 Dec 2009

can you put a print statement in your code to see what MarketPosition_at_Broker yields.

Print(MarketPosition_at_broker);

ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

Postby ppan » 10 Dec 2009

The MarketPosition_at_broker shows -1.

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

Postby TJ » 10 Dec 2009

did you get an error message?

ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

Postby ppan » 10 Dec 2009

No error.
The system start with -1 position in the broker. The marketposition is 0 but the marketposition_at_broker is -1. The buytocover is based on the marketposition. So MC don't cover the -1 position at broker because the marketposition is 0.

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

Postby TJ » 10 Dec 2009

are you using sych or asych mode?

I think it only works with one but not the other.
I am not sure which one tho.

ppan
Posts: 106
Joined: 31 Jan 2007
Has thanked: 2 times

Postby ppan » 11 Dec 2009

I use sych mode.

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

Postby SUPER » 11 Dec 2009

No error.
The system start with -1 position in the broker. The marketposition is 0 but the marketposition_at_broker is -1. The buytocover is based on the marketposition. So MC don't cover the -1 position at broker because the marketposition is 0.


What happen if you change your code to:

IF MARKETPOSITION_AT_BROKER = -1 THEN BEGIN
BUY NEXT BAR AT MARKET;
END;

I have changed BuyToCover to Buy

Kingjelly
Posts: 25
Joined: 23 Jan 2008

Postby Kingjelly » 01 Feb 2010

Anyone figure this out, I really need it to work,

I have

Print(MarketPosition_at_broker);
If MarketPosition_at_Broker = 1 Then begin
Sell Next Bar at Market;
End;

I can see it print that the value is 1 but yet it won't sell the position???

Kingjelly
Posts: 25
Joined: 23 Jan 2008

Postby Kingjelly » 01 Feb 2010

Print("before");
Print(MarketPosition_at_broker);

If MarketPosition_at_Broker = 1 Then
begin
Print("inside1");
Print(MarketPosition_at_broker);
Sell Next Bar at Market;
Print("inside2");
Print(MarketPosition_at_broker);
End;

Print("after");
Print(MarketPosition_at_broker);



before
1.00
inside1
1.00
inside2
1.00
after
1.00


yet no sell order

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

Postby SUPER » 02 Feb 2010

Kingjelly,

I tried following and it worked in SA Mode:

=================

Value1=MarketPosition_at_Broker ;

if C > C[1] then buy next bar at Market;

if BarsSinceEntry >1 and Value1 > 0 then sell next bar at market;

=================

Regards
Super

Kingjelly
Posts: 25
Joined: 23 Jan 2008

Postby Kingjelly » 02 Feb 2010

Thanks, but I don't want it to have a buy order in before the sell, I want it to recognize that a position is there and just close it when certain criteria are met. I have a work around for now, if I tell it to sellshort or buy in the opposite direction of the actual position it will close it and then return 0. I would like it to work correctly though. I would like to use it to automate the closings of quite a few OPG positions that are entered as a basket.

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

Postby janus » 03 Feb 2010

Yes I find it strange that if one uses Sync mode it doesn't really sync with the broker position at start up. Yet in Async mode there appears to be an option to do so. I'm confused too, which is why I always start with a flat position before turning on auto trading in Sync mode.

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

Postby SUPER » 03 Feb 2010

Thanks, but I don't want it to have a buy order in before the sell, I want it to recognize that a position is there and just close it when certain criteria are met. I have a work around for now, if I tell it to sellshort or buy in the opposite direction of the actual position it will close it and then return 0. I would like it to work correctly though. I would like to use it to automate the closings of quite a few OPG positions that are entered as a basket.


From my understanding, every trade generated by means of automation will have a tag assigned to it and only these orders can be controlled through the automation process, now if you have placed manual order then it will not have any reference or tag assigned to it so the automation process will not be able to handle it.

It would be a good idea to have additional feature that can handle your logic.

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

Postby SUPER » 03 Feb 2010

Yes I find it strange that if one uses Sync mode it doesn't really sync with the broker position at start up. Yet in Async mode there appears to be an option to do so. I'm confused too, which is why I always start with a flat position before turning on auto trading in Sync mode.



I too think that same option should be available under SYNC mode.


Return to “MultiCharts”