PosTradeExitPrice doesn't work for open positions?
Posted: Mar 19 2013
The output of the demo code below is like:
When the position is open, PosTradeExitPrice gives 0, even though it gives the correct values when the position is closed out.
Anything wrong? My MC version is 7.4.
Code: Select all
Trading Day: 1130318.00 Trade No.1 Exit price: 0.00
Trading Day: 1130318.00 Trade No.2 Exit price: 0.00
End of day of 1130318.00 Total number of trades: 4 ExitPrice of Trade No.0: 6224.00
End of day of 1130318.00 Total number of trades: 4 ExitPrice of Trade No.1: 6258.00
End of day of 1130318.00 Total number of trades: 4 ExitPrice of Trade No.2: 6322.00
End of day of 1130318.00 Total number of trades: 4 ExitPrice of Trade No.3: 6278.00
Anything wrong? My MC version is 7.4.
Code: Select all
vars: MyCondition(false), Index(0);
if (date <> date[1]) then begin
// on the first bar of the day
sellshort ("S") 20 contracts next bar at close+MinMove stop;
index=0;
end else begin
if MarketPosition <> 0 then begin
// set condition for the multiple exits
MyCondition = time=911 or time=916 or time=1002;
if (MyCondition) then begin
// print out the price of the last exit
if (index>0) then
print("Trading Day: ", date, " Trade No.",
NumToStr(PosTradeCount(0)-1, 0), " Exit price: ",
PosTradeExitPrice(0,PosTradeCount(0)-1));
// execute the three exits
if (index=0) then
buytocover ("BC") 5 contracts next bar at close-MinMove stop;
if (index=1) then
buytocover ("BC1") 5 contracts next bar at close-MinMove stop;
if (index=2) then
buytocover ("BC2") 5 contracts next bar at close-MinMove stop;
index = index+1;
end;
end;
// close out all open positions
if (time>=1456 and time<1500) then begin
if (marketposition<0) then
buytocover ("E") currentcontracts contracts next bar at close-MinMove stop;
end;
// print out the exit prices for the day
if (time=1500 and Index<>0) then begin
for value1=0 to PosTradeCount(1)-1 begin
print("End of day of ", date," Total number of trades: ",
NumToStr(PosTradeCount(1),0), " ExitPrice of Trade No.",
NumToStr(value1,0), ": ", PosTradeExitPrice(1,value1));
end;
end;
end;