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;
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?