[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Optimization Help



PureBytes Links

Trading Reference Links

Thanks for the replies.  Tomasz, I tried to understand what you're 
saying and I looked at the gif you posted...and I think I get how 
trades are executed in regards to the backtests, but I'm still 
confused about the optimization thing.

First, let me repeat what I'm trying to get out of the optimization 
just to make sure I understand what it's supposed to do:  I want it 
to tell me that the 3-bar MA crossing the x-bar MA (MA1) to buy, and 
the 3-bar MA crossing the x-bar MA (MA2) to sell, yields the best 
profit for the time period tested.  IOW, I want to know which 
COMBINATION of MA1 and MA2 was most profitable.

Another example of the optimization results:

Net % Profit   MA   MA
------------  ---- ----
10.06          29   52
10.06          29  132
10.06          29   72

In fact, ALL 195 lines containing a MA of 29 in the first column 
have identical results.  (I assume that the first column is MA1, the 
MA to buy.)  It still makes zero sense to me that the results would 
all be the same when the MA to SELL is ranging from 5 to 200.  How 
can you have the same profits when you're exiting the trades 
at different times??? In fact, when I run individual backtests on 
these same combinations of MAs, I get different results:

MA1   MA2   Profit %
---  ----   --------
29    52     10.01
29   132      9.02
29    72      9.64

So why would the backtests have different results than the 
optimization?  I still say I must be misunderstanding something 
about the optimization or doing something wrong.  Anyone care to take 
another shot at explaining this to me?

Thanks again for your patience.






--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> 
wrote:
>
> Hello,
> 
> For starters: there is not big difference if you choose Cross vs > 
function.
> 
> Cross checks essentially '<=' condition on previous bar and '>' on 
current bar.
> 
> The results would be the same (with the possible exception of very 
first
> trade that > will give you at the beginning of backtest) because
> under normal circumstances you are allowed to hold only ONE open
> position for one symbol. So it does not matter if you have 
repetitive signals
> - they will be simply ignored until matching sell occurs, see this 
how it works:
> 
> http://www.amibroker.com/gifs/bt_regular.gif
> 
> As to your question regarding optimization, your results do not 
change
> when second (MA2) changes because your ENTRY rule does not depend 
on
> MA2. Only MA1 is used in "Buy" rule and it decides which trades 
are 
taken or not.
> MA2 is used ONLY for exits and because of small averaging period 
exits
> occur right after entry so it does not modify your results, and 
they in fact
> depend solely on entry strategy.
> 
> You should really run Scan, to find out when all signals occur to 
learn
> the way signals are converted to trades.
> And again this:
> http://www.amibroker.com/gifs/bt_regular.gif
> 
> is worth studying. It shows "Regular backtest".
> 
> There are 3 other backtest modes available (RegularRaw, 
RegularRawMulti and rotational)
> but I would suggest to start with the regular first.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "longarm61" <norm1@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Monday, August 20, 2007 5:13 AM
> Subject: [amibroker] Re: Optimization Help
> 
> 
> > Hey, Steve, thanks for the reply.  That's interesting because I 
used 
> > the AFL Wizard for my buy and sell code.  Wonder why it would 
give me 
> > code that generates a buy for every bar that remains above the 
MA?  
> > It's also interesting that for a 1-month backtest using 5-minute 
> > bars, my original code yielded only 1 more trade (line) than 
your 
> > code did.  
> > 
> > But the thing I'd really like help understanding is the 
> > Optimization.  I tried it using your code and I'm still confused 
by 
> > the results.  For example, it shows:
> > 
> > NET % PROFIT   MA   MA
> > ------------  ---- ----
> > 3.28           133   5
> > 3.28           133  15
> > 3.28           133   8  
> > 3.28           133   9
> > 
> > As you can see, it shows the same net % profit for every result 
with 
> > a MA of 133, even though the MAs in the second column are all 
> > different.  In fact, ALL the numbers in all the columns are 
> > indentical for the MA-133. Why would that be?  Doesn't the first 
MA  
> > above represent MA1 and the second MA represent MA2?
> > 
> > Either I'm still doing something wrong or I'm misunderstanding 
> > something (very possible!), since obviously trades with 
different 
MAs 
> > for sells aren't going to have the exact same results, even if 
buys 
> > use the same MA.
> > 
> > Looking for enlightenment.  Thanks.
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" <sjdugas@> wrote:
> >>
> >> Hi, your code gives buy sig not just on crossover but also on 
every 
> > bar 
> >> where MA3 remains above the MA it just crossed. Similar result 
for 
> > sell 
> >> sigs. Try it this way...
> >> 
> >> Buy = Cross( MA( Close , 3 ), MA( Close , MA1 ) );
> >> Sell = Cross( MA( Close , MA2 ), MA( Close , 3 ) );
> >> 
> >> Steve
> >> 
> >> ----- Original Message ----- 
> >> From: "longarm61" <norm1@>
> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> Sent: Sunday, August 19, 2007 6:09 PM
> >> Subject: [amibroker] Optimization Help
> >> 
> >> 
> >> > Hello, complete AFL newbie here.  This should be a simple 
one.  
> > If I
> >> > have a system whereby a 3-bar MA crosses another MA to buy, 
and a 
> > 3-
> >> > bar MA crosses a different MA to sell, how would I code the
> >> > optimization to find the most profitable COMBINATION of MAs 
for 
> > the
> >> > buy and sell?
> >> >
> >> > Here's how I attempted to do it--I know it's wrong, as it 
crunched
> >> > numbers for about 2 hours but then gave me results that made 
no 
> > sense:
> >> >
> >> >
> >> > MA1 = Optimize ( "MA", 50, 5, 200, 1 );
> >> > MA2 = Optimize ( "MA", 50, 5, 200, 1 );
> >> >
> >> > Buy = MA( Close , 3 )  >  MA( Close , MA1 );
> >> >
> >> > Sell = MA( Close , 3 )  <  MA( Close , MA2 );
> >> >
> >> > Short = 0;
> >> >
> >> > Cover = 0;
> >> >
> >> >
> >> > Thanks in advance for your patience and help.
> >> >
> >> >
> >> >
> >> > Please note that this group is for discussion between users 
only.
> >> >
> >> > To get 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
> >> >
> >> >
> >> >
> >> >
> >>
> > 
> > 
> > 
> > 
> > Please note that this group is for discussion between users only.
> > 
> > To get 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
> > 
> > 
> > 
> > 
> >
>




Please note that this group is for discussion between users only.

To get 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/