Following is the code I am using.
-------------------
function run()
{
set(PARAMETERS);
StartDate = 20080101;
EndDate = 20131231;
//BarPeriod = optimize(15,5,20,1); //after optimize, value for BarPeriod is 18
//Test shows annual loss of -219p
BarPeriod = 18; //Test without any optimization, test shows +257p
LookBack = 100*5;
vars Price = series(price());
vars Trend = series(LowPass(Price,1000));
if(valley(Trend))
enterLong();
else if(peak(Trend))
enterShort();
}
-------------------
Following are steps for testing it
1) Executed the script in Train mode and found the value for BarPeriod is 18 stored in abc_EURUSD.par file
2) Ran Test, results showed annual loss of -219p
3) Commented the line to optimize BarPeriod, and hard-coded BarPeriod = 18, and saved the file
4) Removed abc_EURUSD.par from Data directory
5) Ran Test, results showed annual profit of +257p
I am confused why the results are different when I used the value provided by optimize function. Any thoughts ?.