I've been working on a ML based algorithm and I've run into a major problem.
Basically, my code uses pipline (which on a daily basis choosed 8 to 12 stocks to trade). The problem I am having is that the positions stack on top each other as days progress. So I might start of, on the first day with something like 4 longed positions and 4 shorted positions, but in a month I'll end up with around 39 longed positions and 64 shorted positions. I want to get rid of the pipeline-chosen positions at the end of each day, so that the next day I start with a fresh batch of pipeline-chosen positions the next day.
This causes extremely high leverage! I've been looking for solutions pertaining to this problem and haven't been able to find one yet. Please look at my algorithm to better understand this problem. (Look the custom data graph for the long position/short position counts)