TimeFrameSet(-1) is not switching tick interval

I am trying to calculate Bid and Ask Volume on Tick interval. When I set Back tester periodicity settings to tick, I am getting tick volume for every tick, from which I can get Ask and Bid volume for every tick.

But when I set the periodicity settings to 5 minutes and explore my below code. The base arrays O,H,L,C are not switching to tick interval instead it is showing the arrays calculated in 5 minutes itself.

TimeFrameSet(-1);
AskV = IIf(C>Ref(C,-1),V,0);
BidV = IIf(C <= Ref(C,-1),V,0);
CAskV = Cum(AskV);
CBidV = Cum(BidV);
TimeFrameRestore();

EBidV = TimeFrameExpand(CBidV,in5Minute,expandLast);
EAskV = TimeFrameExpand(CAskV,in5Minute,expandLast);
Filter = 1;
Ask = EAskV - Ref(EAskV, -1);
Bid = EBidV - Ref(EBidV, -1);
AddColumn(Ask, "Ask Volume");
AddColumn(Bid, "Bid Volume");

It is considering the entire 5 minutes close instead of calculating internal ticks. If any one can help in this it would be helpful. Thanks in advance.

1 Like

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

TimeFrameExpand( array, interval, mode = expandLast ) - expands time-compressed array from 'interval' time frame to base time frame
(interval' must match the value used in TimeFrameCompress or TimeFrameSet)

I have tried to expand. You can see the lines I used for expansion in the code. But still I get the wrong answer.

what ever lines which is inside TimeFrameSet() and TimeFrameRestore. still on 5minutes rather than ticks.

Please read again , your interval (2nd arguement) in TimeFrameExpand does not match what is set in TimeFrameSet.

1 Like

In addition please carefully read the docs.

It clearly says

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.

1 Like

Ok, I get that. But still

TimeFrameSet(-1);
AskV = IIf(C>Ref(C,-1),V,0);
BidV = IIf(C <= Ref(C,-1),V,0);
CAskV = Cum(AskV);
CBidV = Cum(BidV);
TimeFrameRestore();


EBidV = TimeFrameCompress(CBidV,in5Minute,compressLast);
EAskV = TimeFrameCompress(CAskV,in5Minute,compressLast);
Filter = 1;
Ask = EAskV - Ref(EAskV, -1);
Bid = EBidV - Ref(EBidV, -1);
AddColumn(Ask, "Ask Volume");
AddColumn(Bid, "Bid Volume");```

It takes the entire volume of the 5 minutes candle as Ask or bid volume. 
Attaching an image showing that as the first candle C < O it took it as bid and showing it. 
But actually there are ask volume ticks and bid volume ticks in that single candle. It has been combined into either ask or bid based on bigger time frame.

https://imgur.com/nzN3ULK

No, you do not get that (as your code & picture still show). You can not access 1-tick on SELECTED 5-minute interval (of chart or analysis). Try to understand that.

If you are after accessing intrabar data of 5-minute interval then (in AmiBroker) SELECTED interval has to be shorter interval (than 5-minute), for example 1-tick.

Also interval argument of TimeFrameSet and TimeFrameExpand have to match exactly.

For example:

/// related to issue discussed here 
/// @link https://forum.amibroker.com/t/timeframeset-1-is-not-switching-tick-interval/7915/7
/// code applied on 1-tick (SELECTED INTERVAL)

intervale = in5Minute;

TimeFrameSet(intervale);
bi = BarIndex();
TimeFrameRestore();

bi = TimeFrameExpand(bi, intervale, expandFirst);

newbar = bi != Ref(bi,-1);

AskV = IIf(C>Ref(C,-1), V, 0);
BidV = IIf(C<=Ref(C,-1), V, 0);

EAskV = SumSince(newbar,AskV);
EBidV = SumSince(newbar,BidV);

// etc....

Again read here (again).
As well as for TimeFrameSet read here (again).

6 Likes

Thank you for explanation, now I Understand clearly.

As it has solved your issue now ,mark @fxshrat 's post above as the solution ,will be helpful for others to quick jump to solution.
And, while you are at it, why not show some appreciation, click the heart below his post/s.

2 Likes

@fxshrat Thank you for your help! My Intraday Database about 6-month. Now if SELECTED INTERVAL 1-tick then Calculate too slow. I only want to calculate Ask Bid of one day (last day/curent day). How to ignore all day no need cal?