Portfolio Trader - Money Management Signal Max Symbols

Questions about MultiCharts and user contributed studies.
The9000
Posts: 59
Joined: 24 Oct 2015
Has thanked: 2 times
Been thanked: 4 times

Portfolio Trader - Money Management Signal Max Symbols

Postby The9000 » 27 Dec 2015

I have a strategy with a money management signal that limits the symbols for trading based on the slope of the equity curve. It limits possible entries to the 5 symbols that have the highest slope of their equity curve.

The code in the strategy creates the equity curve based on the last X number of trades. It then creates a regression of the last X number of trades and sends it to the money management signal. This code is the following:

Code: Select all

Inputs:
LRSlopeLen(30);

Array: a_NetPL[](0);
condition1 = Array_setmaxindex(a_NetPL,LRSlopeLen);

Vars:

TotTds(0),
oLRSlope( 0 ),
oLRAngle( 0 ),
oLRIntercept( 0 ),
oLRValueRaw( 0 ) ;


TotTds = TotalTrades;

If TotTds > TotTds[1] then begin
For value1 = LRSlopeLen downto 2 begin
a_NetPL[value1] = a_NetPL[value1-1];
end;
a_NetPL[1] = netprofit;
If TotTds >= LRSlopeLen then Value1 = LinRegArray( a_NetPL, LRSlopeLen, 0, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw ) ;
pmms_set_strategy_named_num(pmms_strategies_get_by_symbol_name(symbolname), "slope", oLRSlope);

end;




The money management signal code is the following:

Code: Select all

variables:

SlopeA(0),
portfolioStrategies(0),
idx(0),
Target_idx(0),
SortOrder(0),
StrategiesOK(0),
OKCount(0),
Counter(0);

arrays:

EquitySlope[](0),
TargetRank[](0);



If time = 0850 then begin

portfolioStrategies = pmms_strategies_count();
array_setmaxindex(EquitySlope, portfolioStrategies);
array_setmaxindex(TargetRank, portfolioStrategies);
print("Portfolio Strategies = ", portfolioStrategies);

// Deny entries to all targets

pmms_strategies_deny_entries_all();


for idx = 0 to portfolioStrategies -1 begin
EquitySlope[idx] = pmms_get_strategy_named_num(idx, "slope");
end;

array:

Value_Idx[2, 150](0);

for idx = 0 to portfolioStrategies -1 begin
Value_Idx[1, idx + 1] = EquitySlope[idx];
Value_Idx[2, idx + 1] = idx;

end;

// Sort from the largest equity curve slope to the smallest

SortOrder = 1;

Sort2DArray(Value_Idx, 2, portfolioStrategies, SortOrder );

// Allow entry for the five strategies with the highest slope values

for idx = 0 to 4 begin

pmms_strategy_allow_entries(Value_Idx[2, idx + 1]);

end;

end;
It works the way it's supposed - on the first 60 symbols in the portfolio only. It never enters any trades beyond the first 60 symbols. This is an intraday strategy that runs on 2 minute bars on Data1 and daily bars on Data2. As shown below, after 'A', it doesn't trade any of the symbols beyond that. These are the results by symbol:

Portfolio Overview By Symbols

