How to get current time frame off the chart

Hi all, It take a long time for me to search the way to get the current time frame of the chart (is 100T or 15 minute or Hourly, Daily ...)

For example, Name() will give us current Symbol. How to get current timeframe?

Looking for your help.

@nguyenbao are you looking for a place on your chart that displays the timeframe or are you looking for a method in code to find the timeframe?

For code learn the Interval() function,
https://www.amibroker.com/guide/afl/interval.html

TimeFrame = Interval( 2 );

//////////////////////
// Chart it
//////////////////////
Title = "\n" +
        "Current Time: " + Now( 2 ) + "\n" +
        "Chart Interval: " + TimeFrame;

Plot( C, "", 1, 128 );

///////////////
// Explore it
///////////////
Filter = Status( "LastBarInRange" ) AND Status( "stocknum" ) == 0;
SetOption( "NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddtextColumn( TimeFrame, "TimeFrame" );

image
image

Or on your chart it appears in a couple of places, here for example on a 15 minute chart,
image

3 Likes

@portfoliobuilder Thank you very much, Interval( 2 ) is what I looking for. (I searched key word time frame, period... so I didn't find the answer).

I intented to Open 1 Amibroker windows and 3 or more Chart with different Timeframe or Symbol. => I need detail information to input in Alert function to know which Timeframe to entry a position.

However, I find another issue here when manage multiple alert

You can try this method and set the 2nd onlyvisible to False

Use it, don't abuse it !!!

https://www.amibroker.com/guide/afl/requesttimedrefresh.html

@travick

Thanks for your reply. Please give me some suggestion:

  1. Guide

It does not apply to chart windows that are on placed on inactive sheets, as they do not really exist until they are shown (this way AmiBroker conserves memory and CPU) and as non-existing, can not be refreshed.

It mean that even if put onlyvisible to False in my AFL. If have 3 charts only 1 Active Chart will automatically refresh?

So if I have 3 strategy using same data, what should I do? Open 3 Instances of Amibroker?

  1. What is the defaut value of Interval RequestTimedRefresh( interval, onlyvisible = True )

  2. Can suggest me any Tutorial series of Setting Live Trading system using Amibroker?
    Do we have a different mode for Live Trading Or we just Open Amibroker as normal and let it do the job?

When you have the guide and the resources, these aren't questions you should ask.

Simply "test" it in your AB, you will learn far more than what I can teach you.

Put your code in various test scenarios and see if it works. Infact you can come back and document it so the next leaner can be benefitted.

AB Chart windows are MDI tabs (as are AA among others), and therefore each MDI Tab reserves its own resources the moment its created.
Hence it is not wise to open hundreds of them and leave them idle.

Chart Sheets on the other hand are just tabs that are created when activated and destroyed when closed, and therefore, you need to distinctly understand both.

By this logic, every Chart will have its own Active Sheet, whether its visible to you or MS windows is secondary.
You cant have a chart without atleast one active sheet.

See here, both charts aren't visible but they are still executing AFL code on the active sheet.
The moment the sheet isn't active, output stops.

image

RequestTimedRefresh( 2, False);
_TRACEF( "%g= hidden", 2);    // Unique number for each AFL code. 1, 2 and so on

Read more here:
https://www.amibroker.com/guide/h_customizeui.html

You'll figure out all your answers from this post.

4 Likes

Rephrasing this line because it can be interpreted differently, but in other words it means
Every Chart will always have one and only one active sheet.
Whether its visible, or active as in active window or minimised itself or AB entirely is minimized are different contexts and nothing to do with the "Active Sheet" itself related to the Chart.

  1. Thank you very much @travick, I understand clearly Windows Chart and Chart Sheet now. I also tested, the Active sheet of a Window Chart (MDI tabs) which has onlyvisible = False will automatically refresh, no matter the Chart is active or not.

Sorry for trouble you, please give me some suggestion for 2& 3 questions:

Hint: to detect whenever given refresh comes from timer or user action you can use Status("redrawaction") function. It returns 0 for regular refresh (user action) and 1 for timer-refresh

It means that if I dont set RequestTimedRefresh, AB will refresh "real time" when it is active (not minimised)?

I think that it depen on the Data, how many Windows Chart, Computer hardware. But, based on your experience, 2 to 5 seconds refresh Interval will not a matter, won't it?
RequestTimedRefresh( 5, False);

  1. Asking for Tutorial or Attention points for Amibroker Live Trade system.

You can read this
It is very clear
http://www.amibroker.com/kb/2015/02/03/when-and-how-often-afl-code-is-executed/

AB will save resources as much as possible.

Additionally – by default charts in minimized chart windows or when multiple MDI windows are open and one is maximized, the windows in background that are completely obscured by others and/or minimized windows are not redrawn/refreshed during normal RT refresh.

2 to 5 seconds refresh Interval is speculative.
Instead you should test your specific AFL performance.

AB is always live and alive. Tell it what to do and it will do it.
If you have interfaced your code with a trading platform, it becomes live trading.
Checkout all the articles with IB controller.
Eg. http://www.amibroker.com/at/

3 Likes