I am attempting to write various information about OOS trades during walk-forward optimization. For example, I would like to save the closing price of a stock for every day my system is in a trade. The following code works well for a regular backtest, but it appears I only write the IS trade data during a walk-forward optimization. Is there a way to access the closed OOS trades during optimization?
Thanks in advance.
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject();
bo.PreProcess();
path = "test.csv";
fh = fopen(path, "a");
fputs("Bar#,Symbol,Date,Shares,Price\n", fh);
y = Year();
m = Month();
d = Day();
thisDateTime = DateTime();
for (bar = 0; bar < BarCount; bar++)
{
for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
{
// trade variable now holds Trade object
if (trade.ExitDateTime == thisDateTime[bar - tradeDelay])
{
totalBars = trade.BarsInTrade + tradeDelay;
for (i = -totalBars; i < 0; i++)
{
lookback = bar + i;
bStr = StrFormat("%g,", totalBars + i);
fputs(bStr, fh);
symbols = trade.Symbol;
fputs(symbols + ",", fh);
dStr = StrFormat("%02.0f%02.0f%02.0f,", y[lookback], m[lookback], d[lookback]);
fputs(dStr,fh);
shStr = StrFormat("%4.2f,", trade.Shares);
fputs(shStr, fh);
symC = Foreign(trade.Symbol, "C");
prStr = StrFormat("%4.2f\n", symC[lookback]);
fputs(prStr, fh);
}
}
}
bo.ProcessTradeSignals(bar);
}
bo.PostProcess();
fclose(fh);
}