Syntax for getting HIGH/LOW within a specific timeslot of yesterday

Please provide SYNTAX for getting HIGHEST or LOWEST for time slot of 1:00 pm to 3:30 pm of yesterday.
There are HHV & HHV function which find HIGHEST & LOWEST in respect to current bar.

Here I will be running the program during anytime of today, it should give me same result as the yesterdays timeslot is fixed.

If not direct.. any workaround suggestion can be explored.

@snbarma, try the search tool. Lots of different results for "specific time" that may be helpful to you.

@snbarma To get you started read this knowledge base article
http://www.amibroker.com/kb/2015/02/02/high-low-of-certain-hours-of-the-day

And a similar question previously on this forum

2 Likes

Thanks a lot for your reply. I will try to modify this code as per the requirement.
Could you tell me how this is arrived at:
EndTime = 101500;

My guess is
10 =hour
15=min
00=seconds
If this is true, I would like not to HARDCODE start date and end date. In this case, end date is today and start date is yesterday.

Please suggest how to achieve this.

@snbarma from the TimeNum() documentation:

Returns the array with numbers that represent quotation time coded as follows:
10000 * hour + 100 * minute + second, so 12:37:15 becomes 123715

Take a look also at ParamTime() to use the parameter dialog to change start/end time as needed.

Additionally, you can also use ParamDate() but probably it is better for you to figure out via code the "yesterday" date (more probably corresponding to the last trading date with at least one/x bars in your selected timeslot).

1 Like

Ok.. Thanks.
Can you suggest how to ask for yesterdays data in the code..

Something like this

Date()=Today()-1; //pseudo code

Is there equivalent syntax in AFL to achieve the same, please let me know.

@snbarma Depending upon how you code this, you just need to understand how to use ValueWhen
https://www.amibroker.com/guide/afl/valuewhen.html

I don't trade intraday so here is my attempt but it could probably be written better.

StartTime  = ParamTime( "Start Time", "13:00:00" );
EndTime   = ParamTime( "END Time", "15:30:00" );

tn = TimeNum();

// these conditions are true when TimeNum of the bar equals startime/endtime 
StartBar = tn == StartTime; 
EndBar = tn == Endtime; 

// on the end bar we read the value of highest high since the start bar 
TodayHHinRange = ValueWhen( EndBar, HighestSince( StartBar, High ),1 ); 
// the value of TodayHHinRange is Yesterday's until today at "EndTime" when the latest
// calculation is done and then listed

YesterdayHHinRange = ValueWhen( EndBar, HighestSince( StartBar, High ), 2); 
// the value of YesterdayHHinRange is two day's ago's until today at "EndTime" when the latest
// calculation is done and then listed, then becomes Yesterday's

// just for my Exploration I wanted some Null's so a little re-naming here
TodayResult = IIf(tn==EndTime, TodayHHinRange, Null);
YesterdayResult = IIf(tn==EndTime, YesterdayHHinRange, Null);

/////////////////////////////////
// Explore the attempted solution
/////////////////////////////////
Filter=1;
time_color = IIf(tn>=StartTime AND tn<=EndTime, colorLightYellow, colorDefault);
AddColumn(High, "High", 1.2, colorDefault, time_color);
AddColumn(TodayResult, "TodayResult", 1.2, colorDefault, colorYellow);
AddColumn(YesterdayResult, "YesterdayResult", 1.2, colorDefault, colorLime);
/*
AddColumn(TodayHHinRange, "TodayHHinRange", 1.2, colorDefault, time_color);
AddColumn(YesterdayHHinRange, "YesterdayHHinRange", 1.2, colorDefault, time_color);
*/

Producing an Explore like this,

image

3 Likes

I appreciate your input with lots of thanks.
I will explore this today.

Hello,

I did try with this piece of code @ 2:10 pm.
For me the script is not generating any result for TodayResult and YesrdayResult columns.
Please see the screenshot.
Strategy2

Another small observation- in the exploration output provided by you, I see data for 2 different dates are populated. In my case data for only today is listed.

Please disregard my earlier comment and screenshot.
Now I can see data for two dates has been populated by the explorer.

I see the data in the specific time range has been highlighted in yellow. The columns "TodayResult" and "YesterdayResult" supposed to show HIGHEST value in the specific time frame at the end of the time slot.
In my case these columns are not getting populated.
I changed the time slot as below, still no result in those columns. Anything I am missing?

StartTime  = ParamTime( "Start Time", "13:00:00" );
EndTime   = ParamTime( "END Time", "14:30:00" );

The screenshot is here:
image

@portfoliobuilder- please respond

@snbarma, I am sure you are aware that all the helpful people on the site (other than Tomasz) are just other users who are volunteering their time to help other users.

Your request could be interpreted as demanding.

If you look at the code that was provided, my question is .... Do you understand it?

If you do understand it, you can probably spot the reason that (I think) causes you to not get the Today Result, or Yesterday Result. I don't have intraday data so have not run the code.

If you don't understand it, your hint from me is to look at the code lines that make the values for TodayResult and YesterdayResult, and see if you can figure out why...

Then, try running your exploration again later in the day.

2 Likes

@snbarma, it is not enough if you just change to a different time in the code. Those are just default values.

You actually have to set the time in the analysis parameter window (see picture below). And I am pretty sure that your end time there is not 14:30 but still 15:30 of previous run. Since as per your screen shot your last time of session is 15:00 it is quite logical consequence that the last two columns will show empty cells in all rows considering the fact that the conditions within TodayResult and YesterdayResult variables are equality checks (see tn==EndTime) so they expect matching exact times.

So again go to analysis window and set your time there.

212117

3 Likes

@snbarma

Judging from your posts you are not the sharpest tool in the shed. You should realize that members of this forum come from all over the world. So while you were posting I was asleep. From my bed I arose and went to work. After my day at work I checked in on the forum. Amazing to you perhaps that I do not spend 24/7 on this forum.

Thankfully @snoopy.pa30 and @fxshrat were able to provide you with some help. Credit to @fxshrat also for introducing me to ParamTime in the thread I provided earlier in this discussion as I am not a day trader so have never needed to use that before.

One further point, in the code I provided there are two lines commented out in the Exploration that were there to help you debug in case of problems. Of course you didn't try that did you? It may have helped you figure out YOUR mistakes.

AddColumn(TodayHHinRange, "TodayHHinRange", 1.2, colorDefault, time_color);
AddColumn(YesterdayHHinRange, "YesterdayHHinRange", 1.2, colorDefault, time_color);

image

3 Likes

Thank you very much.
I am amazed by the depth of your knowledge in AFL.

Special thanks to portfoliobuilder,beppe, snoopy.pa30 and fxshrat.

I have a small query. In the code you have used a fixed time (user specified) for the endtime/end bar. This is perfectly fine for yesterdays data.
For today, the endtime/end bar is the current time.
Can you please how to get current time stored in Timenum() format.

EndTime   = ParamTime( "END Time", "14:30:00" );
tn = TimeNum();  //Array of time template
EndBar = tn == Endtime; 

//additional lines for today till current time - Need your advice. 
Endtime1=Current time();  //not sure
Endbar1=tn==Endtime1;

You can't ask other users about every single detail. If you need date/time functions you should start from searching for such functions in the documentation:

AFL Function Reference - Categorized list of functions:
https://www.amibroker.com/guide/a_catfunref.html

DT

I haven't analysed your code, but If you need current System's time in TIMENUM format:

TN

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

2 Likes

Thank you so much for your prompt help.