I am doing something similar using sprintf and file_append to write a csv file with the nbar movement as the target.

I can't easily see how write a custom csv file using the result of the next trade as the target.

Too many features leads to a risk of overfitting, but you do need to select which signals to use. I would suggest writing several scripts to export different sets of 20 signals. Then you can run feature selection on those in order to choose the best 20 signals for the final version.