PureBytes Links
Trading Reference Links
|
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@xxx> 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/
|