Hello!
Is there a way to control an "order named" position?
With "marketposition" I can only see the summery pf all positions of the strategy on the same instrument.
But I have different positions:
Buy [("Entry1")] [Number of Shares/Contracts] [Order Action];
Buy [("Entry2")] [Number of Shares/Contracts] [Order Action];
OK, I can close both orders with
Sell [("Order Name")] [from entry ("Entry1")] [ Number of Shares [Total]]
[Execution Method];
Sell [("Order Name")] [from entry ("Entry2")] [ Number of Shares [Total]]
[Execution Method];
But how can I control these orders?
For example:
If marketposition(Order1) = 1 then....
Code Question: control named order
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Code Question: control named order
Don't have a clear solution for this, but what you could try..But how can I control these orders?
For example:
If marketposition(Order1) = 1 then....
1) Use variables that hold the position size for each order. Incredibly simplified, I mean something like this:
Code: Select all
if .... then begin
buy("EL mkt1") 2 contracts next bar at market;
PosSizeOrderOne = 2;
end;
if .... then begin
buy("EL mkt2") 1 contracts next bar at market;
PosSizeOrderTwo = 1;
end;
if PosSizeOrderOne > 0 then begin
Sell("XL mkt1") 1 contracts next bar at market;
PosSizeOrderOne = PosSizeOrderOne - 1;
end;
2) Use the new PosTradeSize(PosAgo, TradeNumber) for that, perhaps with the PosTradeEntryName/PosTradeExitName or PosTradeEntryCategory/PosTradeExitCategory for the filtering on entry/exit name or type of entry/exit order. Once again simplified, this could look like:
Code: Select all
if .... then begin
buy("EL mkt1") 2 contracts next bar at market;
end;
if .... then begin
buy("EL mkt2") 1 contracts next bar at market;
end;
if PosTradeSize(0, 0) > 0 then
Print("The first order of the open position has a size of ", PosTradeSize(0, 0));
if PosTradeSize(0, 1) > 0 then
Print("The second order is ", PosTradeSize(0, 1), " contracts big.");
Also see the documentation here and this explanation.
Regards,
Josh