Question on multiple timeframe exploration

Hi Amibroker experts,
I am trying to use different timeframe variable .by exploration at daily TF
I have a question about variable( C5 and C60) that why it have same value? and how to fix this.
thank very much:kissing_heart:

My AFL script is as following:

TimeFrameSet( in5Minute );
C5=ROC(C,5)*100;
TimeFrameRestore(); 

TimeFrameSet( inHourly ); 
C60=ROC(C,5)*100;
TimeFrameRestore(); 

Filter = 1;
AddColumn( Close, "Close",1.5 ); 
AddColumn(C5, "Roc5min",1.2 ); 
AddColumn(C60, "Roc60min",1.2 ); 

You can not use Daily data to calculate something in a shorter interval (like 5m, 1h). It’s impossible. Use 5 minute interval (5 minute data), then you will be able to calculate hourly and daily values.

A quote from: 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.


Let me give you an example. If I told you that my birthday is in July and asked you - which day exactly, you would say - you don’t know. In the same way, you can’t tell what was the stock’s price at 12:05 if you have only daily data available :wink:

1 Like

Thanks a lot Milosz:heart_eyes:

HI Milosz

Sorry to bring up old thread alive again but I just would like to confirm. if i have the following

  1. 1 minute resolution OHLCV database (fig 1)
  2. show chart/run afl code , with baseInterval Daily

then I will NOT be able to access the 1 minute resolution Data
for operations?

thank you

Fig 1
TramMinuteData

I apologize if i bump up a 1 year old thread, i hope its the preferred approach than creating a new one ? sorry if i am wrong.

from the above link, is it true that , the TimeFrame* functions can only operate on O, H, L, C, V, OI, Avg arrays ?

on my database , the transaction value , 1 - minute resolution is , stored in the AUX2 array, not sure if the TimeFrame* can operate on the array.

my code below , is run in 1-minute periodicity setting exploration
where I want to compare the cumulative intraday transaction value
with the EMA(Aux2,10); but i think i am not using the time functions properly;

wondering if anyone willing to guide me in pointing out my mistake

thanks in advance.

#include_once <..\Custom\CustomInclude\BuySellVolumeValue.afl>
//minute scan

/*
1. run in explorer mode
2. periodicity setting is at 1-minute
*/
 
//bars on a new day.
newDay = Day() != Ref(Day(),-1);
cBar = LastValue(BarsSince(newDay));

//Running total of today intraday transaction value;
bValSum = Sum(BuyVal,cBar+1)/billion;
sValSum = Sum(SellVal,cBar+1)/billion;
tvalSum = bValSum + sValSum;

//WANT:
//daily transaction value in a 10 *daily* window session
tvalDaily = TimeFrameCompress(Aux2,inDaily); //transaction values are stored in aux2 array
emaD_10 = EMA(tvalDaily,10)/billion;


Filter = tvalSum > 5; // cumulative transaction value for today 5 bilion
AddColumn(tvalSum,"tvalBn",1.2);
AddColumn(emaD_10,"emaD_10",1.2);

