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

[amibroker] Re: Not sure how to create a trigger



PureBytes Links

Trading Reference Links

Hi,

The code published will do as you requested. However, you need to 
understand how AmiBroker works. AmiBroker works accross entire arrays 
simultaneously, not just incrementally bar by bar in loops.

As such, you do not need to do two passes. Instead, you just express 
each trigger as an array, then use logical operators to join the 
results.

See the user guide for a detailed description of the inner workings:

http://www.amibroker.com/guide/h_understandafl.html

Then read the description of each of the functions used in Graham's 
post to understand the pieces involved:

http://www.amibroker.com/guide/afl/afl_index.php?m=1

What he has done is to say that a buy should occur when the 5 day 
moving average of the close (MA5) has crossed above the 10 day moving 
average of the close (MA10) as expressed by:

  Cross( MA5, MA10 )

But, only (i.e. AND) if the lowest 14 day RSI (RSI(14)), *since* the 
MA5 last dropped below the MA10, is under 30, as expressed by:

  LowsetSince( Cross( MA10, MA5 ),  RSI(14) ) < 30

What Graham has done was further quantify the under 30 restriction. I 
had suggested that just looking for whether RSI was ever under 30 was 
probably not going to be useful, and had arbitrarily suggested 
checking that it had occured within the last 20 days.

Graham refined that by saying that you could check that it fell below 
30 any time since the MA5 first dipped below the MA10 now that it is 
crossing above the MA10.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "tridean34" <tridean34@xxx> wrote:
>
> Hi Guys,
> Many thanks for your replies.
> 
> I guess where I was looking was in the wrong spot.
> 
> I has assumed that you could create a system in AFL for the purpose 
> of baktesting that would scan from day one looking for an event, 
like 
> oversold condition on an indicator - ie RSI < 30.
> 
> Once this 1st event occurred then it would look for a second event. 
> Like a loop where the system doesn't even know of the second event 
> until it has found the first one.
> 
> Once event 1, and then event 2 takes place, a trade is made. When 
the 
> trade finally ends at some exit event, the system goes back to the 
> start again looking for event 1 (RSI < 30) from the day after the 
> last trade was exited.
> 
> in other words the trade itself is not dependant on event 1, only 
> event 2, but event 2 IS dependant on event 1 occuring
> 
> Are what you all suggesting going to do this?
> 
> Many thanks
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> > Graham,
> > 
> > Nicely done. My post would have been better had it 
> > suggested "...within some predefined period OR since some 
> meaningful 
> > event". You captured that perfectly with your code suggestion.
> > 
> > Mike
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@> wrote:
> > >
> > > try this, assuming interpretation of your description is correct
> > > 
> > > MA5 = MA( C, 5 );
> > > MA10 = MA( C, 10 );
> > > Buy = Cross( MA5, MA10 ) AND LowsetSince( Cross( MA10, MA5 ),  
RSI
> > (14) ) < 30;
> > > 
> > > 
> > > -- 
> > > Cheers
> > > Graham Kav
> > > AFL Writing Service
> > > http://www.aflwriting.com
> > > 
> > > 
> > > 2008/7/9 Mike <sfclimbers@>:
> > > > Also,
> > > >
> > > > you may want to rethink your logic to be more restrictive. 
Just
> > > > looking to see if the RSI was less than 30 *ever* is not 
going 
> to 
> > be
> > > > very usefull. You might want to adjust your strategy for 
> trigger1 
> > to
> > > > be RSI < 30 within some predefined time period (e.g. within 
> last 
> > 20
> > > > bars) giving the following:
> > > >
> > > > Buy = BarsSince(RSI(14) < 30) < 20
> > > > AND Cross(MA(Close, 5), MA(Close, 10));
> > > >
> > > > If you specifically wanted to measure from the point that the 
> RSI
> > > > *first crossed* below 30 (as opposed to the most recent day 
at 
> > which
> > > > it was *still* below 30), you would use Cross in the first 
> > expression
> > > > too:
> > > >
> > > > Buy = BarsSince(Cross(30, RSI(14))) < 20
> > > > AND Cross(MA(Close, 5), MA(Close, 10));
> > > >
> > > > Mike
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "wavemechanic" <timesarrow@>
> > > > wrote:
> > > >>
> > > >> Sounds like you want something along these lines: barssince
> (rsi <
> > > > 30) > 1 and (moving average condition).
> > > >>
> > > >> Bill
> > > >>
> > > >>
> > > >>   ----- Original Message -----
> > > >>   From: tridean34
> > > >>   To: amibroker@xxxxxxxxxxxxxxx
> > > >>   Sent: Tuesday, July 08, 2008 8:26 AM
> > > >>   Subject: [amibroker] Re: Not sure how to create a trigger
> > > >>
> > > >>
> > > >>   Hi Guys,
> > > >>   sorry for not being more specific.
> > > >>
> > > >>   Let's say it is RSI I am using.
> > > >>
> > > >>   If RSI < 30 then look for trigger 2. Let's say trigger 2 
is 
> mav
> > > >>   crossover. Say 5 and 10
> > > >>
> > > >>   If mav 5 crosses above mav 10 then buy.
> > > >>
> > > >>   As this stands I can have
> > > >>
> > > >>   Buy = RSI < 30
> > > >>   AND
> > > >>   MAV 5 > MAV 10; (or something like that)
> > > >>
> > > >>   The problem is, I don't care if the RSI is < 30 when the 5 
> mav
> > > >>   actually crosses above the 10 mav, only that it occurred 
> before
> > > > hand.
> > > >>   The RSI MUST hit or go below 30 before the system looks 
for 
> the
> > > > mav
> > > >>   crossover, but once the crossover takes place, the RSI 
does 
> NOT
> > > > have
> > > >>   to be at any specific level
> > > >>
> > > >>   And it is this I don't know how to code.
> > > >>
> > > >>   cheers
> > > >>   Dean
> > > >>
> > > >>
> > > >>   ------------------------------------
> > > >>
> > > >>   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
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>   No virus found in this incoming message.
> > > >>   Checked by AVG - http://www.avg.com
> > > >>   Version: 8.0.138 / Virus Database: 270.4.6/1539 - Release 
> Date:
> > > > 7/7/2008 6:35 PM
> > > >>
> > > >
> > > >
> > > >
> > > > ------------------------------------
> > > >
> > > > 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/