• Australian (ASX) Stock Market Forum

Hello and welcome to Aussie Stock Forums!

To gain full access you must register. Registration is free and takes only a few seconds to complete.

Already a member? Log in here.

Most liked posts in thread: Amibroker FAQ

  1. howardbandy

    howardbandy

    Posts:
    838
    Likes Received:
    93
    Joined:
    Jun 13, 2007
    Using the ValueWhen function might be easier.

    The key is this line:
    SellLowClose = C < ValueWhen( Buy, L );

    The ValueWhen function finds the bar of the most recent Buy,
    then returns the value of the Low on that bar.

    The right hand side of the assignment tests every bar to see if
    the Close is less than the Low of the bar of the Buy.
    If it is, set SellLowClose to True.


    Best, Howard

    ---------------------

    // ExitUsingValueWhen.afl

    // Buy when fast moving average
    // crosses up through slow moving average
    // Sell when the Close is lower
    // than the Low on the bar of the Buy

    FastMALB = 10;
    SlowMALB = 30;
    FastMA = MA( C, FastMALB );
    SlowMA = MA( C, SlowMALB );
    Buy = Cross( FastMA, SlowMA );
    SellMA = Cross( SlowMA, FastMA );

    SellLowClose = C < ValueWhen( Buy, L );

    //Sell = SellMA;
    Sell = SellLowClose;

    Buy = ExRem( Buy, Sell );
    Sell = ExRem( sell, Buy );


    Plot( C, "C", colorBlack, styleCandle );
    Plot( FastMA, "FastMA", colorGreen, styleLine );
    Plot( SlowMA, "SlowMA", colorBlue, styleLine );

    shapearrows = Buy * shapeUpArrow + Sell * shapeDownArrow;
    PlotShapes( shapearrows, IIf( Buy, colorGreen, colorRed ),
    0, IIf( Buy, Low, High ) );

    // end //
     
    Indoril, Gringotts Bank and rb250660 like this.
  2. julieta

    julieta

    Posts:
    9
    Likes Received:
    19
    Joined:
    Oct 19, 2014
    csnip.PNGcomsec.PNG
    step1 end of day prices step2 as in pic get date download you get all the warrants etc witch have to be deleted with a script
     
    CNHTractor, qldfrog and dutchie like this.
  3. Newt

    Newt

    Posts:
    459
    Likes Received:
    614
    Joined:
    Oct 17, 2012
    Yes, nice code GB!

    Chipotle, the code does what you asks - a is TRUE when there is a down day, then "aa" is a volume series when based on "a" being true.

    If you want the condition to be a relative change (other than just a "down day") there is nothing to stop you changing the <0 to <x, where x is the % change you want to test against. I don't useROC a lot and would have to double-check references, but if you want a price series based on today's price being less than or equal to 10% increase on yesterday, think this would do the job:

    a = ROC(C,1)<10;
     
    Gringotts Bank and chipotle like this.
  4. Newt

    Newt

    Posts:
    459
    Likes Received:
    614
    Joined:
    Oct 17, 2012
    Its pretty rare you have to resort to looping through bars unless you're doing something particularly tricky. Amibroker makes working with arrays so easy and powerful its generally easy to program and much faster code to say in the "array world".

    Glad you got it working in the end though.
     
    Wysiwyg and Trav. like this.
  5. Gringotts Bank

    Gringotts Bank

    Posts:
    6,175
    Likes Received:
    602
    Joined:
    Jun 30, 2007
    I assume you're doing a portfolio backtest with "all symbols" selected in the Analysis window.

    x.jpg

    Make sure you have symbol ^AORD in your database, with enough history. If you don't, use AQ to download from Yahoo finance.

    x.jpg

    Then substitute your breakout code where I have bolded below.

    SetForeign("^AORD");
    MAPeriod = Optimize("op",2,2,100,1);
    IndexFilterup = C > MA(C,MAPeriod);
    RestorePriceArrays();

    Buy = IndexFilterup AND BOut;
     
    qldfrog and willoneau like this.
  6. kaveman

    kaveman

    Posts:
    173
    Likes Received:
    4
    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.
     
    stanwell likes this.
  7. kaveman

    kaveman

    Posts:
    173
    Likes Received:
    4
    Joined:
    Jul 11, 2005
    this will give buy signal when the ROC drops bleow -10 and sell when C drops below ema

    buy = cross(-10,ROC(c,5));
    sell = cross(ema(c,5),c);

    you might also want to add condition to buy that the Close is above the ema for entry, otehrwise exit will occur straight away

    buy = cross(-10,ROC(c,5)) and C>EMA(C,5);
    sell = cross(ema(c,5),c);

    filter = buy or sell;
    addcolumn(C,"Close",1.3);
    addcolumn(ROC(c,5),"ROC",1.3);
    addcolumn(ema(c,5),"EMA",1.3);

    hope this helps
     
    ozcabman likes this.
  8. rub92me

    rub92me Don't look back

    Posts:
    1,071
    Likes Received:
    6
    Joined:
    Apr 24, 2006
    Question for the Amibroker gurus. I'm importing eod ASX data that includes futures, but really I'm only interested in (three letter) stock codes. I have a script to clean up the futures after the import, but is there a way to restrict the import to three letter codes in the first place (other than editing the data before I import it in Amibroker?). I had a look around in the help file on data import scripts but couldn't find anything that does this. :confused:
     
    aus_trader likes this.
  9. rub92me

    rub92me Don't look back

    Posts:
    1,071
    Likes Received:
    6
    Joined:
    Apr 24, 2006
    Phoenix, that's what I want.
    Say I have data in the EOD file that looks like this:

    BKY,20060320,0.75,0.77,0.71,0.71,1851025
    BKYO,20060320,0.53,0.55,0.50,0.505,724026
    BLD,20060320,8.95,8.99,8.90,8.99,1093978

    I want the import to skip the line for BKYO and only import the data for BKY and BLD (as I'm not interested in the options data).
    My script can delete BKYO after the import, which takes quite a long time to run.
    If you have a script that strips out at/before import, that would be most welcome!
     
    aus_trader likes this.
  10. kaveman

    kaveman

    Posts:
    173
    Likes Received:
    4
    Joined:
    Jul 11, 2005
    Rather than try to limit the imports why not sort the database.
    Here is an aFL I use myself, made it long ago. I just move all symbols to Market0 then run the scan on all stocks.
    The only thing needed is to have any index already in the index category, and I keep any delisted stocks in watchlist 63
    After the scan any symbols left in market0 have no data and can generally be deleted
    So you can run any tests on market 1 being the shares only.

    //Sort shares into the markets
    //Graham Kavanagh 15 Apr 2005
    //Scan on all tickers

    Index = IsIndex();
    Delisted = InWatchList(63);
    Backtest = GroupID()==253;
    Share = (StrLen(Name())==3 OR (StrLen(Name())==5 AND StrMid(Name(),3,1)=="D" AND StrRight(Name(),1)!="P")) AND Index==0 AND Delisted==0 AND Backtest ==0;
    Other = share==0 AND index==0 AND DeListed==0 AND Backtest ==0;

    Buy=1;


    if( Share )
    { CategoryAddSymbol("",categoryMarket,1); }
    if( index )
    { CategoryAddSymbol("",categoryMarket,2); }
    if( Other )
    { CategoryAddSymbol("",categoryMarket,3); }
    if( Delisted )
    { CategoryAddSymbol("",categoryMarket,4); }
    if( Backtest )
    { CategoryAddSymbol("",categoryMarket,253); }
     
    aus_trader likes this.
  11. rub92me

    rub92me Don't look back

    Posts:
    1,071
    Likes Received:
    6
    Joined:
    Apr 24, 2006
    Thanks Graham. I have my data sorted already in a similar way, so it's no real bother from an explore/backtest perspective. Just thought I could prevent from importing it in the first place; I used to have Fcharts that had this built in as import functionality so was looking for something similar. If I can be bothered I may write a little macro to edit the data prior to import instead.
     
    aus_trader likes this.
  12. GreatPig

    GreatPig Pigs In Space

    Posts:
    2,368
    Likes Received:
    8
    Joined:
    Jul 9, 2004
    Download this Windows version of the Grep utility, put it either in the folder with the stock code file or in a folder in the DOS path, then from the command line in that folder, type:

    grep "^...," filename.ext > newname.ext

    where filename.ext is the name of the stock code file, and newname.ext is the output filename that you will then import into AmiBroker.

    Note that this will drop a few stock codes longer than 3 characters which are like stocks (eg. TLSCA). You could specifically include individual codes using a command like this:

    grep -e "^...," -e TLSCA filename.ext > newname.ext

    You could put all this in a batch file (say g.bat), even starting the filename for this year:

    grep -e "^...," -e TLSCA 2007%1.txt > 2007%1-X.txt

    Then to run the conversion, use:

    g 0411

    (assuming the filename has a date format like 20070411.txt)

    This would generate a file called 20070411-X.txt with just the codes you want, which could then be imported into AmiBroker.

    Sounds a bit complicated, but once the batch file is set up, it's dead easy (assuming you're familiar with using the command line interface).

    If you want to know more about Grep, command line switches listed here, and regular expression details listed here (go to the very end).

    GP
     
    aus_trader likes this.
  13. kaveman

    kaveman

    Posts:
    173
    Likes Received:
    4
    Joined:
    Jul 11, 2005
    Tools-Preferences-Charting at bottom of window type in how many panes you want in the chart window
     
    aus_trader likes this.