obtain the close of a specific day
Posted: Jul 03 2016
by nuno-online
Hi
is there a function to obtain the close of a specific day?
Nuno
Re: obtain the close of a specific day
Posted: Jul 06 2016
by Henry MultiŠ”harts
Hello Nuno,
For daily bars you can use this code:
Code: Select all
inputs:
DesiredDate(1160606);
vars:
DDClose(0);
if date=DesiredDate then DDClose=close;
print("Desired Date's Close is ", DDClose);
Re: obtain the close of a specific day
Posted: Jul 06 2016
by nuno-online
thanks Henry for this code
do you think it's possible to have the close of a day in 2015 for example?
and if the day is an holiday day or a week end, we look for the day before
Re: obtain the close of a specific day [SOLVED]
Posted: Jul 07 2016
by ABC
nuno-online,
that is possible, but not as simple as the one liner Henry provided. For starters you will need to have a list of holidays (and probably weekends) you want to check for.
Now you can do something along the lines of:
1. Check if the current bar is not a holiday, weekend and what ever you want to exclude, too.
2. Track the closing of each daily bar that fulfills check 1..
3. The first time the date is greater or equal to your check date you'd save the tracked close.
Of course 3. needs to be located above 2. in your code. Otherwise you wouldn't get the close you are looking for.
4. A special case could arise when condition 3. is fulfilled before your code had the chance to track the close under step 2., so you need to decide on what to do when this happens.
You could also loop back through the bars when the date >= your check date until you find a bar that matches your condition, but the above seems easier to code.
Regards,
ABC