Is there a way to get the date of a previous bar?
In formulas using LoopSum to reference past data I can get the CTR of the bar in question but how do you get the date of the bar? The date functions like Year, Month, MonthDay all seem to reference only the current trading day. I would like to get something like a Month(CTR) but that doesn't seem possible. Is it?
Could you rephrase the question, letting us know exactly what you're looking for? Maybe give a concrete example? I'm afraid I don't quite understand it.
I can get the bars since an event such as a MA cross happening by using LoopSum to sum. But is there a way to return instead of the number of bars since, the actual date? Instead of "20" (bars ago) how do I get "20250602"?
AsOfDate - X
where X is the number of days since whatever. If you're using bars: AsOfDate - 1.4*X
where X is the number of bars.
I suspected there was a simple solution and there it is!
Thank you very much.
Maybe I thought this was solved prematurely?
As a test I used ShowVar(@DateTest, AsofDate-70 ) as a condition in a screen and it returned "20,250,560.00" or 20250560. That doesn't seem to be a legitimate date.
Yes, you're right, I was wrong. It's taking the AsOfDate, converting it into numbers, then subtracting X, which only works if X is less than the day of the month. I don't know of a good workaround at the moment, but I'll ask.
I've learned (thank you, Aaron!) we have an undocumented function for this: BarDate(#bars). BarDate(20) will give you the date 20 bars ago.
3 Likes
Thanks Yuval! Thanks Aaron!