Storing Calendar Data
Author: gbullr
Creation Date: 8/17/2011 6:25 PM
profile picture

gbullr

#1
Suppose that I wanted to store the S&P return for the prior calendar year in a variable, how would I do this.

Lets say that I want to tell a system that if the market was up more than 50 pct the prior calendar year to not buy for a year.


Storing that under non calendar basis is easy and it would be something like ROC.Series(external.Close,252);

but how do I do it on a rolling calendar year basis.

Thanks.

profile picture

Eugene

#2
A new year starts when:
CODE:
Please log in to see this code.

At this bar, you store the current bar in an integer variable e.g. cBar. The difference between the bar and this variable at this bar is the number of the previous year's trading sessions. So, on the first day of a year this should give you the previous year's return:
CODE:
Please log in to see this code.

Or it can be estimated by replacing "bar-cBar" with "252" for simplicity. Save that value in a double variable and reuse it.
profile picture

gbullr

#3
Thanks a lot Eugene.
profile picture

Eugene

#4
Or simply pass your external.Close to this already available indicator: Year To Date Gain.
profile picture

gbullr

#5
Hi.

Can you point me to the area where I can find the attributes for Date and DateTime.

I am trying to figure out how to play around w time of day, but also month and year.

Thanks a lot.


profile picture

Eugene

#6
In MSDN, on Dotnetperls, and in thousands of other sites promoting C# found by Google.

profile picture

gbullr

#7
Thanks.

This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).