How to make AFL to consider only today's candle sticks for generating signals

Hi All,

Can anyone let me know how to make AFL to consider only today's data(candle sticks) for Intraday. For this i am thinking of to delete the backfilled data before market starts.Is there any better approach is there? For my AFL i am considering previous candle to generate signals.So at the start of the market AFL is considering the yesterday's last candle(which is the previous candle at the time) and AFL generates the falls signals.Please suggest me how to make AFL to consider only today's candle sticks for generating signals.

Thanks .

You could just use your signals with current day condition in intraday time frame.

cur_day  = Day() == LastValue( Day() );
MySignal = cur_day AND <your_signal_logic>;
3 Likes

Thanks @travick. In my logic, suppose i am adding volume of present candle and previous candle and store in to "VOL" array and market hours are 9 AM to 5 PM. So at 9:00 AM "VOL" array should not add the previous candle's volume (because previous candle is yesterday's last candle).
from 9:05 onwards "VOL" array can consider the previous candle.(Considering i am using the 5 minute intraday chart). Can you guide me how to achieve this?

Thanks in advance.

Do not create duplicate threads. You have already answered your question here

Bar_today = BarsSince( Day() != Ref( Day(), -1 ) ) + 1;
TodayVolume = Sum( V, Bar_today );

Or use SumSince instead of Sum+BarSince.

This all has been covered multiple times in forum already.

4 Likes

Hi.. @fxshrat. Thank you so much for your valuable support .

Bar_today = BarsSince( Day() != Ref( Day(), -1 ) ) + 1;
redBar = ROC(C,1) < 0;
CountOfconsecutiveGreenBar = Sum(redbar,BarsSince(redBar==0));
Filter= 1;
AddColumn(redBar ,"redBar",1.2);
AddColumn(CountOfconsecutiveGreenBar ,"CountOfconsecutiveGreenBar ",1.2);

Can you guide me.In the above code where i can add the "Bar_today" logic to avoid considering the yesterday's green candles in 5 minute intraday chart.

Thanks,

AFAIU, you want to avoid overlapping count from one day to another day. In short do you want to reset counter each day?

If so, then add this

/// @link https://forum.amibroker.com/t/how-to-make-afl-to-consider-only-todays-candle-sticks-for-generating-signals/12386/6
dn = DateNum();
new_day = dn != Ref(dn,-1);

function Counter_DailyReset(cond) {
	/// @link http://tinyurl.com/y437hnrw
	/// by fxshrat@gmail.com
	/// commercial use prohibited!
	local conseq1, conseq2, conseq;
	conseq1 = BarsSince(!(cond AND ! new_day));
	conseq2 = conseq1 + ValueWhen(new_day, cond);
	conseq = IIf(BarsSince(new_day)+1 == conseq2, conseq2, conseq1);
	return conseq;
}

red_bar = C < O;// or ROC(C,1) < 0;
green_bar = ! red_bar;

conseq_red = Counter_DailyReset(red_bar);
conseq_green = Counter_DailyReset(green_bar);

Filter = 1;
AddColumn(IIf(red_bar, 1, Null),"red_bar",1);
AddColumn(IIf(red_bar,BarsSince(!red_bar), Null),"conseq_red (unfiltered)",1);
AddColumn(IIf(red_bar,conseq_red, Null),"conseq_red ",1);
AddColumn(IIf(!red_bar,!red_bar, Null),"greenBar",1);
AddColumn(IIf(!red_bar,BarsSince(red_bar), Null),"conseq_green (unfiltered)",1);
AddColumn(IIf(!red_bar,conseq_green, Null),"conseq_green ",1);

55

And another for green bar
39


BTW, this one

CountOfconsecutiveGreenBar = Sum(redbar,BarsSince(redBar==0));

does not make sense to me.

  1. It does not count consecutive green bars but rather red bars
  2. and if you want to count consecutive red bars then you may just use BarsSince alone.
conseq_red = BarsSince(! redBar); 

or

conseq_red = SumSince(! redBar, 1); // change "1" to something else you want to count instead.

BTW2, your line

CountOfconsecutiveGreenBar = Sum(redbar,BarsSince(redBar==0));

is zero-based. To make it one-based

CountOfconsecutiveGreenBar = Sum(redbar,BarsSince(redBar==0)+1);

then it will be equal to BarsSince(! redBar). So again use latter one (just BarsSince).

5 Likes