Market Start Date End Date Net Profit # Trades
BBRY 3/1/06 11:08 12/24/15 15:00 -2608.52 30
HD 3/7/06 9:10 12/24/15 14:20 -3815.25 30
GS 3/1/06 9:02 12/24/15 13:26 11091.89 72
GOOG 4/12/06 7:54 12/24/15 15:12 -1395.88 34
AMZN 3/1/06 8:50 12/24/15 15:46 2734.21 55
CAT 3/1/06 9:00 12/24/15 14:30 -2867.86 30
BA 6/9/06 8:54 12/24/15 14:16 3320.13 38
CRM 6/19/06 8:52 12/24/15 13:26 1591.18 49
NFLX 7/14/06 9:02 12/24/15 16:00 -364.58 30
USO 7/17/06 7:12 12/24/15 15:42 1988.05 34
SLB 9/7/06 9:08 12/24/15 13:26 2697.22 56
DVN 10/6/06 10:38 12/24/15 13:30 -2221.05 39
INTC 10/4/06 9:02 12/24/15 12:26 -4496.9 30
UNH 10/18/06 9:02 12/24/15 12:36 -816.97 36
KO 4/13/07 10:10 12/24/15 12:26 -1980.4 34
AA 12/11/06 9:28 12/24/15 15:34 3001.37 35
AAL 3/7/07 10:10 12/24/15 13:44 4557.74 74
MCD 4/12/07 10:06 12/24/15 14:26 -2164.59 39
WMT 6/20/07 9:34 12/24/15 14:58 -616.84 30
CSCO 7/3/07 12:00 12/24/15 15:00 -3022.72 30
MSFT 8/27/07 9:30 12/24/15 13:50 -2195.4 30
FB 8/1/12 9:02 12/24/15 14:56 1136.66 30
T 11/19/07 9:02 12/24/15 14:40 539.56 31
VZ 11/26/07 9:04 12/24/15 13:26 -5221.67 30
V 6/2/08 10:58 12/24/15 14:14 466.08 63
DOW 2/15/08 9:26 12/24/15 13:00 -2053.61 30
DD 9/14/15 7:36 12/24/15 12:26 -5458.61 30
MON 4/21/08 12:24 12/24/15 12:36 -320.4 32
LYB 7/15/10 9:40 12/24/15 12:26 17830.89 143
ECL 10/14/08 9:02 12/24/15 12:26 -216.78 30
PX 10/27/08 9:46 12/24/15 12:26 -519.84 31
PPG 2/18/09 9:02 12/24/15 12:26 3209.11 45
APD 4/7/09 9:36 12/24/15 12:26 4796.39 39
NKE 4/15/09 9:02 12/24/15 14:58 -5406.58 30
WFC 8/17/09 9:30 12/24/15 14:58 -5275.21 30
UA 9/3/09 9:08 12/24/15 14:22 -2913.47 30
BRK.B 2/24/10 10:54 12/24/15 14:38 4506.84 54
AXP 12/15/09 9:16 12/24/15 14:10 262.49 43
BAC 12/23/09 9:28 12/24/15 14:56 2229 47
SPG 1/12/15 10:40 12/24/15 12:26 -5344.6 30
DIS 9/2/10 10:18 12/24/15 16:02 -2752.68 30
CMCSA 2/28/11 9:02 12/24/15 12:24 -5364.73 30
SBUX 10/20/11 9:42 12/24/15 14:54 -643.05 35
LOW 4/2/12 12:54 12/24/15 12:26 -1497.75 30
PCLN (2 Minutes) 6/1/12 10:08 12/24/15 12:58 -9062.48 215
F 9/11/12 9:04 12/24/15 14:36 -666.41 32
JNJ 2/1/13 9:14 12/24/15 13:46 -613.36 47
XOM 5/28/13 9:02 12/24/15 14:32 -44.54 30
PFE 3/1/06 7:02 12/24/15 15:58 -2046.78 30
PCLN (2 Minutes) 11/28/12 9:34 12/24/15 12:58 3015.57 59
COP 5/31/13 9:02 12/24/15 14:08 -7224.88 30
ACN 1/13/14 9:18 12/24/15 12:12 -1218.94 30
ACE 9/8/14 8:34 12/24/15 12:26 546.27 40
ADBE 6/6/14 8:34 12/24/15 13:26 5115.02 46
ADT 12/12/14 10:02 12/24/15 12:02 4205.01 73
AES 7/29/15 9:58 12/24/15 12:12 9259.2 49
AET 6/9/15 12:30 12/24/15 12:02 2530.78 27
AMG 12/8/15 9:24 12/24/15 12:26 1589.51 8
AFL 11/19/15 11:48 12/24/15 12:46 1605.02 5
A n/a 12/24/15 12:04 n/a 0
GAS n/a 12/24/15 12:02 n/a 0
ADP n/a 12/24/15 12:16 n/a 0
ARG n/a 12/24/15 12:26 n/a 0
AKAM n/a 12/24/15 12:16 n/a 0
ALXN n/a 12/24/15 14:54 n/a 0
ATI n/a 12/24/15 12:26 n/a 0
ALLE n/a 12/24/15 12:04 n/a 0
AGN n/a 12/24/15 13:14 n/a 0
ADS n/a 12/24/15 12:26 n/a 0
ALL n/a 12/24/15 12:26 n/a 0
ALTR n/a 12/24/15 14:22 n/a 0
MO n/a 12/24/15 15:00 n/a 0
AEP n/a 12/24/15 12:02 n/a 0
AEE n/a 12/24/15 12:04 n/a 0
AMT n/a 12/24/15 12:26 n/a 0
AMP n/a 12/24/15 12:26 n/a 0
ABC n/a 12/24/15 12:02 n/a 0
CBS n/a 12/24/15 12:04 n/a 0
AME n/a 12/24/15 12:18 n/a 0
AMGN n/a 12/24/15 14:02 n/a 0
APC n/a 12/24/15 12:28 n/a 0
AON n/a 12/24/15 12:26 n/a 0
APA n/a 12/24/15 12:24 n/a 0
AAPL n/a 12/24/15 15:00 n/a 0
EWZ n/a 12/24/15 12:26 n/a 0
RSX n/a 12/24/15 13:26 n/a 0
GLD n/a 12/24/15 14:28 n/a 0
GDX n/a 12/24/15 14:46 n/a 0
ILF n/a 12/24/15 12:40 n/a 0

