PosTradeProfit possible bug
Posted: Apr 29 2014
When using this command with a trade that enters once and exits twice from the entry order, the first exit calculates the profit as though the entire position was filled. The second exit calculates correctly using the reduced size from the entry. I'm using the code below to return the percent gain or loss on each trade.
This code should return the gain or loss percent from each of the exits from an entry. For two exits, the first exit results in a value that equals that of the entire position exiting. The second exit calculates correctly. I then substituted this code and it correctly calculated both exit gain or loss percentages:
This is making the same loop through the last closed trade sequence from one entry but instead of using the PosTradeProfit command, I used the PosTradeExitPrice, PosTradeEntryPrice and PosTradeSize to calculate the gain or loss. This worked correctly.
Code: Select all
for Value1 = 0 to (NumOfTrades - 1) begin
FileAppend("c:\testdata\system.txt",+","+NumToStr((PosTradeProfit(1,value1)/(StartEquity + NetProfit))*100,2)
end;
Code: Select all
FileAppend("c:\testdata\system.txt",+","+NumToStr((((PosTradeExitPrice(1,value1) - PosTradeEntryPrice(1,value1))*PosTradeSize(1,value1))/(StartEquity + NetProfit))*100,2)
end;