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

Re: [amibroker] Re: exit formula help needed



PureBytes Links

Trading Reference Links

I tried changing it as you specified but when I run a backtest it still will exit a trade on the previous bars high/low (depending on whether im short or long).  I want AB to exit on either the low/high of the inside day or on a two bar trailing stop.  Can you see what is causing this problem because I can't work out why?


thanks
-------

NR4Day = (H - L) < Ref(LLV(H-L,3),-1);
Column1 =  NR4Day;
Column1Name = "Nr4Day";

InsideDay = H < Ref(High,-1) AND Low > Ref(Low,-1);
Column2 =  InsideDay;
Column2Name = "Inside Day";


NR4DayYest = Ref( NR4Day, -1 ); // new array - NR4Day shifted forward 1 bar

InsideDayYest = Ref( InsideDay, -1 ); // new array - InsideDay shifted forward 1 bar

HigherHigh = High > Ref( High, -1 );

LowerLow = Low < Ref( Low, -1 );

Buy = NR4DayYest AND InsideDayYest AND HigherHigh;

BuyPrice = Ref ( High, -1 );

Low1 = Ref(L, -2);
Low2 = ValueWhen(Buy,Ref(L,-1)-0.01);

Sell = L < Low1 OR L < Low2;

SellPrice = IIf(L < Low1,
IIf(L < Low2,
Max(Low1, Low2),
Low1),
IIf(L < Low2,
Low2,
0)
);

Short = NR4DayYest AND InsideDayYest AND LowerLow;

High1 = Ref(H, -2);
High2 = ValueWhen(Sell,Ref(H,-1)+0.01);

Cover = H > High1 OR H > High2;

CoverPrice = IIf(H > High1,
IIf(H > High2,
Max(High1, High2),
High1),
IIf(H < High2,
High2,
0)
);

On Fri, May 2, 2008 at 11:29 PM, Mike <sfclimbers@xxxxxxxxx> wrote:

Yes, it takes the lower of the two lows preceding the current bar. If
you want specifically the low of two bars ago, just use:

Low1 = Ref(L, -2);



Mike

--- In amibroker@xxxxxxxxxxxxxxx, "alta hob" <altahob@xxx> wrote:
>
> Thanks for taking the time to help. I will study the code you gave
me.
>
> Another question.
>
> If I use the
>
> Low1 = Ref(LLV(L,2),-1);
>
> Does this take the lowest low of the last 2 bars? If it does then
I have
> made a mistake. What I want to do is use the low from two bars
ago, not the
> lowest of the last two bars as this doesn't give my trade room to
breathe.
>
> cheers
>
> AH
>
> On Fri, May 2, 2008 at 9:09 PM, Mike <sfclimbers@xxx> wrote:
>
> > For these types of problems, it often helps to break up the
> > conditions for easier understanding.
> >
> > Using your example, what about something like:
> >
> > Low1 = Ref(LLV(L,2),-1);
> > Low2 = ValueWhen(Buy,Ref(L,-1)-0.01);
> >
> > Sell = L < Low1 OR L < Low2;
> >
> > SellPrice = IIF(L < Low1,
> > IIF(L < Low2,
> > max(Low1, Low2),
> > Low1),
> > IIF(L < Low2,
> > Low2,
> > 0)
> > );
> >
> > I'm assuming that if both conditions are met, then the one that
> > happened first (i.e. the higher price point) would be the selling
> > price.
> >
> > Mike
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%
40yahoogroups.com>, "alta hob"

> > <altahob@> wrote:
> > >
> > > Hi
> > >
> > >
> > > I am trying to do something similar but need my sellprice to
> > execute at the
> > > point the sell criteria below is hit
> > >
> > > Sell = L < Ref(LLV(L,2),-1) OR L<ValueWhen(Buy,Ref(L,-1)-0.01);
> > >
> > > Can someone please show me how to add the sellprice code to
this?
> > >
> > >
> > > thanks
> > >
> > >
> > > On Sat, Apr 26, 2008 at 12:03 AM, safetrading <safetrading@>
> > wrote:
> > >
> > > > Thanks Graham;
> > > >
> > > > That was exactly what I needed. I use Valuewhen all the time,
for
> > > > some reason I just drew a blank on this. I think the "buy"
> > variable
> > > > threw me, as I have never really done anything with it except
put
> > my
> > > > formula there.
> > > >
> > > > Anyways, thanks very much.
> > > >
> > > > Safetrading
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%
40yahoogroups.com><amibroker%

> > 40yahoogroups.com>,
> > Graham
> > > > <kavemanperth@> wrote:
> > > > >
> > > > > Valuewhen is useful for this
> > > > > I assume you are entering on same bar as buuy signal. This
line
> > > > gives
> > > > > you the low of the bar before buy signal
> > > > >
> > > > > sell=L<valuewhen(buy,ref(l,-1)-0.01);
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Cheers
> > > > > Graham Kav
> > > > > AFL Writing Service
> > > > > http://www.aflwriting.com
> > > > >
> > > > >
> > > > >
> > > > > 2008/4/26 safetrading <safetrading@>:
> > > >
> > > > > > This is probably easy for most of you, but I just can't
seem
> > to
> > > > > > figure this out.
> > > > > >
> > > > > > I'm using one tick above the high of the previous day for
an
> > > > entry
> > > > > > point and trying to create an exit rule where for a long
> > > > position,
> > > > > > the exit would be one tick below the low of the day prior
to
> > the
> > > > > > entry day ( the same days where I got my entry point from)
> > > > until a
> > > > > > low exists that is above the high of my entry point, at
which
> > > > time
> > > > > > the exit would then become one tick below that low and
> > continue
> > > > to
> > > > > > follow the trade like this; sell=L<ref(l,-1)-0.01;
> > > > > >
> > > > > > So what I need to do is label and hang on to the "one tick
> > > > below"
> > > > > > the low of the day prior to entering. I believe I need to
use
> > > > the
> > > > > > Hold function, but am not sure how to identify the price
> > point I
> > > > > > need.
> > > > > >
> > > > > > Any suggestions would be appreciated.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Safetrading
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > ------------------------------------
> > > > > >
> > > > > > 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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___