Optimization By linear Equity Curve

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Optimization By linear Equity Curve

Postby Dru » 18 Jan 2013

Attention! It is working only for MC 8.5 beta 2 or higher. There is a bug with keywords "postrade***" during optimization in less versions.
I found that lots of people are interested in a feature that allowes to optimize a strategy by linear equity curve (https://www.multicharts.com/pm/viewissu ... _no=MC-896).
Here is how to use it: add the signal "!optimize by equity curve std dev!" from attached archive to your signals at the end of the list and run optimization. That is all. This signal maximize netprofit and minimize standard deviation of close to close equity curve.
Example:
Optimization only by NetProfit:
Image

Optimization by NetProfit & Standard Deviation of Close to Close Equity Curve:
Image
Attachments
optimize by netprofit & equity std dev.wsp
(145.46 KiB) Downloaded 1783 times
optimize by net profit & equity std dev.pla
(4.02 KiB) Downloaded 1580 times
Last edited by Dru on 19 Jan 2013, edited 1 time in total.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Optimization By linear Equity Curve

Postby furytrader » 18 Jan 2013

Thanks for writing this - can you explain how we use it though? Do we take the code found in !optimize by equity curve std dev! and put that in our signal? When I do that, I get an STD Exception: invalid argument.

I'm sure I'm doing something wrong here - any help?

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: Optimization By linear Equity Curve

Postby Dru » 19 Jan 2013

Thanks for writing this - can you explain how we use it though? Do we take the code found in !optimize by equity curve std dev! and put that in our signal? When I do that, I get an STD Exception: invalid argument.

I'm sure I'm doing something wrong here - any help?
1) Do you use MC 8.5 beta 2?
2) How to use it: add the signal "!optimize by equity curve std dev!" from attached archive to your signals at the end of the list and run optimization. That is all. It is not necessary copy the code. Look on the attached optimize by netprofit & equity std dev.wsp for example.
If it does not work please attach your wsp for reproduce the issue

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Optimization By linear Equity Curve

Postby SUPER » 20 Jan 2013

Thanks for writing this - can you explain how we use it though? Do we take the code found in !optimize by equity curve std dev! and put that in our signal? When I do that, I get an STD Exception: invalid argument.

I'm sure I'm doing something wrong here - any help?
Dru,

I am using MC 8.0 and get same error message?

Will appreciate your help.

Thanks for sharing your work.

Regards
Super

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: Optimization By linear Equity Curve

Postby Dru » 21 Jan 2013

I am using MC 8.0 and get same error message?
It will work only in MC 8.5 beta 2 and future versions.

User avatar
swz168
Posts: 120
Joined: 30 Sep 2010
Location: Germany
Has thanked: 47 times
Been thanked: 32 times

Re: Optimization By linear Equity Curve

Postby swz168 » 23 Jan 2013

Awesome! Thanks a lot, Dru!

Gaempi
Posts: 60
Joined: 27 Jul 2010
Location: Switzerland
Has thanked: 3 times
Been thanked: 8 times

Re: Optimization By linear Equity Curve

Postby Gaempi » 05 Mar 2013

Thank you, Dru! Great work!

StefanoSF
Posts: 116
Joined: 19 Aug 2012
Location: San Francisco
Has thanked: 23 times
Been thanked: 30 times
Contact:

Re: Optimization By linear Equity Curve

Postby StefanoSF » 06 Mar 2013

Hi Dru. Thanks for coding this.

I'm using MC 8.5 release. When running an optimization, in the Algorithm-specific Properties tab, what Standard Criteria should be selected? The WS you provided seems to default to "Custom Fitness Value". This should be selected correct?

And if I were to select "Net Profit", would the "Net Profit" criteria over ride the !optimize by equity curve std dev! signal?

Thank again.

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: Optimization By linear Equity Curve

Postby Dru » 07 Mar 2013

When running an optimization, in the Algorithm-specific Properties tab, what Standard Criteria should be selected?
- "Custom Fitness Value".
This should be selected correct?
- yes.
And if I were to select "Net Profit", would the "Net Profit" criteria over ride the !optimize by equity curve std dev! signal?
- yes.
!optimize by equity curve std dev! signal just provide "Equity Curve Std Dev" value to the optimizer. But only you will specify what criteria should be used.

