Scanner building

How to develop a scanner to search for situations in which the following three conditions are met:

  1. The price of the asset at 9:30 is lower than the closing price from the previous day by more than 1%
  2. The price of the asset at 10:30 is higher than the closing price from 9:30 (of the current day) by more than 1%
  3. The price of the asset at 12:30 is higher than the closing price from 9:30 (current day) by more than 1%

Of course, the indicated times and differences % are the example changes.

starttime = 093000;
pct = 1.01;

startcond = tn == starttime;

prevclose = ValueWhen(startcond, C, 2 );

condition1 = startcond AND C < prevclose / pct;

startclose = ValueWhen(condition1, C);
higher_than_start = C > startclose * pct;

condition2 = tn == 103000 AND higher_than_start;
condition3 = tn == 123000 AND higher_than_start;

Filter = condition1 and condition2 and condition3;

As for explorations see https://www.amibroker.com/guide/h_exploration.html

3 Likes

Since I wrote upper code in forum editor I did not check for missing code and logical flaws.
Now after having little bit of time I did small update because

  1. definition of "tn" variable was missing
  2. Filter will not work that way because conditions won't occur at same time unless you use ValueWhen function to preserve state till change.

Also I changed to 0.1% to at least get some output for testing on 5-min bars. So simply change yourself to some other one.

So here is update (all three conditions have to meet at 12:30 of same day).

Keep in mind that times are start times of bar (so 093000 will get Close at 9:34:59.999 on 5-min bars).

//for intra-day data!!

starttime = 093000;
pct = 1.001;

SetBarsRequired(1500);

tn = TimeNum();
dn = DateNum();

startcond = tn == starttime;

prevclose = ValueWhen(startcond, C, 2);

condition1 = startcond AND C < prevclose / pct;

startclose = ValueWhen(condition1, C);
higher_than_start = C > startclose * pct;

condition2 = tn == 103000 AND higher_than_start;
condition3 = tn == 123000 AND higher_than_start;

dn_cond3 = ValueWhen(condition3, dn);

Filter = ValueWhen( condition1, dn ) == dn_cond3 AND
         ValueWhen( condition2, dn ) == dn_cond3 AND
         condition3;

AddTextColumn( Interval(2), "Interval", 1 );

Plot( C, "Price", colorDefault, styleCandle );
Plot( prevclose, "prevclose", colorDefault, styleStaircase );
Plot( startclose, "startclose", colorRed, styleStaircase );

003

8 Likes

I'm impressed. Thank you very much. You helped me a lot.:+1:

If you're impressed, you should "like" the post by clicking on the Heart icon and/or marking it as the solution to your question.

2 Likes

Thanks for the information. I am new and unknowing

1 Like