Am I missing something or is there a bug?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby Henry MultiСharts » 08 Jan 2016

Hello The9000,

You need to add output to the code to check whether your sorted array allows to trade strategies with idx>60 or not. Most likely the instruments that do not trade are not at the top of the array after the sorting.

The9000
Posts: 59
Joined: 24 Oct 2015
Has thanked: 2 times
Been thanked: 4 times

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby The9000 » 08 Jan 2016

Hi Henry,

Thanks for the response.

As I looked into this further and started debugging it by printing some values in the Power Editor while the code was running, I stumbled upon something else that is partly at fault.

The way I thought the Money Management script worked is that is acted as a firewall between the strategy and actual trading. The strategy creates an order and then the money management script can allow, disallow, increase the position size or decrease the position size.

The problem turns out to be the netprofit function in the strategy. When the money management script prevents a symbol from entering a trade, the strategy does not see that trade as being taken.

For example, if in the money management script, I create a filter that looks at the regression slope of the equity curve such as:

If SlopeOfEquityCurve < 0 then don't allow the trade

The problem is that once the value is under 0, it will never trade again because inside the strategy, it also sees the trade as never taken for this symbol. And once the slope drops under 0, it can never rise above 0 because it will no longer make trades in that symbol.

If I wanted to know the actual net profit from each symbol in the portfolio based on the effects of the money management script, I could use the pmms_strategy_netprofit(idx) function. So inside the strategy itself, should the netprofit function show the netprofit of the strategy itself, regardless of the effects of the money management script?

If not, is there a simple way to do this?

What I'm trying to do is find which symbols in the portfolio, based on the slope of the equity curve over the last X number of trades and limiting the trading to only the top Y number of symbols.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby Henry MultiСharts » 26 Jan 2016

Hello The9000,

It depends on the auto trading mode you are using:
In SA mode pmms_strategy_netprofit returns a numerical value representing net profit of the actual executed trades at the broker of the strategy with StrategyIndex number.
In AA mode pmms_strategy_netprofit returns a numerical value representing net profit of the backtested trades of the strategy with StrategyIndex number.
For more information please refer to our wiki for Understanding_Automated_Trade_Execution.

The9000
Posts: 59
Joined: 24 Oct 2015
Has thanked: 2 times
Been thanked: 4 times

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby The9000 » 27 Jan 2016

Hi Henry,

Thanks for the response.

I tried running the backtest in AA and SA mode. This is over 10 years of intraday data, from 2006 through today, on 2 minute bars on 60 symbols. There is no difference in the backtest results using either the SS or AA mode.

To troubleshoot, I added code to the MMS that prints out the symbols sorted values. Once a symbol is knocked out of the top 15 or so (the top 10 are allowed to trade), no trades take place within the strategy. Some symbols quit trading in 2008.

Printing the equity curve slope data as a CSV into a file and importing into Excel reveals there are many symbols that, if allowed to continue trading, would make it into the top 10 allowed to trade.

So I replaced the netprofit function within the strategy with pmms_strategy_netprofit function. This produced different results, however the core problem still exists. It doesn't trade the symbol within the strategy if the MMS prevents entry.

As a work around, I think making the netprofit function in the Portfolio Trader reflect the actual net profit generated by the strategy, regardless of the MMS, would work. The pmms_strategy_netprofit function can be used to view the net profit of the strategy with the effects of the MMS applied.

This would be an extremely powerful feature of Multicharts. It would allow effective equity curve trading.

zfsamzfsam
Posts: 9
Joined: 09 Aug 2014
Has thanked: 31 times
Been thanked: 3 times

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby zfsamzfsam » 25 Feb 2016

As a work around, I think making the netprofit function in the Portfolio Trader reflect the actual net profit generated by the strategy, regardless of the MMS, would work.
=>pmms_strategy_netprofit_without_mms

The9000
Posts: 59
Joined: 24 Oct 2015
Has thanked: 2 times
Been thanked: 4 times

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby The9000 » 25 Feb 2016

As a work around, I think making the netprofit function in the Portfolio Trader reflect the actual net profit generated by the strategy, regardless of the MMS, would work.
=>pmms_strategy_netprofit_without_mms
Yes! Please add this feature to the next release.

That one keyword would save lots of coding hours. I developed a work around within the strategy of calculating the netprofit regardless of the MMS effects. It took me about a day of coding to get it to work properly and transposing it other strategies is cumbersome.

Zordan3274
Posts: 2
Joined: 11 Mar 2024

Re: Portfolio Trader - Money Management Signal Max Symbols

Postby Zordan3274 » 11 Mar 2024

Hello, The9000, would you mind sharing your workaround?


Return to “MultiCharts”