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

[amibroker] Re: How to write a backtest when foreign symbol gives signal



PureBytes Links

Trading Reference Links

You haven't indicated where you got 'E' from.

If you used the Equity function, you need to be aware that that 
function calculates the equity based on the buy/sell of the current 
symbol only, not of all symbols in your portfolio working in unison. 
As such it will not tell you when total system equity has moved.

To access the equity of the total system, you can use Foreign to 
reference the ~~~Equity symbol. However, you are running into a 
chicken and egg scenario.  ~~~Equity cannot be calculated until 
Buy/Sell/Short/Cover have been calculated. Yet, you are trying to use 
~~~Equity in those calculations. I don't believe that this is 
possible.

What is possible, however, is to refer to the equity property of the 
backtester object in custom backtest logic ( 
http://www.amibroker.com/guide/a_custombacktest.html ). You could 
then compare the equity, on a bar by bar basis, to the previous bar 
and create sell signals for all open positions when the drawdown 
exceeds your comfort zone.

Refer to the document titled "AmiBroker Custom Backtester 
Interface.pdf" in the Files section of this group for a description 
of how the custom backtester works: 

http://f1.grp.yahoofs.com/v1/wH6WSKSJ4f9R8ibQ_d0OnmKrWP-
dE8XBB_Y9AyoYX1Rno2FiNVaCCe_ySoPd7e8wWuFwNkGEcHK0TvuXj-KVdJhy3z8AAn-
K/AmiBroker%20Custom%20Backtester%20Interface.pdf

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "john10987654321" 
<john10987654321@xxx> wrote:
>
> Thank you very much. I will try this. 
> 
> I also want to be able to sell everything if the system's drawdown 
is
> more than, say, 10 percent. I have written a variable:
> 
> //Your Current Drawdown:
> Draw = (Highest(E) / E);
> 
> and have included it in my sell signals:
> 
> Sell= ... OR Draw <= .90;
> 
> But it is not working. What am I doing wrong? Any help appreciated.
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> > Hi,
> > 
> > I think that you are asking for something like the following:
> > 
> > SetForeign("VGY");
> > LastWeekClose = Ref(Close, -5);
> > Bull = Cross(Close, LastWeekClose * 1.04);
> > Bear = Cross(LastWeekClose * 0.96, Close);
> > BullBarsAgo = BarsSince(Bull);
> > BearBarsAgo = BarsSince(Bear);
> > RestorePriceArrays();
> > 
> > Buy = ... AND BullBarsAgo < BearBarsAgo; // No bear since last 
bull.
> > Sell = ... OR Bear; // Normal sell or start of bear.
> > 
> > Mike
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "john10987654321"
> > <john10987654321@> wrote:
> > >
> > > Thank you for your reply. My request is a little more 
complicated.
> > > Your suggestion would presume that I want to buy if the foreign 
symbol
> > > rises 1.04 *today.* I want to buy on any day after the symbol 
hits
> > > 1.04. Say the VGY gives a buy signal today by rising 4% since 5 
days
> > > ago. The next day it's only 1.02. That doesn't matter. I can 
keep
> > > buying stocks for days, weeks or months until I get a sell 
signal. I
> > > want to be able to buy on any day until I get a sell signal and 
then I
> > > do not want to buy on any day until I get a buy signal. That is 
why I
> > > was trying to write to a file BULL or BEAR. That file would 
only be
> > > written if I get a signal and then referred to on subsequent 
days
> > > until the signal changes. Am I making sense?
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > > >
> > > > Hi,
> > > > 
> > > > There's no need to do looping here. Since Change now holds a 
bar by 
> > > > bar ratio, you may just refer to it directly.
> > > > 
> > > > Also, there's no need to write to any external file. Just
> include the 
> > > > condition in your buy logic using the AND operator and in 
your sell 
> > > > logic using the OR operator.
> > > > 
> > > > Try something like this:
> > > > 
> > > > SetForeign("VGY");
> > > > Change = C/Ref(C, -5);
> > > > RestorePriceArrays();
> > > > 
> > > > Buy = ... AND Change >= 1.04; // Confirm buy signal with Bull
> > > > Sell = ... OR Change <= 0.96; // Regular sell or Bear
> > > > 
> > > > Mike
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "john10987654321" 
> > > > <john10987654321@> wrote:
> > > > >
> > > > > Hello, I have used Amibroker for a long time but am only
> beginning 
> > > > to
> > > > > write complex formulas. First let me explain what I want to
> do, then
> > > > > show you what I've done and then ask for advice on how to 
proceed.
> > > > > 
> > > > > In my backtest, I want to buy stocks using my long-only 
strategy 
> > > > when
> > > > > the Value Line Index (symbol VGY) has given a buy signal by
> rising 
> > > > 4%
> > > > > or more in the past five days. I want to sell all stocks in 
my
> > > > > backtest when the VGY has dropped 4% or more in the past 
five
> days. 
> > > > I
> > > > > will follow my normal sell signals with individual stocks if
> the VGY
> > > > > is still in a buy signal.
> > > > > 
> > > > > To accomplish this, I thought I would, for each day of my
> backtest,
> > > > > check the VGY, and if on that day, it rose 4% or more from 
5 days
> > > > > previous, write to a file called sig.txt "BULL". If the VGY
> did not
> > > > > rise 4%, I would write nothing. If the VGY dropped 4% from 
5 days
> > > > > previous, I would write to the same sig.txt file "BEAR". So
> nothing
> > > > > would be written if there were no signal. I was then going 
to
> figure
> > > > > out a way to read from sig.txt for each day of my backtest, 
and 
> > > > follow
> > > > > the most-recently written signal, BEAR or BULL.
> > > > > 
> > > > > I have partially written this code. I can get it to write 
to a
> file,
> > > > > but it will only write BEAR. I thought that by setting 
backtest 
> > > > dates
> > > > > in Automatic Analysis, that this would run for each day. 
But the
> > > > > reason it is only writing BEAR today, I believe is it is 
only 
> > > > checking
> > > > > for today. 
> > > > > 
> > > > > That led me to functions and for loops, etc. and I am at a 
point 
> > > > where
> > > > > I am in need of direction. So far, I have been learning 
alot about
> > > > > FOREIGN, LastValue, fopen, etc. Here's the code I've done 
thus
> far:
> > > > > 
> > > > > VgyToday = Foreign("VGY", "Close");
> > > > > VgyLastWeek = Ref(Foreign("VGY","Close"),-5);
> > > > > Change = (VgyToday / VgyLastWeek);
> > > > > 
> > > > > if ( LastValue(Change[0], lastmode = True )  <= .96 )
> > > > > {
> > > > >                fh = fopen( "c:\\tmp\\sig.txt", "w");
> > > > >                if( fh )
> > > > >                {
> > > > >                        fputs( "BEAR", fh );
> > > > >                        fclose( fh );
> > > > >                }
> > > > > }
> > > > > else
> > > > > {
> > > > >        printf ("No\n");
> > > > > }
> > > > > 
> > > > > 
> > > > > if ( LastValue(Change[0], lastmode = True )  >= 1.04 )
> > > > > {
> > > > >                fh = fopen( "c:\\tmp\\sig.txt", "w");
> > > > >                if( fh )
> > > > >                {
> > > > >                         fputs( "BULL", fh );
> > > > >                         fclose( fh );
> > > > >                }
> > > > > }
> > > > > else
> > > > > {
> > > > >        printf ("No\n");
> > > > > }
> > > > > 
> > > > > Any guidance much appreciated.
> > > > >
> > > >
> > >
> >
>



------------------------------------

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/