**Solved!** (Sorry, quite happy/satisfied now)

the price of every Entry is calculated with PosTradeEntryPrice(positions_ago, trade_number). All keywords beginning with “PosTrade…” return the necessary information regarding every trade of your strategy.

*According to my understanding*: PosTradeEntryPrice uses the position number, followed by the trade number

**relative** for the position, starting at

**zero**. So, if your first position scales in three times, and your second position 2 times, you can call this with:

Code: Select all

`PosTradeEntryPrice(2, 0); // first position, first entry`

PosTradeEntryPrice(2, 1); // first position, second entry

PosTradeEntryPrice(2, 2);

PosTradeEntryPrice(1, 0); // second position (i.e. 1 position ago), first entry

PosTradeEntryPrice(1, 1);

So, an error I made was to use the 'TotalTrades number' for the 'trade_number' input in PosTradeEntryPrice (perhaps this can be clearer communicated in the future, since we now have 3 three types of numbers, each different to another: position number != total trades number != trade number).

See for example the code below:

Code: Select all

`if LastBarOnChart_s = true then begin`

// Get number of positions

for tradeNumber = TotalTrades DownTo 1 begin

if EntryPrice(tradeNumber) > 0 then

numberOfPositions = numberOfPositions + 1;

end;

Print("Total positions: ", NumToStr(numberOfPositions, 0), ", totalTrades: ", totaltrades, NewLine);

tradeNumber = 1;

for positionNumber = numberOfPositions DownTo 1 begin

// Get the number of trades into the position

tradesIntoPosition = PosTradeCount(positionNumber);

// Print position data

Print("Position #", NumToStr(numberOfPositions - (positionNumber - 1), 0), Spaces(2),

"Trade #", NumToStr(tradeNumber, 0), Spaces(2),

"AvgEntryPrice: ", NumToStr(EntryPrice(positionNumber), 3), Spaces(2),

"ExitPrice: ", NumToStr(ExitPrice(positionNumber), 3),

Spaces(5), "Trades into position: ", NumToStr(tradesIntoPosition, 0));

// Print seperate entries data

for value5 = 0 to (tradesIntoPosition - 1) begin

Print(Spaces(3), "Entry", NumToStr(value5+1, 0), " @ ",

NumToStr(PosTradeEntryPrice(positionNumber, value5), 3), Spaces(2),

"TradeSize: ", NumToStr(PosTradeSize(positionNumber, value5), 0), Spaces(2),

"ExitPrice: ", NumToStr(PosTradeExitPrice(positionNumber, value5), 3)

);

end;

tradeNumber = tradeNumber + tradesIntoPosition;

end;

end;

Which gives here the following correct output, STD Exception free:

Code: Select all

`Total positions: 63, totalTrades: 280.00`

Position #1 Trade #1 AvgEntryPrice: 80.865 ExitPrice: 80.843 Trades into position: 8

Entry1 @ 80.865 TradeSize: 1000 ExitPrice: 80.843

Entry2 @ 80.870 TradeSize: 1000 ExitPrice: 80.843

Entry3 @ 80.850 TradeSize: 1000 ExitPrice: 80.843

Entry4 @ 80.858 TradeSize: 1000 ExitPrice: 80.843

Entry5 @ 80.844 TradeSize: 1000 ExitPrice: 80.843

Entry6 @ 80.850 TradeSize: 1000 ExitPrice: 80.843

Entry7 @ 80.861 TradeSize: 1000 ExitPrice: 80.843

Entry8 @ 80.844 TradeSize: 1000 ExitPrice: 80.843

Position #2 Trade #9 AvgEntryPrice: 80.843 ExitPrice: 80.850 Trades into position: 2

Entry1 @ 80.843 TradeSize: 1000 ExitPrice: 80.850

Entry2 @ 80.834 TradeSize: 1000 ExitPrice: 80.850

Position #3 Trade #11 AvgEntryPrice: 80.750 ExitPrice: 80.769 Trades into position: 2

Entry1 @ 80.750 TradeSize: 1000 ExitPrice: 80.769

Entry2 @ 80.757 TradeSize: 1000 ExitPrice: 80.769

Position #4 Trade #13 AvgEntryPrice: 80.773 ExitPrice: 80.834 Trades into position: 2

Entry1 @ 80.773 TradeSize: 1000 ExitPrice: 80.834

Entry2 @ 80.776 TradeSize: 1000 ExitPrice: 80.834

Position #5 Trade #15 AvgEntryPrice: 80.782 ExitPrice: 80.778 Trades into position: 10

Entry1 @ 80.782 TradeSize: 1000 ExitPrice: 80.778

Entry2 @ 80.797 TradeSize: 1000 ExitPrice: 80.778

Entry3 @ 80.793 TradeSize: 1000 ExitPrice: 80.778

Entry4 @ 80.804 TradeSize: 1000 ExitPrice: 80.778

Entry5 @ 80.800 TradeSize: 1000 ExitPrice: 80.778

Entry6 @ 80.801 TradeSize: 1000 ExitPrice: 80.778

