Simple code like the following, however, is NOT adequate to accurately capture all strategy trades:
TotTrades = TotalTrades;
if TotTrades <> TotTrades[1] then
n = n + 1;
TradeArray[n] = PositionProfit(1);
end;
Therefore, additional logic is needed to ensure all trades are captures into the array. The following code may be used:
if BarStatus(1) = 2 then begin
{ NewTrades will be > 1 if more than 1 trade is closed on same bar }
NewTrades = TotalTrades – PriorTotalTrades;
for j = 1 to NewTrades begin
n = n + 1;
TradeArray[n] = PositionProfit(j);
{ store number of trades in unused element 0 of array }
TradeArray[0] = n;
end;
PriorTotalTrades = TotalTrades;
end;
A better practice would be to bracket the call to the function with the BarStatus(1) = 2 requirement in the strategy code to reduce the frequency of calls to this function:
if BarStatus(1) = 2 then begin
value1 = LoadTradeArray(TradeArray);
end;
Downloads
Initially posted version: 09/16/09
Latest Update: 07/04/10
*.ELD files are compiled for TS 8.6
All ELD and code text files packaged here:
Users of earlier versions fo TradeStation may compile the code
from the text files included in the above *.zip file.
The code may be visualized here: