Money Management Code that Won't Bust my Margin

Questions about MultiCharts and user contributed studies.
Posts: 50
Joined: 28 Sep 2014
Has thanked: 7 times

Money Management Code that Won't Bust my Margin

Postby trader0311 » 28 Apr 2015


I would like to Manage a portfolio whereby there are several strategies that are applied to each symbol. I would like to somehow rank each strategy and limit the number of open positions so that I don't bust my margin (I am trading stocks at Interactive Brokers).

As a hypothetical, I have 5 strategies applied to 10 different ETF's for 50 strategies total. I would like to rank each of these strategies based on the order that I would want them to execute, giving preference to better performing strategies. I only want one of the strategies to be active on any one symbol (ie I don't want all 5 strategies to fire on the same symbol). I also want to limit the number of open positions to 5 and allocate a certain amount of money to each position. (lets say I have a $50,000 account and want my trade size to be $10,000 per position for a max of 5 positions).

So I need a money management strategy that will allow me to set my maximum exposure as a percentage of capital that I would specify. The money management strategy would look first at the priority assigned to each strategy and then begin executing the strategies based on the ranking order and would put on a number of positions that would not exceed 5 (ie my maximum exposure).

I am open to doing this in the Portfolio Trader or by using separate charts. I am just not sure how to tell Multicharts what I would like my exposure to be and then have MC not exceed that exposure limit.

Sorry for the long question, but any help on this matter would be greatly appreciated.

User avatar
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times

Re: Money Management Code that Won't Bust my Margin

Postby fbertram » 30 Apr 2015

Hi there,

did you have a look at the documentation? See here: ... lio_Trader ... y_Examples

The examples are actually pretty good.

You can figure out your current portfolio size like this:
EquityAvailable = iff(GetAppInfo(aiStrategyAuto) = 1, GetRTAccountEquity(GetAccountID), Portfolio_Equity) * 0.99;

The reason why this is a bit more complicated is, that you want it to work both in real time and in backtesting.

Based on this, you can 'resize' the orders created by the strategies using pmms_strategy_set_entry_contracts.

You will probably need the target price to figure out the number of contracts... which the strategy can assign using pmm_set_my_named_num and the MM signal can read via pmms_get_strategy_named_num.

Hope this helps,


Return to “MultiCharts”