Equity Curve Trading

Questions about MultiCharts and user contributed studies.
CharlieChalk
Posts: 7
Joined: 09 Feb 2015

Equity Curve Trading

Postby CharlieChalk » 18 Apr 2016

Hello,

i realise that you only like to give limited coding assistance but i believe the bulk of the coding has been done. I am trying to get a Money Management system that trades the equity code of a system on each individual futures contract it is applied too.

The MM system presently looks at the regression of the equity curve for the last N number of trades. The code below is placed in the strategy code:
[+] see the code

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] = (PreviousEquity - netprofit)/EquityScaler;
If TotTds>= LRSlopeLen then Value1 = LinRegArray( a_NetPL, LRSlopeLen, 0, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw ) ;
oLRSlope = oLRSlope / RSize;
end;]
This then passes a value to the MM system which places the regression values into quartiles and then passes the new Position size back to the strategy. See below for this code:
[+] see the code

Code: Select all

[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;]
One of the issues i have is when i try to verify this code i get an error code back saying:
"assignment is allowed only for variables or array elements
line 2, column 0"

I'd very much appreciate if you could help me understand where on earth i am going wrong with this. I'll be honest this is entirely my own code :)

Thanks Charlie

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

Re: Equity Curve Trading

Postby Henry MultiСharts » 19 Apr 2016

Hello Charlie,

First of all you need to remove the square brackets at the beginning and at the end of the code. Then you need to declare the variables/inputs that are not declared in the pieces of code you have provided.

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

Re: Equity Curve Trading

Postby The9000 » 21 Apr 2016

Hello,

i realise that you only like to give limited coding assistance but i believe the bulk of the coding has been done. I am trying to get a Money Management system that trades the equity code of a system on each individual futures contract it is applied too.

The MM system presently looks at the regression of the equity curve for the last N number of trades. The code below is placed in the strategy code:
[+] see the code

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] = (PreviousEquity - netprofit)/EquityScaler;
If TotTds>= LRSlopeLen then Value1 = LinRegArray( a_NetPL, LRSlopeLen, 0, oLRSlope, oLRAngle, oLRIntercept, oLRValueRaw ) ;
oLRSlope = oLRSlope / RSize;
end;]
This then passes a value to the MM system which places the regression values into quartiles and then passes the new Position size back to the strategy. See below for this code:
[+] see the code

Code: Select all

[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;]
One of the issues i have is when i try to verify this code i get an error code back saying:
"assignment is allowed only for variables or array elements
line 2, column 0"

I'd very much appreciate if you could help me understand where on earth i am going wrong with this. I'll be honest this is entirely my own code :)

Thanks Charlie
viewtopic.php?f=1&t=49287&p=119431#p119431

It looks like you copied my code almost verbatim from another post and are taking it out of context. You have just a snippet of the moving pieces you need to make this work.
Last edited by The9000 on 21 Apr 2016, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Equity Curve Trading

Postby TJ » 21 Apr 2016

When you pinch someone's code, you should always give credit, and to cite the source. How difficult is that? It is merely a respect for other's hard work, and to show appreciation for the author's generosity of sharing.


Return to “MultiCharts”