PureBytes Links
Trading Reference Links
|
Hello,
What you wrote is COMPLETELY WRONG.
You simply completely lack the understanding how BarsSince works,
how MS works and how AB works.
FYI: Metastock BarsSince works the same as AFLs.
You simply are misguided by MS formulas using infamous "PREV" statement
that is basically the worst idea Equis programmers came up with.
Please READ http://www.amibroker.com/guide/h_understandafl.html
Read it twice, three times or four, five or ten times if necessary.
Your problem is that you want to use "PREVIOUS" bar value.
There are many ways to achive this goal but most general
is TO USE LOOPING.
=============
Simple and straightforward AND *FAST* (compared to horrible MS "Prev")
See sample code that demonstrates it (posted tens of times already)
and also available in http://www.amibroker.com/guide/whatsnew.html
document (at the very end):
/* a sample low-level implementation of Profit-target stop in AFL: */
Buy = Cross( MACD(), Signal() );
priceatbuy=0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 && Buy[ i ] )
priceatbuy = BuyPrice[ i ];
if( priceatbuy > 0 && SellPrice[ i ] > 1.1 * priceatbuy )
{
Sell[ i ] = 1;
SellPrice[ i ] = 1.1 * priceatbuy;
priceatbuy = 0;
}
else
Sell[ i ] = 0;
}
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "Owen Davies" <owen5819@xxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Friday, November 12, 2004 2:50 PM
Subject: Re: [amibroker] BarsSince(Buy)
>
> Tomasz Janeczko wrote:
>
>>You can use ExRemSpan instead: (etc.)
>>
>
> I could again go over why this doesn't work?
>
> Please trace through the logic of what happens when ExRemSpan lands you
> on another day when the Buy conditions are true.
>
> For example--the example I used maybe two weeks ago--take the classic
> Larry Williams system with a volatility-breakout entrance and his
> "bailout" exit: Enter when today's High is higher than the Open plus
> (some fraction of) yesterday's range. To get out, wait one bar, to give
> the price time to move, and Sell on the first profitable Open. Use a
> stop-loss to escape the losers. So:
>
> Buy=H > O + Ref(H - L,-1);
> BuyPrice=Max(O, Ref(H - L,-1) + TickSize);
>
> Sell=BarsSince(Entry) > 1 AND O > Ref(C,-BarsSince(Entry));
> SellPrice=O;
>
> //And the obvious equivalents for Short trades
>
> ApplyStop(0,2,PickANumber,1,False);
>
> Those of you who once used Metastock will remember BarsSince(Entry),
> probably with great fondness and regret. But you can't do that in AFL.
> You can't even do separate BarsSince(Buy) and BarsSince(Short)
> statements. In AFL, your Sell statement becomes Sell=O >
> ValueWhen(Buy,BuyPrice,1); And when you try to use ExRemSpan, there is
> every chance that you will land on another day where the Buy conditions
> are true. At which point the ValueWhen function looks at that day's
> BuyPrice, and O is never higher.
>
> For a one-day delay, we can write two sell conditions, one for use if
> today is a Buy day and one for use if it is not, with different numbers
> for the third parameter in the ValueWhen statement. But what if you'd
> like to set the delay for more than one day? How many Sell conditions
> do you have to write to take care of all the possible combinations of
> Buy and non-Buy days since the entry?
>
> Two very talented programmers from our group were kind enough to attempt
> solutions to this problem for me, one in AFL, the other in ... I guess
> that was jScript. I am very grateful to them for trying. However,
> neither succeeded. In each case, trades that should have ended with a
> profit after two or three days were not exited until much later. In a
> test of the AFL version on continuous S&P data, the average trade length
> was just over 46 bars, and one trade lasted more than 600 bars!
>
> This is a very simple system, one of the most famous in all of
> traderporn. It can be "coded" unambiguously in English. With
> BarsSince(Entry), it could be coded unambiguously in Metastock; but MS
> would not give you valid entry and exit prices when I used it last; that
> was a major reason I was delighted when Tomasz made Amibroker
> available. Unfortunately, one really useful thing from Metastock got
> left behind. I understand that there are reasons for this. But those
> reasons are keeping me from testing this and several other ideas that
> might be of value. Or they might not. At this point, I have no way to
> know.
>
> I am profoundly sorry to keep pushing this, as I believe Tomasz created
> ExRemSpan in response to one of my early pleas for help in coding this
> exit. And it could be that there is some way to use ExRem and ExRemSpan
> that actually solves the problem with the kind of generality I'm looking
> for, a technique that Tomasz knows but neither I nor my Samaritans were
> able to recognize. But I'm betting against it.
>
> I have been trying to solve this problem for more than two years and am
> quite convinced that it cannot be done. Tomasz, PLEASE HELP.
>
> Pretty please? I'll finally get around to renewing my license if you
> do. 8-)
>
> Thanks to all for bearing with me on this.
>
> Owen Davies
>
>
>
> Check AmiBroker web page at:
> http://www.amibroker.com/
>
> Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
Check AmiBroker web page at:
http://www.amibroker.com/
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> 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/
|