• Australian (ASX) Stock Market Forum

Amibroker FAQ

Discussion in 'Software and Data' started by RichKid, Jul 15, 2005.

  1. RichKid

    RichKid PlanYourTrade > TradeYourPlan

    Posts:
    2,981
    Likes Received:
    1
    Joined:
    Jun 18, 2004
    This thread is for fellow Amibroker users to help each other out. If there is a very specific project you are carrying out which is likely to deviate from a general faq type thread then you are welcome to start a new thread.

    There was some discussion of how to use Amibroker in one of the system testing threads, hence the reason for this thread.

    If there is sufficient interest we may start a Metastock thread too but always be aware of the forums/websites dedicated to particular software, that should always be the first stop (apart from the vendor site itself) imo. But otherwise the folk who frequent ASF should be happy to help you out!

    Over to you Amibroker fans!!
     
  2. kaveman

    kaveman Well-Known Member

    Posts:
    173
    Likes Received:
    0
    Joined:
    Jul 11, 2005
    I am always happy to help anyone with writing AFL for AB. I am a regular in the AB yahoo group, AB website forum, RC and other places.
     
  3. Artamon

    Artamon Active Member

    Posts:
    25
    Likes Received:
    0
    Joined:
    Jul 11, 2005
    G'day all,

    Not that my endorsement will carry much weight :D but kaveman is very helpful and active when it comes to AB and he knows his stuff. Certainly an asset to be used for us AB'ers ;)

    Andrew.
     
  4. RichKid

    RichKid PlanYourTrade > TradeYourPlan

    Posts:
    2,981
    Likes Received:
    1
    Joined:
    Jun 18, 2004
    Thanks very much Kaveman, glad to have an expert around!
     
  5. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    Kaveman,

    A couple of questions about something I'm finding a little confusing.

    Firstly, the ValueWhen and LastValue functions, specifically when used together - ie. LastValue(ValueWhen(...)). The help says that ValueWhen returns an array value, yet also says the return value is an array. From examples it seems that ValueWhen is really to find one particular number, and the above construct implies that that desired value is the last one in the returned array. So what's in the rest of the returned array? It seems like a convoluted way of just returning a number from an array. I normally just access the last element of an array using subscript notation, eg. Close[BarCount-1].

    Secondly, something that's not explained at all in the help. With the Peak and Trough functions, the second parameter is called "Change". In a sample trendline example, the change parameter is calculated using a rate-of-change formula. What exactly is this change parameter, and what does it do?

    Thanks.

    GP
     
  6. wayneL

    wayneL Rotaredom

    Posts:
    14,893
    Likes Received:
    2
    Joined:
    Jul 9, 2004
    I've caused myself an anurism trying to program a chandelier exit that duplicates the one done in metastock using the prev function.

    This is my version of it in metamumble code:

    mult:=Input("Enter ATR Multiplication Value",1,10,3);

    ap:=Input("Enter ATR Lookback",5,50,21);
    Stop1:=If(PREV < C,If((x-mult*ATR(ap)) >= PREV,(x- mult*ATR(ap) ),PREV),( x - mult*ATR(ap) ));
    x:=Max(Stop1,Ref(stop1,-1));
    x;
     
  7. wayneL

    wayneL Rotaredom

    Posts:
    14,893
    Likes Received:
    2
    Joined:
    Jul 9, 2004
    PS This is how it plots:
     

    Attached Files:

  8. Milk Man

    Milk Man Well-Known Member

    Posts:
    566
    Likes Received:
    0
    Joined:
    May 11, 2005
    G'day all,

    I've been working on a "bang for buck" indicator; this is the jist of it:

    -Care of one of Tech/a's posts (he's already got the Metastock formula there)
    "Divide a $10,000 account by the closing price on any given day. This number is then multiplied by the average range of the stock for the last 200 days. Dividing this number by 100 converts the result to dollars and cents which inturn indicates the possible dollar return on any given day."

    I've converted this to:

    (10000/C)* (ATR(200)/100)

    Is this right?

    I'm thinking of plotting it as a histogram but i'll cross that bridge when I come to it.

    Also see the systems development thread for another interesting application.
    (well I think it is anyway :) )
     
  9. DTM

    DTM Well-Known Member

    Posts:
    674
    Likes Received:
    0
    Joined:
    Dec 21, 2004
    Now you're definitely speaking Greek to me.

    Pardon my ignorance but what is Amibroker? Is it like E-signal and Metastock. Do you get a live feed from Amibroker?

    Thanks in advance.

    Daniel
     
  10. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    Daniel,

    Take a look here.

    It's a charting program but I believe you can get live feeds for it, although not from AmiBroker themselves. I only use EOD data myself.

    GP
     
  11. kaveman

    kaveman Well-Known Member

    Posts:
    173
    Likes Received:
    0
    Joined:
    Jul 11, 2005
    I will try to answer queries, just remember that except for TJ, the AB developer/owner .. yes only one person not large copmpany, nobody knows it all. The amibroker yahoo groups are the best resource as yu get the developer plus users from all over the world helping each other. There is also a compilation of the emails available on the AB website that works like a help search database.

    But I can answer most straightforward questions.

    1. Daniel, Amibroker is a charting package that MS would love to be when it grows up. AB can use live intraday data feed from various sources to plot the intraday data, explore, scan etc. I do this using quotetracker as the data feed, which in turn takes the data suipply from my online broker, although there are many sources of data for QT. AB can aslo take direct fromm other sources as well, check the website for AB (www.amibroker.com) download the trial version and see for yourself what it does.

    2. Greatpig

    VALUEWHEN & LASTVALUE

    Valuewhen provides values of an array when the prescribed condition/s are true eg FridayHigh = Valuewhen( dayofweek()==5, H, 1 ) will give the value of high for the previous Friday. This value of FridayHigh will hold true until the next friday occurs try this plot

    Friday = DayOfWeek()==5;
    FridayHigh = ValueWhen( Friday, H, 1 );
    Plot(C,"Close",colorGrey50,styleBar);
    Plot(FridayHigh,"Friday High",colorRed,styleStaircase|styleNoRescale);
    PlotShapes( shapeStar*Friday,colorGreen,0,H,10);
    LastFridayHigh = LastValue(FridayHigh);
    Filter=1;
    AddColumn(FridayHigh,"All Friday",1.3);
    AddColumn(LastFridayHigh,"Last Friday",1.3);

    Lastvalue just gives the absolute last value of an array for that symbol, eg try the above in AA exploration over the last 10 bars for a stock


    PEAK & TROUGH

    Peak and trough are just the turning points as seen ina zig plot
    To explain the change for just peak, the help screen gives this
    Peak( ARRAY, change, 1 )
    Peak( Close, 5, 1 )
    so what peak does is finds higher close value and holds until either a new higher close OR until the value of close drops by 5% from the last high close

    eg close values
    90,89,95,94,97,100,98,97,95
    p, -, p, -, p, P, -, -, **
    the lower case p's are the new higher values. The ** means 5% lower value than the last peak, ie 100 *95% = 95. So the 100 point will become the Peak point and be embedded in stone on the chart. Once the peak is found in zig the next trough search begins like the peak but in reverse.
    This is why they say zig looks into the future, it means that later values are required to find the actual value in the past. it has to go into the future to determine where/what that point is. In my example it went 3 bars after the peak could be designated.
    If you had said the change wqas 20, the fro a value of 100 it would have to reach 80, ie 20% of the value before the peqak would have been set. In that time if another vaslue higher than 100 occured before th 80 then it resets to a new 20% of that higher value.

    Hope this helps.


    wayneL,

    you could try the 3rd party plug in
    http://www.amibroker.org/3rdparty/
    and this example on how to use
    http://www.amibroker.com/library/formula.php?id=395

    you could also use the applystop from the help screens, but that won't help you plot it

    ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(14), True, True );

    However that does not quite answer your query. PREV is probably the most frequently asked question from past MS users. AB does looping which does this job better and faster. Afraid I am not fully conversant with MS mumbo jumbo, although some can be obvious


    from what I can discover the chandelier exit is just the ATR * constant

    one way would be, provided you had buy signals

    mult= Param( "Enter ATR Multiplication Value", 1, 10, 3 );
    ap = Param( "Enter ATR Lookback", 5, 50, 21 );
    Chand = highestsince( buy, C-mult*ATR(ap) );

    for more details on PREV look up the yahoo group database
    basically I think it just looks up the previous bars value
    I will sue the same as above as example of looping it

    Buy = Cross(C,EMA(C,10)); //example only to get code working

    mult= Param( "Enter ATR Multiplication Value", 1, 10, 3 );
    ap = Param( "Enter ATR Lookback", 5, 50, 21 );
    Chand = C-mult*ATR(ap);
    Stop[0] = L[0];

    for(i=1;i<BarCount;i++)
    {
    if( Buy )
    { Stop = Chand; }
    else
    { if ( chand > Stop[i-1] )
    { Stop = Chand; }
    else
    { Stop = Stop[i-1]; }
    }
    }

    Sell = Cross(Stop,C);

    One thing to note, if you use Applystop it works on the low crossing the nominated stop value (in my experience of trying it). If you want to use something else, then need to loop it as above


    Hope this helps a bit


    3. loakglen
    sorry am not familiar with bang for buck, so can only guess at the original

    if you have data in cents then use the /100, else remove the /100
    this is correct. Try this as both the price and ATr will be in cents
    ( 10000 / (C / 100) )* ATR(200)/100

    simpler
    1000000/C*ATR(200)

    if your data is in dollars
    10000/C*ATR(200)


    hope I have been of help here
     
  12. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    That formula can be simplified and made a little clearer. You'll notice it multiplies by 10,000 but then divides by 100, which is the same as just multiplying by 100.

    If you consider what it's doing:

    ATR(200) is the average true range for the last 200 days in dollars.

    ATR(200) / C is the range as a fraction of the closing price, which is more meaningful than an absolute value since you'd expect the absolute range to be higher for higher priced stocks (plus for a fixed amount of capital, you'd have less shares of a higher priced stock).

    Multiplying that by 100 turns it into a percentage. So the formula you gave, which is identical to ATR(200)/C*100, is the 200 day average true range of a stock as a percentage of the closing price.

    Thus if the ATR(200) of a $1 share is 2 cents, then the result would be 2%. Which would be the dollar amount for a $100 of that share.

    It's worth seeing what difference the ATR period makes. For a long period like 200, you'll see the result shoot up when the price falls significantly. In reality the fractional ATR at the lower price might be similar to before, meaning the absolute ATR will have dropped as well, but the 200 period ATR is holding on to the older high values, making it look like it's gone up. This can be seen in the attached chart of BGF, where at the bottom of the dip in Sept '04 the 10 period ATR gives a value of 3.9% compared to the 7.8% of the 200 period ATR. Personally I think a shorter period would be more useful for a stock that has ranged in price a fair bit.

    Cheers,
    GP


    AmiBroker formula to display this as a histogram, allowing the ATR period to be a parameter:

    //********************************************************

    /*
    Percentage ATR

    The parameter slider uses zero as the first value just so that
    other values will be a multiple of 5. However, zero shouldn't
    be passed to the ATR function, so will change to 1.
    */

    per = Param("Period?", 200, 0, 400, 5);
    if (NOT per)
    per = 1;

    Plot(ATR(per)/Close*100, "ATR(" + WriteVal(per, 1.0) + ")%", colorBlack, styleHistogram);

    //********************************************************
     

    Attached Files:

  13. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    Kaveman,

    Thanks for the info!

    So is there any difference between LastValue(ARRAY) and ARRAY[BarCount-1]?


    Okay.


    Ah... so that change is a percentage price move value. That makes sense.

    Thanks again.

    Cheers,
    GP
     
  14. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    Just thinking, a better idea would be to average the percentage ATR rather than the absolute one. So instead of:

    ATR(200) / C

    Try:

    EMA(ATR(14) / EMA(C, 14), 200)

    This takes a 200 period EMA of the 14 period percentage ATR (using a 14 period EMA of the close rather than the last close). I think that would give more useful results.

    Attached is BGF again, with a 14 period ATR and 21 period EMA of the percentage ATR.

    Cheers,
    GP


    Updated formula, allowing ATR and EMA periods to be parameters:

    //*****************************************************

    /*
    Percentage ATR
    */

    eper = Param("1. EMA Period?", 21, 1, 200, 1);
    aper = Param("2. ATR Period?", 14, 1, 100, 1);
    Plot(EMA(ATR(aper)/EMA(Close, aper), eper)*100, "ATR(" + WriteVal(aper, 1.0) + "), EMA(" + WriteVal(eper, 1.0) + ")%", colorBlack, styleHistogram);

    //*****************************************************
     

    Attached Files:

  15. kaveman

    kaveman Well-Known Member

    Posts:
    173
    Likes Received:
    0
    Joined:
    Jul 11, 2005
    might be a good idea to just keep this thread to straight question/answer on using amibroker. Further discussion on mods for systems can be discussd in separate threads. Otherwise be hard to sort the wheat from the chaff.
     
  16. DTM

    DTM Well-Known Member

    Posts:
    674
    Likes Received:
    0
    Joined:
    Dec 21, 2004
    Thanks GP and kaveman, very interesting indeed. So cheap and I also looked up reviews for it and it was something like 96% approval rating.

    Now I'll be reading this thread more closesly to see if I can learn anything. :D
     
  17. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    Yeah, you're probably right.

    Unfortunately I'm not able to move the other stuff now.

    Cheers,
    GP
     
  18. RichKid

    RichKid PlanYourTrade > TradeYourPlan

    Posts:
    2,981
    Likes Received:
    1
    Joined:
    Jun 18, 2004
    Hi,
    Also do a search for 'amibroker' on ASF and you'll find some discussion of it (including comments by GP), I think I asked some questions about it myself. Hope this helps.
     
  19. Milk Man

    Milk Man Well-Known Member

    Posts:
    566
    Likes Received:
    0
    Joined:
    May 11, 2005
    I want to set buy and sell signals for all positions when theres a 50 day MA crossover (for example) by the xao.

    How do I set buy/sell signals by indicators given by a particular index/stock?

    Help has and will be much appreciated. :)
     
  20. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    0
    Joined:
    Jul 9, 2004
    You need two periods for an MA crossover. Say you want to use 14 day crossing 50 day, then for a particular stock you can write (using EMA - my preferred one):

    es = EMA(C, 14);
    el = EMA(C, 50);
    Buy = Cross(es, el);
    Sell = Cross(el, es);

    For the XAO you have to use the Foreign function:

    xao = Foreign("XAO", "Close");

    Then same as above but using "xao" in place of "C":

    xes = EMA(xao, 14);
    xel = EMA(xao, 50);
    Buy = Cross(xes, xel);
    Sell = Cross(xel, xes);

    I don't think you'd want to buy a particular stock just because the XAO has done a crossover though. However, if you wanted something like the stock crossover but only if the shorter MA for the XAO was above the longer one (meaning it's rising), then you could do something like:

    Buy = Cross(es, el) AND xes > xel;
    Sell = Cross(el, es) OR xes < xel;

    This would only signal buy if xes was above xel when the stock crossover happened, but would signal sell if either the stock crossover happened or xes dropped below xel.

    You have to be careful if using crossover signals to buy but other signals to sell. If the other signal (eg. xes dropping below xel) signalled a sell, but then it reverted back again (ie. xes went back above xel), you wouldn't get another buy stock crossover if it hadn't crossed downwards, and thus might not get back into a longer uptrend. In that case you might want to make the XAO crossover signal a buy if the stock MAs were already in the buy position:

    Buy = (Cross(es, el) AND xes > xel) OR (Cross(xes, xel) AND es > el);

    Hope that helps.

    GP
     
Loading...

Share This Page