MaxOpenPosition based on Equity

Hello, could someone help me, how to write code for MaxOpenPosition based on Equity?
See the following code:

SetOption("initialequity",5000);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",2);

//MaxPositions = 5;
PEquity =Foreign ("~~~EQUITY","C");
MaxPositions = round(PEquity/1000);
SetOption("MaxOpenPositions", MaxPositions );

PositionSize = -15; // invest 25% of equity in single security 
RoundLotSize = 1; // No fractional shares

// trade on next day open
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Open * 1.001; // * 1.001 = slippage;

SetBacktestMode( backtestRotational );
// PositionScore
PositionScore =  100 - RSI (14);	

Filter = 1;
AddColumn( PositionSize, "PositionSize", 1.2, colorDefault, colorDefault) ;
AddColumn( MaxPositions, "MaxPositions", 1.2, colorDefault, colorDefault) ;
AddColumn( PEquity, "PEquity", 1.2, colorDefault, colorDefault) ;

"Foreign ("~~~EQUITY","C") " is wrong becouse call an ARRAY but NUMBER is expected. How can I write "EQUITY" with call a NUMBER?

Thank you.

MaxOpenPositions is a MAXIMUM number of positions EVER needed during entire backtest. It is not "current" number of positions. It is scalar number. Global backtester setting. The limit. It is like "c" (speed of light). Absolute limit. It does not change "bar by bar".

To limit number of positions based on equity you should just use fixed amount for position size.

// that would give you 5 positions when equity is 5000 and 10 if equity is 10000
PositionSize = 1000;