Gamestudio Links
Zorro Links
Newest Posts
Deformers struct in MDL7 abspeichern.
by tagimbul
Today at 02:06
Votes for future features
by Hredot
Today at 01:48
What happens with particles, Memory wise?
by jumpman
Today at 00:41
Plotting on hour time scale
by Hredot
Yesterday at 17:42
Fetter ACSII Parser
by MasterQ32
Yesterday at 14:31
AUM Magazine
Latest Screens
RPG PARTY
Triton Wing now available on Steam
AckCon'17: Lotter vs The World
Triton Wing
ZeaL
Who's Online
7 registered (Dalla, AndrewAMD, firecrest, jyd, tagimbul, johnnyp, jrath), 444 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
CaptainPablo, blAx, BBX, jcadihere, Peeyotch
17759 Registered Users
Topic Options
Rate This Topic
#467685 - 08/21/17 19:14 Optimizing equity curve trading
brax Offline
Newbie

Registered: 08/02/17
Posts: 20
Hi,

I am trying to optimize the lowpass filter in equity curve trading for a basket of assets. It seems the optimization is not being performed, surely there is some kind of issue with Balance or ProfitClosed behaviour. This is my code:

Code:
static var opt_Filtered;
static var opt_Signal;
static var opt_Threshold;
static var opt_Stop_Cntr;
static int opt_EquityAvg;

var equityCurveSizing()
{
  if(Train) { return 1; } // no phantom trades in training mode
  vars EquityCurve = series(BalanceLong+BalanceShort);
//  vars EquityLP = series(LowPass(EquityCurve,10));
  vars EquityLP = EquityCurve;
  if(EquityLP[0] < LowPass(EquityLP,opt_EquityAvg))// && falling(EquityLP))
    return -1; // drawdown -> phantom trading
  else
    return 1; // profitable -> normal trading
}
	
function tradeCounterTrend()
{
	vars Price = series(priceClose());
	vars Filtered = series(BandPass(Price,opt_Filtered,0.5));
	vars Signal = series(Fisher(Filtered,opt_Signal));
	var Threshold = opt_Threshold;
	
	Stop = opt_Stop_Cntr * ATR(10);
	Trail = 4*ATR(10);
	
	if(crossUnder(Signal,-Threshold))
		enterLong(); 
	else if(crossOver(Signal,Threshold)) 
		enterShort();
}

function run()
{
	set(LOGFILE+PARAMETERS);
        NumCores = -2;
	BarPeriod = 24*60;
	LookBack = 500;
	StartDate = 2005;
	EndDate = 2015;
	Capital = 10000;
	
	if(ReTrain) {
		UpdateDays = -1;
		SelectWFO = -1;	
		reset(FACTORS);	
	}

	while(asset(loop("EUR/USD","USD/JPY","GBP/USD","USD/CHF"))){
        
        // Parameters	
	opt_Filtered = optimize(30,20,40,1);
	opt_Signal = optimize(10,5,20,1);
	opt_Threshold = optimize(1,0.5,1.5,0.1);
	opt_Stop_Cntr = optimize(4,2,10,1); 
        opt_EquityAvg = optimize(100,5,200,5);

        Lots = 5;
        Lots = equityCurveSizing() * Lots;
	tradeCounterTrend();	
	}
			
	PlotWidth = 1024;
	PlotHeight1 = 400;
}



ŋThe behaviour of equity curve trading is for the global equity produced from all the assets or itīs applied on every asset equity?

If globally, ŋCould i store the different asset equities and apply it separately with a function that receives that equity?.

Thanks.

Top
#467939 - 09/08/17 22:00 Re: Optimizing equity curve trading [Re: brax]
brax Offline
Newbie

Registered: 08/02/17
Posts: 20
Well, after some research i can answer myself some questions:

First, equity curve trading as explained in the manual is only for global equity produced by all trades from all assets. If you want to individualize it, you must do some workarounds.

Second, i havenīt realized how to optimize the parameter for the average, but it doesnīt matter.

Finally, i have found a mechanism i think is better than doing it with averages. It consists of applying the kelly factor for every asset on every trade close, this way i donīt need any parameters at all and it serves the purpose of avoiding broken systems to be traded.

The only problem is that most times it hinders performance but seems to be a good contingency plan.

More about this can be found here:
http://www.financemagnates.com/forex/bloggers/equity-curve-trading-part-2-rolling-expectancy-ratio/

In my case, as i donīt want to add more parameters iīve used all data to implement it. Hope it is useful for everybody.


Edited by brax (09/08/17 22:01)

Top
#467949 - 09/09/17 18:59 Re: Optimizing equity curve trading [Re: brax]
MatPed Offline
Senior Member

Registered: 02/28/15
Posts: 362
Loc: Milano, Italy
Well, I do not think that what you stated is correct. I do check equity curve for each Algo/Asset Combination.
Just call the checkEquity() function in each Algo script before opening the trade and the job is done.
In order to size the trade I use the Margin not LOTS in order to evoid conflicts between sizing the trade and equity line check.

My 2 cents. Ciao

Top
#467956 - 09/10/17 22:24 Re: Optimizing equity curve trading [Re: MatPed]
brax Offline
Newbie

Registered: 08/02/17
Posts: 20
Hi MatPed.

Surely you are right, iīve always avoided to place optimize statements directly in algo scripts, as i tend to do it at a global level. Probably thatīs the reason why i couldnīt optimize the average...

Iīve used lots instead of Margin just for simplicity, but itīs good to know that could be another reason why i couldnīt optimize equity curve trading properly.

Anyway, i see a problem with doing it with averages, this is because we add more parameters to the equation, so we unintentionally increase curve fitting.

You can check the first part of the article and see what i mean, i think applying expectancy or kelly factor over the whole data is a good way of avoiding disasters without adding parameters nor bias. The rolling versions work in a similar way like doing it with averages.

There is people who even just stop trading when they reach MDD95 from Montecarlo.

Thanks.

Top



Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs | beta features

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net