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

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.
 
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?
 
Quote from ngterry:

if (TimeNum() < 150000)
Buy = Cover(Close, BuyStop);
How do I correct it? How to convert TimeNum() to an array?
TimeNum() already returns an array, that is your problem. Use instead:

if(selectedvalue(TimeNum()) < 150000)
Buy = .....
 
Quote from ngterry:

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

Buy = ATR(yourPeriod) > 2 AND TimeNum() < 150000;

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