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

[amibroker] AFL question



PureBytes Links

Trading Reference Links

Dear Amibroker experts,

 I may be missing a major concept or I am trying to do something 
that you cannot do in AFL.  I was going thru Elders concepts and he 
mentions a concept called  safe zone to help calculate a stop.

What I wanted to do is the following:
Calculate a buy signal.
Calculate the safezone .  
Establish a sell stop based on the safezone.
Never allow the sell stop to go down . . . .(Ok if it goes up)

Looking at Buy and Testflip, they first follow a pattern of 0,0
Then on the buy day, its 1,1 
And then on the following days, Its buy=0 and testflip =1

The problem seems to be you need to calculate the stop to set up the 
sell and need the sell to get test flip and need testflip to get 
stop, so its circuitous logic that won't run and will show a
syntax 
error.

If you try to set up as below with an initial condition stop, that 
doesn't give you what you want either.

I know this logic is no good and at this point I am totally 
confused.  If any one can help point me in the right direction I 
would appreciate it.  Perhaps there is an AFL statement I am not 
aware of that would solve this.  For example set an intial condition 
but then never go thru that statement again?

Here is the logic I had been running; I have been playing with it 
all day and have just about given up.  Please help thanks

//wg Elder v3-  set up Buy

Cond1 = EMA(Close, 130);
Cond2 = EMA(Ref(Close, -1),130);
FI1 = (C - Ref( C, -1 )) * V;
FI = EMA( FI1, 2 ); 
Buy = (Cond1 > Cond2) AND FI < 0; 

//an attempt at Elder Safezone - WG
down_penetration = 
IIf(C < Ref(C,-1), Ref(C,-1) - C, 0) +
IIf(Ref(C,-2) < Ref(C,-3), Ref(C,-3) - Ref(C,-2), 0) +
IIf(Ref(C,-3) < Ref(C,-4), Ref(C,-4) - Ref(C,-3), 0) + 
IIf(Ref(C,-4) < Ref(C,-5), Ref(C,-5) - Ref(C,-4), 0) +
IIf(Ref(C,-5) < Ref(C,-6), Ref(C,-6) - Ref(C,-5), 0) + 
IIf(Ref(C,-6) < Ref(C,-7), Ref(C,-7) - Ref(C,-6), 0) +
IIf(Ref(C,-7) < Ref(C,-8), Ref(C,-8) - Ref(C,-7), 0) + 
IIf(Ref(C,-8) < Ref(C,-9), Ref(C,-9) - Ref(C,-8), 0) +
IIf(Ref(C,-9) < Ref(C,-10), Ref(C,-10) - Ref(C,-9), 0) + 
IIf(Ref(C,-10) < Ref(C,-11), Ref(C,-11) - Ref(C,-10), 0) +
IIf(Ref(C,-11) < Ref(C,-12), Ref(C,-12) - Ref(C,-11), 0);

Num_dn_days = 
IIf(C < Ref(C,-1), 1, 0) +
IIf(Ref(C,-2) < Ref(C,-3), 1, 0) +
IIf(Ref(C,-3) < Ref(C,-4), 1, 0) + 
IIf(Ref(C,-4) < Ref(C,-5), 1, 0) +
IIf(Ref(C,-5) < Ref(C,-6), 1, 0) + 
IIf(Ref(C,-6) < Ref(C,-7), 1, 0) +
IIf(Ref(C,-7) < Ref(C,-8), 1, 0) + 
IIf(Ref(C,-8) < Ref(C,-9), 1, 0) +
IIf(Ref(C,-9) < Ref(C,-10), 1, 0) + 
IIf(Ref(C,-10) < Ref(C,-11), 1, 0) +
IIf(Ref(C,-11) < Ref(C,-12), 1, 0);

Avg_down_penetration = down_penetration / Num_dn_days;

stop = Low - (Avg_down_penetration * 2);
Calcstop = Low - (Avg_down_penetration * 2);

Sell = Low < stop;

//remove extra buy and sell signals
Buy = ExRem (Buy,Sell);
Sell = ExRem (Sell,Buy);
testflip = Flip(Buy,Sell);

STOP =
IIf (NOT Buy AND NOT TESTFLIP, CALCSTOP,
IIf(Buy AND TESTFLIP, CALCSTOP, 
IIf(NOT Buy AND TESTFLIP, IIf(Ref(STOP,-1) > STOP, Ref(STOP,-1), 
STOP), CALCSTOP)));


// filter allows explore - filter = 1 shows all rows
Filter = 1;
NumColumns = 8;
Column0 = C;
Column1 = Avg_down_penetration;
Column2 = Num_dn_days;
Column3 = Low;
Column4 = stop;
Column5 = Buy;
Column0Name = "Close";
Column1Name = "avg dn pen";
Column2Name = "dn days";
Column3Name = "low";
Column4Name = "stop";
Column5Name = "buy = 1";
Column6 = Sell;
Column6Name = "sell = 1";
Column7 = testflip;
Column7Name = "testflip";
 





------------------------ Yahoo! Groups Sponsor ---------------------~-->
Your own Online Store Selling our Overstock.
http://us.click.yahoo.com/rZll0B/4ftFAA/46VHAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/