Can you please help me figure out what's wrong with this. As a n00b, I'm trying to understand the major pitfalls that can lead to this type of too-optimistic result.

Code:
Walk-Forward Test: Workshop6_2_dusktrader portfolio 2002..2013
Read Workshop6_2_dusktrader.fac Workshop6_2_dusktrader_1.par Workshop6_2_dusktrader_2.par Workshop6_2_dusktrader_3.par Workshop6_2_dusktrader_4.par Workshop6_2_dusktrader_5.par Workshop6_2_dusktrader_6.par Workshop6_2_dusktrader_7.par
Profit 2141744$  MI 28546$  DD 1$  Capital 9180$
Trades 1241  Win 61%  Avg +173291.9p  Bars 761
AR 685102%  PF 539.68  SR 11.16  UI 0.1%  Error 22%
Generate Chart - please wait... ok



In studying Workshop 6_2, I decided to make a few changes. First, I didn't like the idea that the margin calculation was being lumped together for all the trade types, because they weren't all profitable. Also, I wanted to improve overall robustness by adding all the other pairs available to me.

So I (attempted to make) these changes:
* Only trade if OptimalF result was positive
* Don't trade any margin for now (that skews results)
* Test all available pairs, as much history as possible, in NFA mode

Questions I have now:
* Is it possible/correct for some pairs to have an OptimalF value of .999? That happens if I test over a shorter period.
* Is it possible/correct for some pairs to have such high profit factors as shown here?
* Is it true that when history data is not available, that there would be no negative effect on the backtest? For example, I requested backtesting to 2002, but some pairs do not have that much history. My assumption is that it will just skip those pairs if no data available.

THANKS

Code:
// Workshop 6: Portfolio trading ///////////////////

function tradeTrend()
{
	vars Price = series(price());
	vars Trend = series(LowPass(Price,optimize(250,100,1000)));

	Stop = optimize(4,2,8) * ATR(100);
	Trail = 0; 
	if(valley(Trend) && OptimalFLong > 0) //long setup, known profitable
	{
		// reinvest the square root of profits
		var MarginLong = sqrt(WinLong-LossLong)*OptimalFLong;
		Margin = clamp(MarginLong, 5, 100); //max $1000 per trade

		enterLong();
	}
	
	else if(peak(Trend) && OptimalFShort > 0) //short setup, known profitable
	{
		// reinvest the square root of profits
		var MarginShort = sqrt(WinShort-LossShort)*OptimalFShort;
		Margin = clamp(MarginShort, 5, 100); //max $1000 per trade

		enterShort();
	}
}

function tradeCounterTrend()
{
	vars Price = series(price());
	vars DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	vars HP = series(HighPass(Price,LowPeriod*optimize(1,0.5,2)));
	vars Signal = series(Fisher(HP,500));
	var Threshold = optimize(1,0.5,2,0.1);
	
	Stop = optimize(4,2,8) * ATR(100);
	Trail = 4*ATR(100);
	if(crossUnder(Signal,-Threshold) && OptimalFLong > 0) //long setup, known profitable
	{ 
		// reinvest the square root of profits
		var MarginLong = sqrt(WinLong-LossLong)*OptimalFLong;
		Margin = clamp(MarginLong, 5, 100); //max $1000 per trade

		enterLong(); 
	}
	else if(crossOver(Signal,Threshold) && OptimalFShort > 0) //short setup, known profitable
	{
		// reinvest the square root of profits
		var MarginShort = sqrt(WinShort-LossShort)*OptimalFShort;
		Margin = clamp(MarginShort, 5, 100); //max $1000 per trade

		enterShort();
	}
}


function run()
{
	set(PARAMETERS+FACTORS+NFA);  // generate and use optimized parameters
	BarPeriod = 240;	// 4 hour bars
	StartDate = 2002;
	LookBack = 500;	// needed for Fisher()
	NumWFOCycles = 8; // activate WFO

	//if(ReTrain) {
	//	UpdateDays = -1;	// update price data from the server 
	//	SelectWFO = -1;	// select the last cycle for re-optimization
	//}
	
// portfolio loop
	while(asset(loop("EURUSD","USDJPY","AUDUSD","EURCHF","GBPUSD","NZDUSD","USDCAD","USDCHF")))
	while(algo(loop("TRND","CNTR")))
	{
// initiate trade if known profitable track record
		if(OptimalFLong > 0 or OptimalFShort > 0) 
		{
			if(strstr(Algo,"TRND")) 
				tradeTrend();
			else if(strstr(Algo,"CNTR")) 
				tradeCounterTrend();
		}
	}
	
	PlotWidth = 800;
	PlotHeight1 = 320;
}



EDIT: I made some improvements to the script by allowing it to set margin as the square root of equity gain (I think I did this right), clamping trades to $1000 max margin. I updated the script and stats above.

Attached Files Workshop6_2_dusktrader_NZDUSD.png
Last edited by dusktrader; 07/22/13 15:57.