# Need help to count quotes per 15 minutes

Hi, i'm new to amicoding. I don't know how to count quotes on a time frame like quotes per hour, quotes per minute. Please help me.

You should get a signal at the end of a period for which you want to count the number of its quotes

then You can use barssince function

if you want to get number of quotes every 15m , you can use a code like this one

``````MT     = Minute();
TB15M   = Ref(int(MT/15),0)  != Ref(int(MT/15),-1);
``````

Note .. Barcount tell you the total number of quotes on your chart

4 Likes

Thank Sebastian.
I use Analysis explore, but the number of quotes is 1. May be something wrong with my code.

``````TimeFrameSet(in15minute);

MT     = Minute();
TB15M   = Ref(int(MT/15),0)  != Ref(int(MT/15),-1);

Filter = 1;
``````

If you want to count the number of shorter interval's bars within longer Interval via time frame functions then you may do like so, for example.

``````TimeFrameSet(in15minute);
bi = BarIndex();
htfstr = Interval(2);
TimeFrameRestore();
bi = TimeFrameExpand(bi, in15Minute, expandFirst );

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

AddTextColumn( Interval(2), "Shorter Interval", 1 );
AddTextColumn( htfstr, "Longer Interval", 1 );

Filter = 1;
`````` In order to properly align the longer interval's data to shorter interval's date/time elements you need to expand after restoring.

3 Likes

It is probably better to refer to the most recent version of the Multiple Time Frame support in AFL user guide.

@Tomasz added some yellow/orange boxes surrounding some paragraphs that are crucial to understanding the correct use of the TimeFrame functions.

2 Likes

Thank fxshrat.
I just want to count the number of quotes in quations table The first line in your code mean you are working within a time interval equal to 15m
So a true signal will be generated for all consecutive bars in your chart because there's no space between them
and that will not allow you to know how many quotes each 15 minutes

Instead of this you need to amend the the first line of your code to be

``````TimeFrameSet(in1minute);
``````
1 Like

I am not sure what that got to do with your code snippet trying to get shorter interval count within 15 minute bars.

Now all of the sudden you seem to be looking for getting the barcount of the base time interval of data base (which in your case looks like tick).

So in order to output the barcount of your base time interval (which would be equal to the number of rows in "Quote editor" - see your picture -) simply set Periodicity to "Tick" in Analysis settings.

Then run exploration

``````if( Interval(2) != "1-tick" )
Error( "Set Periodicity to 1-tick" );
else {
Filter = Status( "lastbarinrange" );
AddColumn( BarCount, "Number of ticks", 1 );
}
``````

No, TimeFrameSet(1minute) will not access 1-minute bars within 15minute bar interval!

If he wants to count number of 1-minute bars within 15-minute bars via time frame functions then timeframe function(s) interval setting has to be 15-minute and selected interval (in chart or analysis) has to be 1-minute. Please re-read upper post how to use timeframe functions. It works from shorter interval to longer interval but not vice versa.

``````// code applied e.g. on 1-tick, 1-second, 1-minute, 5-minute (selected chart & analysis intervals!)
TimeFrameSet(in15minute);

//do something
x = ....;

TimeFrameRestore();

x = TimeFrameExpand(x, in15Minute); //Expand to SELECTED INTERVAL (being SHORTER interval than 15-minute!)

``````

If he wants to get number of ticks (instead of 1-minute bars within 15-minute bars then again selected interval (in chart or analysis) has to be 1-tick but timeframeset (and timeframeexpand) interval still being 15-minute but not 1-tick!

3 Likes

When i tested the code the time interval on my chart was already 1m , so i did not need to use timeframeset() , and yea its true that timeframeset() work properly only from shorter interval to longer one as you mentioned above , i acknowledged this part missed me ...

Thanks fxshrat for correction 3 Likes

Thank fxshart.
I just want to find 10 stock have highest maching speed in last 15 minutes.
After change periodicity to 1 tick, I run the code for 1 recent bar but maybe the result is not right.

``````TimeFrameSet(in15minute);
bi = BarIndex();
htfstr = Interval(2);
TimeFrameRestore();
bi = TimeFrameExpand(bi, in15Minute, expandFirst );

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

AddTextColumn( Interval(2), "Shorter Interval", 1 );
AddTextColumn( htfstr, "Longer Interval", 1 );
AddColumn( BarCount, "Number of ticks", 1 );

Filter = 1;
`````` You need to better explain what you actually want. What is meant by "highest maching speed"?

You wrote

together with uploaded picture of "Quote editor" (which I guess is what you meant by "quations table").

So that's what

``````AddColumn( BarCount, "Number of ticks", 1 );
``````

is doing if periodicity of analysis settings is set to same interval as base time interval setting of File-Database settings-Basetime interval. Output number will be equal to number of rows of "Quote editor".

1 Like

Sory fxshrat if my idea not clear.
At first, i want to find stock have most number of trade in last 15minute. After that I find that in "Quote editor" have the information of a trade match with price, vol. So I think that count the tick will solve. But I don't know how to count tick in last 15 minutes for all symbol.

Add sorting (first sort by Date/time then sort by "NQ" column) and add rank column (see below).

``````TimeFrameSet(in15minute);
bi = BarIndex();
htfstr = Interval(2);
TimeFrameRestore();
bi = TimeFrameExpand(bi, in15Minute, expandFirst );

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

Filter = Status( "lastbarinrange" );

AddTextColumn( Interval(2), "Shorter Interval", 1 );
AddTextColumn( htfstr, "Longer Interval", 1 );
Thank for your help. 