|
Chaim6
2014-09-14 23:25:20
|
|
I tried:
DateTime ThisBar = cFunctions.Date;
result = ThisBar.ToString() ;
cFunctions.SetForwardAndBackwardBars(0, 0);
When run in the screener it says 1/3/1950. What's the right way to do this? My goal is to create a function that returns 1 if the current bar is the last bar of the month. This function would be useable across a number of my systems.
Thanks.
|
|
|
|
QuantShare
2014-09-15 03:50:11
0
|
|
cFunctions.Date returns a Vector not a single DateTime.
Please use the exising function:
a = IsLastBar();
|
|
|
|
Chaim6
2014-09-15 14:55:41
0
|
|
Maybe I wasn't so clear about this. I am writing a custom function to tell me if the current bar is the last bar of the month. This is useful for simulations that use daily bar periods to signal a trade at the end of the month. I could write the code in the simulation itself but then I would need to duplicate it for each sim. I figured that creating a custom function to be shared by many sims is a better way.
The first step is getting the date of the current bar. That's where I'm stuck. I tried using cFunctions.Date and cFunctions.Date[0]. They both returned the same date in 1950. Doesn't 0 index the *current* bar of the vector?
Thanks
|
|
|
|
Chaim6
2014-09-15 19:09:40
0
|
|
When running a simulation using a custom function, is the custom function called once for the entire vector or is it called anew for each bar? I am assuming that the answer is yes. Therefore to get the number of days in this month:
// Returns the number of days in this month
VectorDate dates = cFunctions.Date;
for (int i = 0; i < result.Length; i++)
{
result[i] = DateTime.DaysInMonth(dates[i].Year, dates[i].Month);
}
cFunctions.SetForwardAndBackwardBars(0, 0);
This seems to work!
|
|
|
|
QuantShare
2014-09-16 05:12:04
1
|
|
The custom function is called once for the entire vector.
date[0] references the first bar
date[date.Length - 1] references the last/current bar
|
|
|
|
Chaim6
2014-09-16 15:04:41
0
|
|
Thanks. Did you mean to point out a possible bug? Is date.Length different than result.Length?
|
|
|
|
QuantShare
2014-09-17 03:38:38
0
|
|
No, both are vectors and all vectors in a custom function have the same size.
I used "date" vector because you wanted to get the last date.
|
|
|
|