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: Aug 28 2007
Has thanked: 4 times
Been thanked: 171 times

Jan 18 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 1820 times
optimize by net profit & equity std dev.pla
(4.02 KiB) Downloaded 1637 times
Last edited by Dru on Jan 19 2013, edited 1 time in total.

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

Jan 18 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: Aug 28 2007
Has thanked: 4 times
Been thanked: 171 times

Jan 19 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: 647
Joined: Mar 03 2007
Has thanked: 106 times
Been thanked: 85 times

Jan 20 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: Aug 28 2007
Has thanked: 4 times
Been thanked: 171 times

Jan 21 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: Sep 30 2010
Location: Germany
Has thanked: 47 times
Been thanked: 32 times

Jan 23 2013

Awesome! Thanks a lot, Dru!

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

Mar 05 2013

Thank you, Dru! Great work!

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

Mar 06 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: Aug 28 2007
Has thanked: 4 times
Been thanked: 171 times

Mar 07 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: Aug 12 2012
Has thanked: 1 time

Mar 15 2013

Thanks for the code.

Are we optimizing by ascending or descending?

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

Jun 24 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: Sep 11 2014

Sep 14 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: Aug 08 2012
Has thanked: 41 times
Been thanked: 41 times

Sep 29 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: Aug 25 2011
Has thanked: 1264 times
Been thanked: 2958 times

Sep 30 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: Feb 28 2014
Has thanked: 5 times
Been thanked: 5 times

May 18 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.