PureBytes Links
Trading Reference Links
|
Hmmmm. Looks like Tony is right. I tried running this with some
traces. AmiBroker executes your code twice prior to the start of the
optimize loop. If you try the code below, you will see this trace:
a=1, FastMALength=5, actionEx=actionExEditVerifyFormula
a=5, FastMALength=1, actionEx=actionExOptimizeSetup
a=1, FastMALength=5, actionEx=actionExOptimizeBacktest
a=2, FastMALength=1, actionEx=actionExOptimizeBacktest
a=3, FastMALength=2, actionEx=actionExOptimizeBacktest
a=4, FastMALength=3, actionEx=actionExOptimizeBacktest
a=5, FastMALength=4, actionEx=actionExOptimizeBacktest
You can see the actionExOptimizeSetup pass is writing 5 to the file.
Each optimize pass is picking up the value written by the previous pass.
Here is the modified code:
a = Optimize( "a", 1, 1, 5, 1 );
#pragma nocache
#include "c:\TestAFL.afl";
fh = fopen( "c:\\TestAFL.afl", "w");
fputs("FastMALength = ", fh);
fputs(NumToStr(a, 1.0, 0 ),fh);
fclose( fh );
actionExNum = Status("ActionEx");
if (actionExNum == actionExEditVerifyFormula) actionExName =
"actionExEditVerifyFormula";
else if (actionExNum == actionExOptimizeSetup) actionExName =
"actionExOptimizeSetup ";
else if (actionExNum == actionExOptimizeBacktest) actionExName =
"actionExOptimizeBacktest ";
else if (actionExNum == actionExOptimizePortfolio) actionExName =
"actionExOptimizePortfolio";
_Trace("a="+a + ", FastMALength="+FastMALength + ",
actionEx="+actionExName);
SlowMALength = 20;
FastMA = MA( C, FastMALength );
SlowMA = MA( C, SlowMALength );
Buy = Cross( FastMA, SlowMA );
Sell = Cross( SlowMA, FastMA );
--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Yes. But I am not sure how that creates the problem I am seeing.
> Because when TestAFL.afl is processed, say for a =1, it simply results
> in the following statement first being placed into memory:
>
> FastMALength = 1;
>
> then the main AFL is processed, and this should result in the
> crossover trade being processed with the above variable assignment.
> But instead of the above variable assignment, it instead is:
>
> FastMALength = 5;
>
> How and why does it skip from 1 to 5?
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Tony Grimes" <Tonez.Email@> wrote:
> >
> > *#include is a preprocessor command. The included file, in this case
> > TestAFL.afl, will be processed before your trade system 2 afl is
> processed.*
> >
> > On Sat, Dec 13, 2008 at 5:59 PM, ozzyapeman <zoopfree@> wrote:
> >
> > > Hello, hoping someone can help with this issue. When I use an
> optimize
> > > statement with #include and fputs, the optimization variable keeps
> getting
> > > shifted.
> > >
> > > For example, please consider the two basic MA crossover systems
> below. They
> > > should both give identical results whether one does a backtest or an
> > > optimization. The backtests do appear identical. However, the
Include
> > > version gives wonky results in optimization. Instead of 'a'
> starting at
> > > value 1. It starts at 5 but says in the optimization report that
> it is 1. I
> > > know it's probably something simple that I am overlooking, but
> can't seem to
> > > figure this one out:
> > >
> > >
> > >
>
//------------------------------------------------------------------------
> > > // TRADE SYSTEM #1: SIMPLE CROSS BASIC
> > >
>
//------------------------------------------------------------------------
> > >
> > > FastMALength = Optimize("FastMALength", 1, 1, 5, 1);
> > >
> > > SlowMALength = 20;
> > >
> > > FastMA = MA( *C*, FastMALength );
> > > SlowMA = MA( *C*, SlowMALength );
> > > *Buy* = Cross( FastMA, SlowMA );
> > > *Sell* = Cross( SlowMA, FastMA );
> > >
> > >
> > >
> > >
> > >
>
//------------------------------------------------------------------------
> > > // TRADE SYSTEM #2: SIMPLE CROSS USING INCLUDE AND FPUTS
> > >
>
//------------------------------------------------------------------------
> > >
> > > a = Optimize( "a", 1, 1, 5, 1 );
> > >
> > > *#pragma* nocache
> > > *#include* "c:\\TestAFL.afl";
> > >
> > > fh = fopen( "c:\\TestAFL.afl", "w");
> > > fputs("FastMALength = ", fh);
> > > fputs(NumToStr(a, 1.0, 0 ),fh);
> > > fclose( fh );
> > >
> > > SlowMALength = 20;
> > >
> > > FastMA = MA( *C*, FastMALength );
> > > SlowMA = MA( *C*, SlowMALength );
> > > *Buy* = Cross( FastMA, SlowMA );
> > > *Sell* = Cross( SlowMA, FastMA );
> > >
> > >
> >
>
------------------------------------
**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
*********************************
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|