Part 1. I want to dump the results of all trades to a file. These are my training targets.
Part 2. I want to dump the values of several signals to a file. These are my training signals.
To prevent leaking future data into signals, training signals and targets must be synchronized.
I can dump part 2 at every bar. There will be one record per bar, and they will be ordered by Bar number.
I can dump part 1 only in EXITRUN since I need to wait for the trade to play out.
I figured I would use all_trades to loop through these trades, as you helpfully suggested, but I encountered three prohibitive factors.
1. There are gaps when a trades are not entered or when entry conditions were not met. If there are several entries per Bar, some may have a gap and others not. So it's very difficult to sift them all out.
2. There is no way to get a TRADE's entry time. There is no such thing as a TradeBarEntry property. So now (1) really seems like a quagmire.
3. They are not sorted by Entry time. It doesn't matter that the list starts out sorted, and in the interest of efficiency something comes along and partially disturbs the sorting. In computer science, an array is either sorted by some quality or it is not. Here, it's not. So, no help there either.
Do you get it?
To get around this, I am maintaining my own array of TRADE* I've created. It looks like you might imagine.
TRADE** my_trades = NULL;
int* my_trades_bar = NULL;
int my_trades_pos;
void init_my_trades() {
int size = MAX_BARS * TRADES_PER_BAR * sizeof(TRADE*);
my_trades = (TRADE*) malloc(size + 1);
size = MAX_BARS * TRADES_PER_BAR * sizeof(int);
my_trades_bar = (int*) malloc(size + 1);
my_trades_pos = 0;
}
void my_trade(TRADE* trade) {
my_trades[my_trades_pos] = trade;
my_trades_bar[my_trades_pos] = Bar;
my_trades_pos++;
if (my_trades_pos >= MAX_BARS * TRADES_PER_BAR) {
printf("\nOut Of my_trades positions.");
quit();
}
}
function run() {
if (is(INITRUN)) {
init_my_trades();
...
}
...
my_trade(enterLong());
my_trade(enterShort());
if(is(EXITRUN)) {
for (trade_num = 0; cols_output < TRADES_PER_BAR; trade_num++) {
ThisTrade = my_trades[trade_num];
// write TradeResult to file
// two per line
// with special handling for NULL.
}
}
}
In the meantime, as a side note, I observed surprising behavior of EntryTime = 1. I do not understand how, with EntryTime = 1, TradeBarOpen can be anything other than NULL or the bar number the trade was entered. EntryTime = 1 should mean open the trade withing this bar or not at all. Not, in a later bar.
Get it?