rotational trading

#1
Hi,
I wrote an algorithm which says that I would like the 5 best stocks each month and sell them in the same month. I choose the 5 best stocks according to the performance.
What I would like to do now:
I would like to have in total 50000 equity capital. But for each stock 10000.
That means that I would like to buy every month 5 stocks with an equity capital of 10000 per stock. Next month when I buy it I would like to have the same.
Right now, the capital is accumulating. But I do not want that my algorithm accumulates.
The other thing is that I would like to say: If for example AAPL is in january under the 5 best ones and in february as well. I don't want to buy it again and the equity capital in total is 40000.
Is there anyone who could help me with this?
 
#2
this is my code so far:

SetPositionSize(50000,spsValue);
PosQty = Param( "Number of Positions", 5, 1, 20, 1); // name, MaxOpenPositions, MinShares,
SetOption( "InitialEquity", 50000 );
SetPositionSize(20,spsPercentOfEquity);
SetPositionSize(PosQty,spsNoChange);
SetOption( "MaxOpenLong", PosQty );
SetOption( "MaxOpenPositions", PosQty );
SetOption( "WorstRankHeld", PosQty );
SetOption( "AllowPositionShrinking", True );
 

Similar threads