Hi jyd, I checked again today and it did not work. Here's the code for my script:

Code
// Simple portfolio rotation /////////////
//////////////////////////////////////////

#define RISK	0.7	// no risk, no fun

var Momentums[100],Weights[100];

void rotate(int GoLong)
{
	var Invest = RISK*(Capital+ProfitTotal);
	for(listed_assets) {
		int NewLots = Invest*Weights[Itor]/MarginCost;
		if(Test) {
			if(NewLots > LotsPool && GoLong)
				enterLong(NewLots-LotsPool);
			else if(NewLots < LotsPool)
				exitLong(0,0,LotsPool-NewLots);
		} else if(Live) {
			int OldLots = brokerCommand(GET_POSITION,Asset);
			if(NewLots > OldLots && GoLong)
				enterLong(NewLots-OldLots);
			else if(NewLots < OldLots)
				enterShort(OldLots-NewLots);
		}
	}
}

void run() 
{
	set(PLOTNOW|LOGFILE);
	StartDate = ifelse(Live,NOW,20120101); 
	EndDate = 20181231;
	BarPeriod = 1440;
	LookBack = 100;
	SaveMode = 0;
	
	assetList("AssetsSP30");
	Capital = slider(1,10000,0,20000,"Capital","");
	
	for(listed_assets) { 
		asset(Asset);
		vars Prices = series(priceClose());
		Momentums[Itor] = ROC(Prices,LookBack-1);
	}

	if((Live && !is(LOOKBACK))
		|| (Test && tdm(0) == 1 && month(0)%2)) // first trading day of every second month
	{
		distribute(Weights,Momentums,NumAssetsListed,5,0.5); 
		rotate(0);	// exit old positions
		rotate(1);	// enter new positions
	}

	if(Live && !is(LOOKBACK)) quit("Ok!");
}


I did two attempts, on the first he opened 5 positions. Directly after I started the script a second time. This time Zorro tried to open another 5 positions, but could not close the trades from the previous run. So there was not enough margin left to place all orders.

Can anyone help me fix this?

Thanks in advance,

Simon

Attached Files Bildschirmfoto 2021-04-07 um 16.48.33.jpgBildschirmfoto 2021-04-07 um 16.49.08.jpg