High-Low of certain hours of the day from different time frame

My first post so lets see how it goes…

The link below refers.

http://www.amibroker.com/kb/2015/02/02/high-low-of-certain-hours-of-the-day/

This works fine provided the start time co-insides with selected timeframe, else I get null values. for instance, below code on a 5min chart gives null values (note StartTime = 90100;)

tn = TimeNum();
StartTime = 90100;
Endtime = 91500;
StartBar = tn == StartTime;
EndBar = tn == Endtime;
FirstBarsH = ValueWhen( EndBar, HighestSince( StartBar, High ) );
FirstBarsL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );

What I have done instead is to code the below function and it works fine. I am just wondering if my solution is optimal. What I am really after is ignoring the very messy first minute on open in my ORB systems (which run in longer than one minute timeframe).

function marketOpenTimeFrame( shiftFrom, shiftTo, field )
{
	result = ValueWhen(NewDay,TimeFrameGetPrice("O", in1Minute, shiftFrom),1);
	for( i = shiftFrom; i <= shiftTo; i++ )
	{
		switch( field )
		{
		  case "H":
				result = Max(result,ValueWhen(NewDay,TimeFrameGetPrice(field, in1Minute, i),1)); 
				break;

		  case "L":
				result = Min(result,ValueWhen(NewDay,TimeFrameGetPrice(field, in1Minute, i),1));
				break;
		}  
	}
	return result;
}

My Function above does not achieve its objective. In fact it is looking into the future.

Am I correct in saying multiple time frame support allows calculations on “higher” time frames only? For example, 5 minute bars could access arrays from 1h bars, but would not make available the arrays from 1 minute bars?

http://www.amibroker.com/guide/h_timeframe.html

“Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, …N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.”

@Zargo so the conclusion is you need to be in shorter interval else your code wil not work ?

I am trying to do something along this line , but on the volume metrics, the setup is the following.

1 chart is in daily time fame
2. there ia a marker on Ref(V,-1), indicating yesterday volume , at current time (fig.1)

now i am not sure if that is possibe, given the workings of amibroker. ?

image

@fourier Best to ignore my code above. You can call dataframes (arrays, indicators) from higher (longer) TF, but not shorter. You can set the chart interval as you prefer.

eg in a 1minute bar chart, I can call yesterday’s Daily H like this DayH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high. But I cannot in hourly chart call the H for some 5 minute period.

For completeness, I can achieve my initial objective by setting my backtester periodicity to 1 minute and then call the H for a specified time period (StartTime to EndTime) like this:

NewDay = Day()!= Ref(Day(), -1);
marketOpenTime =ValueWhen(NewDay,TimeNum(),1);
StartTime = marketOpenTime + 100;              //ignore 1st 1 minute
Endtime = StartTime + 500;                          //consider 5 minutes
StartBar = TimeNum() == StartTime;
HighValue=HighestSince(StartBar,H);
RangeHigh = ValueWhen(Cross(TimeNum() , Endtime ), HighValue);

Above code returns today’s Highest H for 5 minutes, ignoring the messy open bar.

The thread that discusses this already exists: Displaying Lower TF EMA on Higher TF Chart

1 Like