I'm trying to setup to run an optimization, but can't get the OC modified code to compile. I've attempted to follow the steps in the User Manual under Optimization Control. I first open the optimization window and set it up with a single parameter called Parameter 1. It adds the following code to the top of my program:
CODE:
Please log in to see this code.
However, when I attempt to compile I get the following error messages:
QUOTE:
errorCS0116 @ (2,3): A namespace cannot directly contain members such as fields or methods
errorCS0116 @ (4,10): Expected class, delegate, enum, interface, or struct
where lines 2 and 4 refer to StrategyParameter and public MyStrategy(), respectively. Also I'm not sure how to modify my code. My first attempt is to create the following 2 lines:
CODE:
Please log in to see this code.
Any hints on how to proceed would be appreciated.
Size:
Color:
The Optimizer won't be adding that code to the top of your strategy, resulting in these compiler errors. It would have done it in the proper places w/o producing any error messages. Show us how the complete code looked before your attempt to insert the parameter, and we'll help modify it correctly.
Size:
Color:
Here is the complete code. My primary symbol is .SPX.
CODE:
Please log in to see this code.
As an aside, when the code is run on symbol .SPX, the Trades tab shows that symbol BND is entered and exited on the same day (4/11/2007) which as near as I can tell is not the case?
Size:
Color:
I'm taking my words back. Actually, the Optimizer has a problem like you described when a Strategy class was not defined as
public. You modified some old Strategy out of a dozen publicly available or built-in strategies that had this peculiarity.
To fix, simply change this:
CODE:
Please log in to see this code.
This way:
CODE:
Please log in to see this code.
Size:
Color:
Thanks Eugene. That fixed it.
Size:
Color:
I've now run into a problem. I'm using 3 optimization parameters. The code segment introduced appears as follows in which you can see the commented out variables as they existed prior to optimization:
CODE:
Please log in to see this code.
Now it runs fine when optimizing, but generates an error when run without optimization.
QUOTE:
Runtime error: bar number must be 3 or greater
I would have thought that it should continue to work when run without optimization perhaps using the default values which worked fine before running optimization?
Size:
Color:
QUOTE:
Now it runs fine when optimizing, but generates an error when run without optimization.
To reproduce, tell us the following: the symbols in the DataSet, bar scale, loaded data range, data provider, position sizing used.
Size:
Color:
Thanks Eugene. I've made numerous changes and the results are intermittent. Sometimes it runs and sometimes it generates the runtime error. Here is the info you requested:
primary symbol .SPX
stksym VTI
bndsym BND
executed bar scale: 20 - 1820
loaded data range: 4/1/2007-6/24/2014
data provider: not sure; just created a data set and added the above symbols
position sizing: Portfolio Simulation Mode / 9.95% equity
Size:
Color:
It's the default value.
Be careful: selecting "Save Parameters" in the Strategy Parameters box will override the default value in the Editor with the saved setting for that strategy. (To set a new default parameter value, change a slider and Save.)
Size:
Color:
Thanks. I found a nasty bug in which I was using startbar instead of bar in the call to SellAtClose which caused the runtime error. It was intermittent since it only occurred when I had a Buy bond/Sell stock signal.
Size:
Color: