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;
Can't Sync with the Broker
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
What happen if you change your code to: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.
IF MARKETPOSITION_AT_BROKER = -1 THEN BEGIN
BUY NEXT BAR AT MARKET;
END;
I have changed BuyToCover to Buy
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
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
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.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.
It would be a good idea to have additional feature that can handle your logic.
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.