How to get more previous daily candle

Dear all,
Please help me,
I tried to write simple afl for explore / stock screening like below: (Use multi time frame)

_SECTION_BEGIN("Pullback of Momentum Daily candle");

TimeFrameSet( inDaily ); // switch now to Daily

dt = DateTime();
WhiteBody_Up = ((Close - Open)/Open) * 100 >= 5;

Bull = TimeFrameExpand(WhiteBody_Up,inDaily);

Mom_P = ((Close - Open)/Open) * 100;

TimeFrameRestore(); // restore time frame to original

ma5= LastValue(MA(C,5));

C_MA5H1Dev = ((LastValue(C) - ma5) / LastValue(C)) * 100;

Filter = WhiteBody_Up AND C_MA5H1Dev < 5;

AddColumn(C,"Close");
AddColumn(Mom_P,"White Body(%)");
AddColumn((dt), "White Body Date",formatDateTime);
AddColumn(C_MA5H1Dev,"Deviasi Close to MA5");

_SECTION_END();

But the problem are:

  1. The explore limited to White Body date 2020-08-27 when i run explore range 1 recent day(s) or from- to date 2020-09-04 and 2020-09-04.
    How to make this afl explore more previous daily candle (ie previous 20 candle daily) when i run in range 1 recent day(s).
  2. Because i run exlpore this afl in intraday time frame, its show more than 1 signal in a day. How to make only show latest signal when i use range 1 recent day(s).

Thanks alot in advance

Regards
Nyoman

First of all your code is not proper multi time frame code.
You did not expand and you did not expand properly (expansion follows after restoration).

Please read documentation properly.
Please read entire page before (Please read the orange boxes in addition).
http://www.amibroker.com/guide/h_timeframe.html


First set "1 recent day(s)". Then you have to insert 20 and then hit Enter key. Then explore.


/// @link https://forum.amibroker.com/t/how-to-get-more-previous-daily-candle/21227/2
TimeFrameSet( inDaily ); // switch now to Daily
	dt = DateTime();	
	WhiteBody_Up = ((Close - Open)/Open * 100) >= 5;
	Mom_P = (Close - Open)/Open * 100;
TimeFrameRestore(); // restore time frame to original

/// Expansion AFTER TimeFrameRestore
WhiteBody_Up = TimeFrameExpand(WhiteBody_Up,inDaily);
Mom_P = TimeFrameExpand(Mom_P,inDaily);

ma5= MA(C,5);
C_MA5H1Dev = (C - ma5) / C * 100;

dn = DateNum();
newday = dn != Ref( dn, -1);

Filter = WhiteBody_Up AND C_MA5H1Dev <= 5;

// get most recent true Filter within a day
cs = SumSince(newday, Filter);
comp = TimeFrameCompress(cs, inDaily, compressHigh);
expand = TimeFrameExpand(comp, inDaily, expandFirst);
Filter = Filter AND cs == expand;

AddColumn(C,"Close");
AddColumn(Mom_P,"White Body(%)");
AddColumn(TimeFrameExpand(dt,inDaily), "White Body Date",formatDateTime);
AddColumn(C_MA5H1Dev,"Deviasi Close to MA5");

Then another general advice in regards to creating post.
It is mandatory rule to insert code via code tags.
Please read carefully and watch GIF animation there

2 Likes

Thank alot Mr. fxshrat for your reply.
Problem no 2. i already test and work properly to prevent multi signal in one daily candle.
But problem no 1, could you please tell me another way to achieve it than just change 1 recent(days) to 20 recent(days) because i prefer use default range 1 recent(days) for all my afl, sir.

Thanks in advance
Nyoman

  1. Make sure that only single (!) analysis window is opened (Because the last closed analysis tab saves new state for all others re-opened afterwards).
  2. Set Range to "1 recent day(s)".
  3. Then close Analysis window.
  4. Re-open analysis window from "File - New - Analysis" or from + button right of last chart tab. Set Range still should be "1 recent day(s)" being new default setting.
  5. (You may save to APX file in addition, File - Save or Save as.)

I did it sir but there is no solved my problem about limited previous (White_Body) candle sir.
The problem is AFL's output only 2020-08-27 when i screening today with last candle (2020-09-04). I want to screening about 20 candle daily even i use my default range 1 recent(days).

