Page 1 of 1

PosTradeExitPrice doesn't work for open positions?

Posted: Mar 19 2013
by cnbiz850
The output of the demo code below is like:

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
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

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;

Re: PosTradeExitPrice doesn't work for open positions?

Posted: Mar 19 2013
by Henry MultiŠ”harts
Hello cnbiz850,

PosTradeExitPrice works as expected in MultiCharts 8.5 Release build 6851. The behavior is the same as in MC 7.4. It returns the execution price for closed positions and partial exits.
Here is a simplified code we have tested:

Code: Select all

once cleardebug;
if currentbar=1 then buy 3 contract next bar at market;
if currentbar=3 then sell 1 contract total next bar at market;
if currentbar=5 then sell 1 contract total next bar at market;
if currentbar=7 then sell 1 contract total next bar at market;

if currentbar<10 then
print( currentbar:2:0,
PosTradeCount(0):5:0,
PosTradeExitPrice(0,0):10:5, PosTradeExitPrice(0,1):10:5,
PosTradeExitPrice(1,2):10:5);