MeiHua
Posts: 26
Joined: 12 Aug 2012
Has thanked: 1 time

Re: Optimization By linear Equity Curve

Postby MeiHua » 15 Mar 2013

Thanks for the code.

Are we optimizing by ascending or descending?

Ming80
Posts: 24
Joined: 18 Jun 2012
Has thanked: 20 times
Been thanked: 1 time

Re: Optimization By linear Equity Curve

Postby Ming80 » 24 Jun 2014

Old thread but a big thank you to Dru for this.

I'm looking if any of you guys have another fitness function for comparison for a smoother equity curve. The reason is in certain instances majority of profits happen in a year and remain flat afterwards and the net profit/equity standard deviation is ranked high.

I'm looking along the lines somewhat like the perfect profit correlation in TS or equity curve correlation coefficient with net profit from Adaptrade. I'm having trouble translating the code from Adaptrade into a function in MC custom fitness value field either getting array errors or code running too slow to effeciently optimize. Appreciate if anyone could point me in the right direction. Thanks!

http://help.TS.com/09_00/Trad ... fields.htm

http://www.adaptrade.com/BreakoutFuture ... er1104.htm

lianhc
Posts: 7
Joined: 11 Sep 2014

Re: Optimization By linear Equity Curve

Postby lianhc » 14 Sep 2014

Can be written as following in custom criterion

// TODO: Enter your formula to replace the samples below

/************************************* Sample 1 ******************************************/
if (StrategyPerformance.MaxStrategyDrawDown != 0) {
return StrategyPerformance.NetProfit / (-StrategyPerformance.MaxStrategyDrawDown);
}
Attention! It is working only for MC 8.5 beta 2 or higher. There is a bug with keywords "postrade***" during optimization in less versions.

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: Optimization By linear Equity Curve

Postby shanemcdonald » 29 Sep 2014

Hi

How can I get the equity curve line indicator at the bottom of the chart ?
Must I only use this workspace to get that ?

thanks
shane

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

Re: Optimization By linear Equity Curve

Postby Henry MultiСharts » 30 Sep 2014

Hi

How can I get the equity curve line indicator at the bottom of the chart ?
Must I only use this workspace to get that ?

thanks
shane
Hello shane,

You can use i_OpenEquity or GetPositionOpenPL in your code to do that.

shane1800
Posts: 84
Joined: 28 Feb 2014
Has thanked: 5 times
Been thanked: 5 times

Re: Optimization By linear Equity Curve

Postby shane1800 » 18 May 2015

Hello,

I'm really excited to see this metric!

I was able to get it working using the provided workspace.

I then tried to get my own workspace working but the Custom Fitness Value is always 0 and I'm not sure why.

My custom workspace has a data1 and data2, 5 min bars for 5 years.

The !optimize! signal is the last and status is on, "Custom 1 Line" works and shows the equity.

Thinking it maybe something in EquityCurveStdDev

Code: Select all

Input: CalculateRatio(TrueFalseSimple) {final calculation};

if CalculateRatio then begin
array: equty_per_bar[](0);
var: intrabarpersist last_idx(0);

for value1 = maxpositionsago downto 0 begin
value3 = PosTradeCount(value1)-1;
for value2 = 0 to value3 begin
last_idx += 1;
array_setmaxindex(equty_per_bar, last_idx);
equty_per_bar[last_idx] = PosTradeProfit(value1, value2);
//print( "trade [", maxpositionsago - value1, ",", value2, "] = ", equty_per_bar[last_idx]);
end;
end;
EquityCurveStdDev = StandardDevArray( equty_per_bar, last_idx, 0 );
// if 0=getappinfo(aioptimizing) then print( "EquityCurveStdDev = ", EquityCurveStdDev );
end;
Or StandardDevArray

Code: Select all

inputs:
PriceValueArray[MaxSize]( numericarray ),
Size( numericsimple ),
DataType( numericsimple ) ;



Value1 = VarianceArray( PriceValueArray, Size, DataType ) ;
if Value1 > 0 then
StandardDevArray = SquareRoot( Value1 )
else
StandardDevArray = 0 ;

Thanks in advance.


Return to “User Contributed Studies and Indicator Library”