Thank you sir

If you set range 1 recent day(s) then only 1 recent day is considered but not 20, 30, ..., 100 days!

If you want to scan recent 20 days then you have to set 20 recent days but not 1 day. :roll_eyes:
17

Also Note: recent days setting is setting calendar days but not business days.

And FYI only results returning TRUE are part of result list. That's what Filter is all about... returning TRUE results.

I am outta here. No intention wasting time on totally imprecise posts.

Thanks you Mr. Fxshrat for your time.

Kind Regards
Nyoman

Good Evening Mr. fxshrat and Mr. Tomasz,
I am so sorry for miss explain about the problem in my last post.

The problem actually is i want to search stock that price near ma5 in its last candle in 60minute timeframe but with White Body in its previous daily candle, let say between yesterday until 20 daily candle previous.

Because if i use range 20 recent(days) or from- to dates in window explore, these output are not signal in last candle 60m tf but its signal in previous candle.

I write/edit the afl like below :

_SECTION_BEGIN("Pullback of Momentum Daily candle");

TimeFrameSet( inDaily ); // switch now to Daily
dt = DateTime();
WhiteBody_Up = ((Close - Open)/Open) * 100 >= 5;
Mom_P = ((Close - Open)/Open) * 100;

TimeFrameRestore(); // restore time frame to original

WhiteBody_Up = TimeFrameExpand(WhiteBody_Up,inDaily);
Mom_P = TimeFrameExpand(Mom_P,inDaily); ;

ma5= LastValue(MA(C,5));
C_MA5H1Dev = ((LastValue(C) - ma5) / LastValue(C)) * 100;

Filter = WhiteBody_Up AND C_MA5H1Dev < 5; // its mean deviation price to ma5 below 5%

AddColumn(C,"Close");
AddColumn(Mom_P,"White Body(%)");
AddColumn(TimeFrameExpand(dt,inDaily), "White Body Date",formatDateTime); // i want to 1-20 daily candle previous 
AddColumn(C_MA5H1Dev,"Deviasi Close to MA5");

_SECTION_END();

I use ma5= LastValue(MA(C,5)); to get ma5 value in last candle.
I very curious is this possible or not, sir.

i am so sorry sir, wasting your time.

Many thanks in advance

Regards

Nyoman

My last attempt... otherwise you would need to get someone who explains in better English (if it is still not what you look for).

_SECTION_BEGIN("Pullback of Momentum Daily candle");

TimeFrameSet( inDaily ); // switch now to Daily
dt = DateTime();
WhiteBody_Up = ((Close - Open)/Open) * 100 >= 5;
Mom_P = ((Close - Open)/Open) * 100;

is_sum_white = Sum(WhiteBody_Up, 20) >= 1;

TimeFrameRestore(); // restore time frame to original

WhiteBody_Up = TimeFrameExpand(WhiteBody_Up,inDaily);

is_sum_white = TimeFrameExpand(is_sum_white ,inDaily);
Mom_P = TimeFrameExpand(Mom_P,inDaily);

ma5=MA(C,5);
C_MA5H1Dev = ((C- ma5) / C) * 100;

Filter = is_sum_white AND C_MA5H1Dev < 5 AND Status("lastbarinrange"); // its mean deviation price to ma5 below 5%

AddColumn(C,"Close");
AddColumn(Mom_P,"White Body(%)");
AddColumn(TimeFrameExpand(dt,inDaily), "White Body Date",formatDateTime); // i want to 1-20 daily candle previous 
AddColumn(C_MA5H1Dev,"Deviasi Close to MA5");

_SECTION_END();

Thank you sir for your kind attention. I am sorry my english so bad.

Btw with this filter:

Filter = is_sum_white AND C_MA5H1Dev < 5 AND Status("lastbarinrange"); // its mean deviation price to ma5 below 5%

Criteria WhiteBody_Up doesn't work so that it will show red candle too.

To more clear about my explain before, here i attach picture to describe what i mean.

Daily candle
image

Hourly Candle
image

When i run this AFL in window explore, suppose to be this stock appear but it doesn't.

Many thank to your help and kind attention, sir

Regards

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.