Page 1 of 1

Optimization By linear Equity Curve

Posted: 18 Jan 2013
by Dru
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

Re: Optimization By linear Equity Curve

Posted: 18 Jan 2013
by furytrader
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?

Re: Optimization By linear Equity Curve

Posted: 19 Jan 2013
by Dru
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

Re: Optimization By linear Equity Curve

Posted: 20 Jan 2013
by SUPER
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

Re: Optimization By linear Equity Curve

Posted: 21 Jan 2013
by Dru
I am using MC 8.0 and get same error message?
It will work only in MC 8.5 beta 2 and future versions.

Re: Optimization By linear Equity Curve

Posted: 23 Jan 2013
by swz168
Awesome! Thanks a lot, Dru!

Re: Optimization By linear Equity Curve

Posted: 05 Mar 2013
by Gaempi
Thank you, Dru! Great work!

Re: Optimization By linear Equity Curve

Posted: 06 Mar 2013
by StefanoSF
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.

Re: Optimization By linear Equity Curve

Posted: 07 Mar 2013
by Dru
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.

Re: Optimization By linear Equity Curve

Posted: 15 Mar 2013
by MeiHua
Thanks for the code.

Are we optimizing by ascending or descending?

Re: Optimization By linear Equity Curve

Posted: 24 Jun 2014
by Ming80
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

Re: Optimization By linear Equity Curve

Posted: 14 Sep 2014
by lianhc
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.

Re: Optimization By linear Equity Curve

Posted: 29 Sep 2014
by shanemcdonald
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

Re: Optimization By linear Equity Curve

Posted: 30 Sep 2014
by Henry MultiŠ”harts
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.

Re: Optimization By linear Equity Curve

Posted: 18 May 2015
by shane1800
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.