Amibroker: AFL of "Cover when time is 3pm"

Discussion in 'Programming' started by ngterry, Nov 23, 2012.

  1. ngterry

    ngterry

    Newbie help:

    I am working on a trading system for ES. How to write AFL saying that "Buy to cover when time is 3pm"? Thanks in advance.
     
  2. Cover = TimeNum() == 150000;
     
  3. ngterry

    ngterry

    Thank you! But I have another problem on the TimeNum().

    How do I correct it? Covert TimeNum to an array?

    Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] to access array elements

    If I want to write "when Average True Range > 2 AND Time < 3pm then Buy"

    AvgTruRange = ATR(40);

    for (i = 0; i < BarCount; i++)
    {
    if (AvgTruRange >= 2)
    if (TimeNum() < 150000)
    Buy = Cover(Close, BuyStop);
    }

    How do I correct it? How to convert TimeNum() to an array?
     
  4. TimeNum() already returns an array, that is your problem. Use instead:

    if(selectedvalue(TimeNum()) < 150000)
    Buy = .....
     
  5. Buy = ATR(yourPeriod) > 2 AND TimeNum() < 150000;

    You should read the How AFL Works section in the user guide to familiarize yourself with arrays.