I'm getting very different values in OnClosePosition than I get when I look at the trade information after the simulation is done. The values are off by quite a bit and it is wreaking havoc on calculations. It becomes obvious when I simply add a trade metric to show the profit from within OnClosePosition; it is very different than the default Profit metric in the table of trades.
Upon further investigation, it appears that the values in OnClosePosition are the values at the time the exit signal is received, but not necessarily the time when the position is actually closed (depending on simulation settings). So the difference seems to be that my system sell setting is to sell on the close tomorrow. So the profit shown in OnClosePosition is not correct because the position is not sold until tomorrow.
So I believe I need to add the trade metrics in OnEndPeriod using:
Portfolio.GetClosedPositions(Divers.CurrentDate);
Will this always give me the final profit per position?
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.