Entry7 @ 80.806 TradeSize: 1000 ExitPrice: 80.778

Entry8 @ 80.818 TradeSize: 1000 ExitPrice: 80.778

Entry9 @ 80.825 TradeSize: 1000 ExitPrice: 80.778

Entry10 @ 80.815 TradeSize: 1000 ExitPrice: 80.778

Position #6 Trade #25 AvgEntryPrice: 81.141 ExitPrice: 81.106 Trades into position: 8

Entry1 @ 81.141 TradeSize: 1000 ExitPrice: 81.106

Entry2 @ 81.145 TradeSize: 1000 ExitPrice: 81.106

Entry3 @ 81.178 TradeSize: 1000 ExitPrice: 81.106

Entry4 @ 81.165 TradeSize: 1000 ExitPrice: 81.106

Entry5 @ 81.143 TradeSize: 1000 ExitPrice: 81.106

Entry6 @ 81.132 TradeSize: 1000 ExitPrice: 81.106

Entry7 @ 81.124 TradeSize: 1000 ExitPrice: 81.106

Entry8 @ 81.136 TradeSize: 1000 ExitPrice: 81.106

Position #7 Trade #33 AvgEntryPrice: 81.063 ExitPrice: 81.084 Trades into position: 1

Entry1 @ 81.063 TradeSize: 1000 ExitPrice: 81.084

Position #8 Trade #34 AvgEntryPrice: 80.870 ExitPrice: 80.843 Trades into position: 7

Entry1 @ 80.870 TradeSize: 1000 ExitPrice: 80.843

Entry2 @ 80.859 TradeSize: 1000 ExitPrice: 80.843

Entry3 @ 80.863 TradeSize: 1000 ExitPrice: 80.843

Entry4 @ 80.867 TradeSize: 1000 ExitPrice: 80.843

Entry5 @ 80.857 TradeSize: 1000 ExitPrice: 80.843

Entry6 @ 80.858 TradeSize: 1000 ExitPrice: 80.843

Entry7 @ 80.849 TradeSize: 1000 ExitPrice: 80.843

Position #9 Trade #41 AvgEntryPrice: 80.961 ExitPrice: 80.938 Trades into position: 5

Entry1 @ 80.961 TradeSize: 1000 ExitPrice: 80.938

Entry2 @ 80.954 TradeSize: 1000 ExitPrice: 80.938

Entry3 @ 80.958 TradeSize: 1000 ExitPrice: 80.938

Entry4 @ 80.960 TradeSize: 1000 ExitPrice: 80.938

Entry5 @ 80.942 TradeSize: 1000 ExitPrice: 80.938

Position #10 Trade #46 AvgEntryPrice: 80.938 ExitPrice: 80.961 Trades into position: 2

Entry1 @ 80.938 TradeSize: 1000 ExitPrice: 80.961

Entry2 @ 80.927 TradeSize: 1000 ExitPrice: 80.961

Position #11 Trade #48 AvgEntryPrice: 81.211 ExitPrice: 81.230 Trades into position: 2

Entry1 @ 81.211 TradeSize: 1000 ExitPrice: 81.230

Entry2 @ 81.216 TradeSize: 1000 ExitPrice: 81.230

Position #12 Trade #50 AvgEntryPrice: 81.230 ExitPrice: 81.215 Trades into position: 10

Entry1 @ 81.230 TradeSize: 1000 ExitPrice: 81.215

Entry2 @ 81.252 TradeSize: 1000 ExitPrice: 81.215

Entry3 @ 81.246 TradeSize: 1000 ExitPrice: 81.215

Entry4 @ 81.223 TradeSize: 1000 ExitPrice: 81.215

Entry5 @ 81.223 TradeSize: 1000 ExitPrice: 81.215

Entry6 @ 81.230 TradeSize: 1000 ExitPrice: 81.215

Entry7 @ 81.255 TradeSize: 1000 ExitPrice: 81.215

Entry8 @ 81.240 TradeSize: 1000 ExitPrice: 81.215

Entry9 @ 81.239 TradeSize: 1000 ExitPrice: 81.215

Entry10 @ 81.243 TradeSize: 1000 ExitPrice: 81.215

Position #13 Trade #60 AvgEntryPrice: 81.215 ExitPrice: 81.242 Trades into position: 2

Entry1 @ 81.215 TradeSize: 1000 ExitPrice: 81.242

Entry2 @ 81.210 TradeSize: 1000 ExitPrice: 81.242

Position #14 Trade #62 AvgEntryPrice: 81.266 ExitPrice: 81.276 Trades into position: 2

Entry1 @ 81.266 TradeSize: 1000 ExitPrice: 81.276

Entry2 @ 81.269 TradeSize: 1000 ExitPrice: 81.276

Dave Masalov wrote:EntryPrice returns average Entry price, (..)

I don't mean this disrespectful, but I doubt that. See for example the output above - the EntryPrice(positions ago) returns the entry price for the first entry of the total position. Also other tests that I've done never returned the average entry price for the complete position. What am I doing wrong?

Regards,

Josh