Retrieve Close Values on Specific time duration in the past

I need to retrieve close values related to the specific time duration in the past. I have already used Status( "firstbarinrange" ); and Status( "lastbarinrange" ); as part of my exploration code used From-To field in Analysis section. Is there any other way to refer to a specific period of time? I need to work on/ refer to close values related to 2 separate time durations in my exploration idea.
I appreciate it if you could give me a hint as I couldn't find any suitable functions. It seems most of the functions can give the close value for a specific date/time, not the duration.
Basically, I need to access a subset of the Close array, which is different from what I've already specified by the From-To field and firstbarinrange and lastbarinrange parameters.

Ultimately, I want to calculate the EMA of close values of a security, let's say from 01/02/2019 to 01/02/2020.

Thanks

For specific period in time you can use Lookup()
AFL Function Reference - LOOKUP (amibroker.com)

Lookup( array, datetime, mode = 0 )

Thanks for your reply. I've checked this function already; If I could replace the datetime argument with a time interval or somehow identify, for example, 250 daily bars before or after a specific time identified by the datetime argument, that works for me. However, I couldn't find any example or figure out how to do it yet.

It can be done, im sure. You need to explain it more clearly.

Even the DT array can be compressed, then refer value from it and use it.
or build a date string and then convert it to DT and use in Lookup.

So far your posts are not crystal clear for me atleast.

@Sepideh, as @nsm51 states, you need to define what you want more clearly.

With AB using Arrays, you can easily define an EMA for every day in the period. What you do with that is then up to you.

When starting out with AB/AFL it is often difficult in wrapping your coding mind around the use of arrays. I suggest to people to think of it like a Row in Excel. You have a row for Close, that uses the Column for the days. If you want the MA, then you define a new Row for it, and Calculate it by defining the formula.

The KEY to the formula is that it can only reference Columns to the left (history) and Rows above (already defined).

AB/AFL does this automatically for you, so a MA (or EMA) is a simple call. AB then gives you access to all the values

So, here in your case, an EMA over a period does not really make sense, as if you define an EMA, it will be for ALL periods (excluding initialization).

If you reference your last topic, and use the Exploration, you will see EMA values over the entire history (if you change the Filter value to 1).

It takes a bit of effort to wrap your head around the array programming that AFL uses, but the results when you get it are simpler coding, rarely the need for a loop, and blazingly fast processing.

So, work on defining your coding requirements a bit more, and post any code you have (using code blocks), and we can see better how we can help you out.

4 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.