Exploration results differs during live trading and End of Day when using higher time frame criteria


I have an afl to generate signals when the close price crosses prev_day_high/prev_day_low and if ROC_Daily is > 0 (for Buy) and ROC_Daily < 0 (For sell). ROC daily is calculated for period of 5. Since i run the exploration at fixed interval of 15 mins on last 2 bars, to get the ROC_Daily I am using timeframeset and restore functions. Now the challenge is, during live market exploration, the daily close is equal to interval close (obviously) at the time of exploration and the timeframeset/restore/expand functions calculates the ROC as per the last close value. But, when I run the exploration at the end of the day, ROC is changed because Timeframeset/restore/expand calculates ROC based of Close of the Day so the ROC_daily value is same for all 15 min bars of the day.. Because of this, the live exploration result counts and end of day result counts differs. For example, yesterday, during live exploration at 15 mins interval, the number of trades were 30 for a day, but when I ran the exploration at the end of the day(recent days =1), the results were 54. I know the difference is due to change in ROC condition because of timerameset/restore/expand. My question is how do I make sure that the end of the day exploration results are also same. I need to work on this because I want to optimize ROC days parameter and I know historical exploration data may have additional extra results which did not occur during the live 15 min exploration so, if I optimize it based on historical data, I will not get the correct optimized setting.

In short, the condition should be buy when Cross(C, prev_day_high) and when this condition is true , the corresponding ROC value which is coming from ROC function used with Timeframeset/restore/expand should be > 0 (for Buy) and <0 (for sell). I do not know how to get the ROC value at the time of signal generation especially when it coming from higher timeframe using timeframeset/restore/expand.

Plz note, that I am using free trial version 6 and not a paid customer of Amibroker as of now. I tried searching for topics on the same but could not find it.

XDA_Setting=Per =9;




EurekaBuy=  Cross(C, prev_day_high) AND ROC_Daily > 1 ;
EurekaSell= Cross(prev_day_low,C)  AND ROC_Daily < -1 ;


BSG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault)); 
BSFG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault)); 

PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low);
PlotShapes(Sell*shapeDownArrow, colorRed, 0, Low);

if((Status("action") == actionExplore) OR (Status("action") == actionScan)) 
	Filter = Buy or Filter = Sell;

			SetOption("NoDefaultColumns", True); 
			AddTextColumn(Name(), "Symbol", 77, BSFG, BSG, 120);
			AddColumn(DateTime(), "Date", formatDateTime, BSFG, BSG, 100);
			AddColumn(TimeNum()/100 ,"Time",1,BSFG, BSG, 100);
			AddColumn(IIf( Buy, 'B', 'S'), "Trade",formatChar);
			AddColumn( C, "Trade_Price", 1.2,BSFG, BSG, 100 );
			AddColumn( round(IIf(Buy,C*0.9875,1.0125*C)/tick_size)*tick_size, "Stop_Price", 1.2,BSFG, BSG, 100 );
			AddColumn( round(IIf(Buy,C*1.03,0.97*C)/tick_size)*tick_size, "Target_Price", 1.2,BSFG, BSG, 100 );
			AddColumn( Buy, "Buy", 1,BSFG, BSG, 50);
			AddColumn( Sell, "Sell", 1,BSFG, BSG, 50 );
			AddColumn( ADX_, "ADX", 1.2,BSFG, BSG, 50 );
			//AddColumn( ADX_15min, "ADX_15min", 1,BSFG, BSG, 50 );
			AddColumn( prev_day_high, "prev_day_high", 1.2,BSFG, BSG, 100 );
			AddColumn( prev_day_low, "prev_day_low", 1.2,BSFG, BSG, 100 );
			AddTextColumn(Now() ,"Current_Time",formatDateTime,BSFG, BSG, 100);

Let me get the first part right, you want the RoC period for last 5 Days, "Daily Bars".

In that case if you replaced



with this

close_5day = TimeFrameGetPrice ( "C", inDaily, -5); // Close 5 days ago
ROC_Daily  = ( C / close_5day - 1) * 100;           // 5 day RoC 

You will have the same RoC value throughout the day until a new day was added irrespective of which interval or Periodicity the AFL is run in.

Hey Thanks Travick !!!

I have got the solution... Calculating ROC at the time of exploration interval as
(C - prev_per_close)*100/prev_per_close

This prev_per_close is coming from Timeframeset/restore/expand as

prev_per_close=TimeFrameExpand(prev_per_close_,inDaily, expandFirst);
ROC_Daily=(C - prev_per_close)*100/prev_per_close

Here per is optimized value for period...

But your suggestion is far better than my solution...... I will implement it .. this will definitely help me in other AFLs as well...Thanks for your time and efforts !

You can mark that post as solution so that it may help future posters.