AmiBroker: sorting by entrytime

Discussion in 'Trading Software' started by cstdc1000, May 21, 2005.

  1. I just bought AmiBroke 4.70rc3 Pro and am using it to do real-time scans based on intraday timeframe.

    When new symbols appear, I hope the symbols can be lined up by their respective entry time, so that the newest symbol will be at the top or at the very bottom. AmiBroker does have the ¡°date¡± option, but I found out that it¡¯s only valid on ¡°daily¡± base but doesn¡¯t work on ¡°intraday¡± base.

    The technical supporter of AmiBroker said that their Amibroker works on the intraday function and can¡¯t reproduce my problem and thus doesn¡¯t know what to do with it.

    So I want to ask the users of AmiBroker: has anyone of you encountered the same problem, or can your AmiBroker work on the intraday function? I need to make sure if this is my individual problem, or it¡¯s a problem of AmiBroker.


    :confused: :confused: :confused:
     
  2. Not alot of (Amibroker) AFL fans on this forum, I've noticed.

    Not sure what you mean by "newest symbol that appears". If you're talking where you click the heading of a column (date/time) and the results then sort by that column. If that works with daily data and not RT data, then the support answer is probably right. last time I asked their support an AFL question I got a reply from a programmer, so they seem to know their stuff.

    What AFL script/code are you using in the scan (are you using their Powerscan product or Automatic analysis window)?

    With AFL you should be able to customize your alert output to display symbol and time (but not in the scan result rows) and sort the results by hours/min/secs. That would take some AFL coding, however.

    I'm in the process of setting up 100-150 symbols with Amibroker 4.70 RT version, and doing automated 1 minute or 5 minute scans on those symbols (i.e, using the Automatic Analysis window to do the scan every 1 minute). I write the output (of say, 20-30 symbol results) to a text file instead of using the alert window.
     
  3. Thanks, maxwell_e.

    I¡¯m a newbie of Amibroker, and I learn to use the program by writing and testing a very simple AFL file. I use automatic analysis window to view the scanned results. However, I notice that in the automatic analysis window, there¡¯s only the ¡°Date¡± option but no ¡°Date/time¡± option. But in Explore window, there¡¯s the ¡°date/time¡± option. I hope all symbols scanned by intraday can be sorted according to their hours/min/secs.

    For instance, when I scanned 30 stocks, on the 5-min chart, when 10- & 20-EMA crossover, an alert signal was given. Below is the program I¡¯ve written using AFL:

    Cond = Cross(EMA(Close, 10), EMA(Close, 20) );
    Cond1 = Cross(EMA(Close, 20), EMA(Close, 10) );
    Buy = Cond;
    Sell = Cond1;


    I use the Automatic Analysis window to do the scan every 1 minute, so at least 100 alert signals would appear each day. If I sort them according to hh/mm/ss, the newest signal (it could be the same symbol or different symbols) is on the top or at the very bottom, so I can easily see them. But if these signals are sorted according to ¡°Ticker,¡± ¡°Trade,¡± or ¡°Close,¡± then I need to FIND the new-coming signal through hard work.

    I want to make sure that if one can sort by hh/mm/ss in Amibroker. If this is achievable, then I must work hard to succeed, though I might need to improve my AFL coding knowledge. :(
     
  4. Doable.

    There isn't a substitute for sifting through sample AFL scripts from the online lib, and dissecting the skimpy AFL reference in the userdoc.

    Most likely you'll have to write strings to the alert output window using the AlertIf() function. No HH:MM:SS with Automatic Analysis, as you've found. For time, try the function Now(2).

    Here's some basic code I did that finds a Gap up/down (my own definition, not the Amibroker GapUP() function) and writes the amount of gap, if the gap is greater than 0.50 It writes to a text file instead of the Alert output window. You would change the
    fputs(...) to AlertIf() syntax. I prefer creating functions, so they are in tidy blocks, but it's not necessary. (When this runs, there is no output in the Automatic Analysis window, but that's just my preference).

    // writeGap.afl - measure the gap at open (today) from prev. day's close. RT data used.

    todayOpen = GetRTData("Open"); // Last = last RT trade price
    prevDayClose = GetRTData("Prev");
    Buy = 0;
    // Buy = Iif (RTLast < PrevDayclose, 1, 0);

    openGap = todayOpen - prevDayClose;

    function upGap()
    {
    if ( openGap < -0.5 )
    {
    FH = fopen( "c:\\Program Files\\Amibroker\\AFL\\Alert.txt", "a");
    if (FH)
    {
    fputs(Name() + "\t\tGap Down\t" +WriteVal(Gap), FH);
    fputs("\n", FH);
    fclose(FH);
    }
    }
    }
    function downGap()
    {
    if ( openGap > 0.5 )
    {
    FH = fopen( "c:\\Program Files\\Amibroker\\AFL\\Alert.txt", "a");
    if (FH)
    {
    fputs(Now(2), FH);
    fputs(Name() + "\t\tGap Up\t" +WriteVal(openGap), FH);
    fputs("\n", FH);
    fclose(FH);
    }
    }
    }
    downGap();
    upGap();

    Here's a sample of the output:

    9:06:02 PM MFE Gap Up 0.760
    9:06:04 PM NTES Gap Up 0.550
    9:06:06 PM OSTK Gap Up 0.740
    9:06:12 PM SNE Gap Up 0.700

    I ran this at 9:06 PM, and the timestamp is when the conditions hit (gap > 0.5). Have about 80 symbols in my list. The next run, 1 min or 5 min later, would have a later timestamp, etc. Textfile is appended to each time the code is run (I have Alert.txt open in a text editor and it automatically reloads if the file is changed.
     
  5. Short(er) reply. If you look in the 4.60 userguide for AlertIf(), there's an example of writing a simple alert to the alert output window.

    Just add Name(4) in the output string.
     
  6. It seems like that in order to realize this kind of very basic function, I must first learn AFL. :(

    In fact, I only use Amiborker as an auxiliary means. I mainly do daytrading with TopgunSoftware. This program is powerful and is also very easy to use. You don¡¯t need to know coding at all.

    Attached below is a picture so you can clearly see the page layout of Hotlist and Filter.
     
  7. Sorry, I can't attach this picture because it's larger than the maximum limit of size.:(
     
  8. Try adding one line at the end of your origional AFL code.

    WriteVal( DateTime(), formatDateTime );

    Btw, most likely you are looking at 'daily' results in your alert window. If you want intraday output, you'll need to use "GetRTData()".
     
  9. My current AFL coding knowledge can be said to be 0. Well, I added the phrase
    "WriteVal( DateTime(), formatDateTime );"
    into my original AFL code, as shown below:

    Cond = Cross(EMA(Close, 10), EMA(Close, 20) );
    Cond1 = Cross(EMA(Close, 20), EMA(Close, 10) );
    Buy = Cond;
    Sell = Cond1;
    WriteVal( DateTime(), formatDateTime );

    But, the scanned results are the same as before and there's no change. I don't know if I should include any "parameters" into the "phrase," so please help me.

    Also, I searched for the info of "GetRTData()" and found the only content that has mentioned about GetRTData is this:
    ..........
    "ChangeTime" - timenum (HHMMSS) of last data change
    "UpdateDate" - datenum (YYYMMDD) of last data update
    "UpdateTime" - timenum (HHMMSS) of last data update
    "Shares" - total number of shares

    Note 1: this function is available ONLY in PROFESSIONAL edition, calling it using Standard edition will give you NULL values for all fields
    Note 2: works only if data source uses real time data source (plugin)
    Note 3: availablity of data depends on underlying data source - check the real-time quote window to see if given field is available
    Note 4: function result represents the current value at the time of the call /formula execution/, and they will be refreshed depending on chart or commentary refresh interval /settable in preferences/. Built-in real time quote window is refreshed way more often (at least 10 times per second) ?


    However, unfortunately I don't know how to do this. Maybe I should ask specialists of Amibroker.

    :(
     
  10. Attached below are 2 pictures so you can clearly see the status of the AA window. Because the size of the pictures is too large, I put them into 2 posts.

    This scan is based on 6 stocks. If there are 30 or more stocks but the later-coming signals can¡¯t be sorted by HHMMSS, then to find the new signals would be a very hard job.
    :(
     
    #10     May 26, 2005