London
Experience: Advanced
Platform: MultiCharts
Trading: Global Futures
Posts: 6 since Apr 2016
Thanks Given: 2
Thanks Received: 0
|
Hello guys,
i've actually pinched this code from another user on this site but have been unable to make the modifications to work. Basically the code is looking at the slope of the closed trades equity curve and then passing this to a money management algorithm which resizes the trade size depending on whether the strategy is going through a winning or losing streak.
There are two parts to this, firstly the code to be placed within the strategy code and then secondly the code for the money management algorithm(MM) to be placed in the MM signal section within Portfolio Trader.
At present i have this code for the MM signal but am not sure if i have assigned code correctly to variables or arrays:
var:
AdjustedPositionSize(0),
IDX(0),
TargetRank(0),
EquitySlope(0);
for idx = 0 to portfolioStrategies -1 begin
TargetRank[idx] = pmms_get_strategy_named_num(idx, "TargetRank");
EquitySlope[idx] = pmms_get_strategy_named_num(idx, "EquityCurveSlope");
// Adjust position size based on equity slope
AdjustedPositionSize[idx] = 1.25;
If EquitySlope[idx]>= .150 then AdjustedPositionSize[idx] = 1.5;
If EquitySlope[idx] <= .075 and EquitySlope[idx]> -.075 then AdjustedPositionSize[idx] = .75;
If EquitySlope[idx] <= -.075 then AdjustedPositionSize[idx] = 0;
// Send the adjusted position size back to the strategy
pmms_set_strategy_named_num( idx, "PosSizeScaler", AdjustedPositionSize[idx] );
end;
Secondly there is the code to be placed in the strategy itself:
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] = (PreviousEquity - netprofit)/EquityScaler;
If TotTds>= LRSlopeLen then Value1 = LinRegArray( a_NetPL, LRSlopeLen, 0, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw ) ;
oLRSlope = oLRSlope / RSize;
end;
|