`

You can use Aux1 and Aux2 also.

You have forgotten to expand compressed array to selected interval.

//... code of before

//daily transaction value in a 10 *daily* window session
tvalDaily = TimeFrameCompress(Aux2,inDaily); //transaction values are stored in aux2 array
emaD_10 = EMA(tvalDaily,10)/billion;
// expand to original interval
emaD_10_exp = TimeFrameExpand(emaD_10, inDaily, expandLast);


Filter = tvalSum > 5; // cumulative transaction value for today 5 bilion
AddColumn(tvalSum,"tvalBn",1.2);
AddColumn(emaD_10_exp,"emaD_10",1.2);
1 Like

much appreciated as alway @fxshrat, I tried the modification,
it does gave same result but not what i had in mind, below are two result , showing, what the ema-10 value indaily exploration
vs 1-minute.

both result after modification.

image
using Daily periodicity Setting , the correct ema10 (daily) result

image
using 1-minute periodcity Setting, incorrect ema10 (daily) result

//... code of before

//daily transaction value in a 10 *daily* window session
tvalDaily = TimeFrameCompress(EMA(Aux2,10)/billion,inDaily); //transaction values are stored in aux2 array
// expand to original interval
emaD_10_exp = TimeFrameExpand(tvalDaily, inDaily, expandLast);


Filter = tvalSum > 5; // cumulative transaction value for today 5 bilion
AddColumn(tvalSum,"tvalBn",1.2);
AddColumn(emaD_10_exp,"emaD_10",1.2);

BTW, I suggest to better use TimeFrameSet, TimeframeRestore as it is better readable and you don't need multiple TimeFrameCompress calls if wanting to compress more than one variable.

//... code of before

//daily transaction value in a 10 *daily* window session

TimeFrameSet(InDaily);
tvalDaily = Aux2;
emaD_10 = EMA(tvalDaily,10)/billion; //transaction values are stored in aux2 array
TimeFrameRestore();

// expand to original interval
emaD_10_exp = TimeFrameExpand(emaD_10, inDaily, expandLast);


Filter = tvalSum > 5; // cumulative transaction value for today 5 bilion
AddColumn(tvalSum,"tvalBn",1.2);
AddColumn(emaD_10_exp,"emaD_10",1.2);
1 Like

@fxshrat , thank you , but the change in code did not produce different result. stil incorrect. when run in 1-minute time frame
just a note my datebase resolution is 1-minute.
image
just thought i should point that out.

It does work that way as it is proper way of using TimeFrame functions!

You don't tell what your "billion" variable is about! It is unknown to reader (as are other variables in your code)! If it is array then you have to create it within TimeFrameSet also (since you want same result as in daily interval)!

I told you already to better use TimeFrameSet.

BTW your tvalSum variable will be different in Daily interval compared to 1-minute also.
Have you checked that? It is part of your Filter.

I have given you many hints. I do not know your other variables. It is your responsibilty to debug further.

1 Like

This code gives same results in daily and 1-minute
It is the first one I posted where you said it does not do that.
I only changed Aux with C.

tvalDaily = TimeFrameCompress(C,inDaily);
emaD_10 = EMA(tvalDaily,10);
emaD_10_exp = TimeFrameExpand(emaD_10, inDaily, expandLast);

Filter = 1;

AddTextColumn( Interval(2), "Interval", 1 );
AddColumn(emaD_10_exp,"emaD_10",1.4);

54

508

You need to check your other variables (such as unknown "billion" etc)!

But again better use TimeFrameSet.

1 Like

sorry for getting back late, I tried by copying your exact code on your last reply, for my Aux2 component still does not give me the same result. I also tried using , TimeFrameSet approach still it does not work. I think it could be my database format , my thanks to you
@fxshrat for your help, since the code works on your end , but not on mine , it has to be my database format. thanks again as always. I will keep trying.

@fourier,

In my previous example I was using price data (of Close field). But since you seem to use volume data (cumulative data) in such case for your Aux field you would have to add compressVolume to 3rd argument of TimeFrameCompress.

tmfrm = inDaily;
tvalDaily = TimeFrameCompress(Aux2, tmfrm, compressVolume);// cumulative data
emaD_10 = EMA(tvalDaily, 10);
emaD_10_exp = TimeFrameExpand(emaD_10, tmfrm, expandLast);

Filter = 1;

AddTextColumn( Interval(2), "Interval", 1 );
AddColumn(emaD_10_exp,"emaD_10",1.2);

As you can see it works on such data too (below result is output of Aux2 data!)

439

505


TimeFrameSet...TimeFrameRestore if applied on Aux fields seem to work on non-cumulative data (price data) only. Even if aggregation mode in Database Settings - Intraday settings is set to Sum.

57

5 Likes

thank you very much, i feel dumb after missing the small bit of information on the function reference/help page. it was right there. apologies for wasting your time. #solvedby @fxshrat

Well just a rub through, I am working on a 15 minute exploration, but trying to get the daily values for the exploration.

The code


dn = DateNum();
dt = DateTime();
newday = dn != Ref(dn, -1);
todays_bars = BarsSince( newday )+1;
todaybarsnum = LastValue(todays_bars);


tmfrm = inDaily;
shift = 0;
TimeFrameSet( tmfrm );
   HH10DV = HHV(V,10);
   Vol10cond = (V== HH10DV);
   
   H10HV = ValueWhen(Vol10cond,H,1);
   L10HV = ValueWhen(Vol10cond,L,1);
   D10HV = ValueWhen(Vol10cond,dt,1);
   
   HH15DV = HHV(V,15);
    Vol15cond = (V== HH15DV);
   
   
   H15HV = ValueWhen(Vol15cond,H,1);
   L15HV = ValueWhen(Vol15cond,L,1);
   D15HV = ValueWhen(Vol15cond,dt,1);
   
TimeFrameRestore();

   
HH10DVOut = TimeFrameExpand(HH10DV, tmfrm, expandLast );
H10VOut = TimeFrameExpand(H10HV, tmfrm, expandLast);
L10VOut = TimeFrameExpand(L10HV, tmfrm, expandLast);
D10VOut = TimeFrameExpand(D10HV, tmfrm, expandLast);

HH15DVOut = TimeFrameExpand(HH15DV, tmfrm, expandLast );
H15VOut = TimeFrameExpand(H15HV, tmfrm, expandLast);
L15VOut = TimeFrameExpand(L15HV, tmfrm, expandLast);
D15VOut = TimeFrameExpand(D15HV, tmfrm, expandLast);


HH15Min5DV = HHV(V,135+todaybarsnum);

Filter = 1;

AddColumn(C,"C",1.2);


AddColumn(HH10DVOut,"10VFD",1.0);
AddColumn(D10VOut,"D10V",formatDateTime);
AddColumn(H10VOut,"H10VFD",1.2);
AddColumn(L10VOut,"L10VFD",1.2);

AddColumn(HH15DVOut,"15VFD",1.0);
AddColumn(D15VOut,"D15V",formatDateTime);
AddColumn(H15VOut,"H15VFD",1.2);
AddColumn(L15VOut,"L15VFD",1.2);



_SECTION_END();


Now to what I wish to do:

  1. While working on the 15 minute chart - I am finding out the highest volume of past 10 days (inDaily). Working fine till here.
  2. Corresponding to this high volume daily bar, I wish to find the High & Low.
  3. Repeat step 1 & 2 above for 15 days instead of 10.
  4. Now I move down to current TimeFrame i.e. In15Minute. Here I will check for the high volume bar for past 5 days (5*27 15 minute bars = 135) & mark it's HIGH-LOW
  5. For step 4 exclude today's bars

Well my apologies for posting it without proper SEARCH

https://forum.amibroker.com/t/find-high-and-low-of-highest-volume-bar-in-a-range/2096/5

The code should have been as follows:

/// For last ("current") day set Range to "1 recent bar" (or keep "All quotes") 
/// For past selectable dates use Range "From-To" settings and set "To" date.
/// @link https://forum.amibroker.com/t/incremental-loop-to-add-columns/10703/2

dn = DateNum();
dt = DateTime();
newday = dn != Ref(dn, -1);
todays_bars = BarsSince( newday )+1;
todaybarsnum = LastValue(todays_bars);


tmfrm = inDaily;
shift = 0;
TimeFrameSet( tmfrm );

Bars10SinceHighestVolume = HHVBars( V, 10 );
HV10 = Ref( V, -Bars10SinceHighestVolume );
DV10 = Ref( dn, -Bars10SinceHighestVolume );
H10HV = Ref( High, -Bars10SinceHighestVolume );
L10HV= Ref( Low, -Bars10SinceHighestVolume );

Bars15SinceHighestVolume = HHVBars( V, 15 );
HV15 = Ref( V, -Bars15SinceHighestVolume );
H15HV = Ref( High, -Bars15SinceHighestVolume );
L15HV= Ref( Low, -Bars15SinceHighestVolume );
   
TimeFrameRestore();

   
HH10DVOut = TimeFrameExpand(HV10, tmfrm, expandFirst );
D10DVOut = TimeFrameExpand(DV10, tmfrm, expandFirst );
H10VOut = TimeFrameExpand(H10HV, tmfrm, expandFirst);
L10VOut = TimeFrameExpand(L10HV, tmfrm, expandFirst);

HH15DVOut = TimeFrameExpand(HV15, tmfrm, expandFirst );
H15VOut = TimeFrameExpand(H15HV, tmfrm, expandFirst);
L15VOut = TimeFrameExpand(L15HV, tmfrm, expandFirst);



HH5D15MinV = HHVBars(V,135);
HV5D15Min = Ref(V,-HH5D15MinV);
High5D15Min = Ref(H,-HH5D15MinV);
Low5D15Min = Ref(L,-HH5D15MinV);

Filter = 1;

AddColumn(C,"C",1.2);


AddColumn(HH10DVOut,"10VFD",1.0);
AddColumn(D10DVOut,"D10V",formatDateTime);
AddColumn(H10VOut,"H10VFD",1.2);
AddColumn(L10VOut,"L10VFD",1.2);
AddTextColumn("$","S");
AddColumn(HH15DVOut,"15VFD",1.0);
//AddColumn(D10VOut,"D10V",formatDateTime);
AddColumn(H15VOut,"H15VFD",1.2);
AddColumn(L15VOut,"L15VFD",1.2);
AddTextColumn("$","S");
AddColumn(HV5D15Min,"5x15V",1.0);
//AddColumn(D10VOut,"D10V",formatDateTime);
AddColumn(High5D15Min,"5x15H",1.2);
AddColumn(Low5D15Min,"5x15L",1.2);
AddTextColumn("$","S");



_SECTION_END();


Now what remains,

  1. Getting the date of high volume bar on daily scale & datetime of high volume bar on 15Min scale
  2. Excluding today's data if it runs on real time scale. For dayily it would mean getting the Volume for Ref(-1) bars.