Hi,
I have been searching on your forum and webpage but couldn't get to the bottom of what I was looking for.
Is there a Wealthscript function to retrieve the start and end dates of your backtesting settings in the C# code, (the <i>Data Range</i> being set set in the top left corner of your WealthLab window)?
The reason for the above is that I am running a strategy on a futures strip (with futures reaching back to, say, Jan 2000) and it turns out that the various futures only have data for 2.5-year windows. I then would like to identify which one is the first futures to consider, given the backtesting start date (which I set to say 2002 and I would like to ignore all futures which are pre-2002).
Thanks,
Seb
Size:
Color:
Hi,
QUOTE:
Is there a Wealthscript function to retrieve the start and end dates of your backtesting settings in the C# code, (the <i>Data Range</i> being set set in the top left corner of your WealthLab window)?
There are many ways:
1. Simple: Bars.Date[0] and Bars.Date[ Bars.Count-1 ]. What can be simpler?
2. Exotic: parse the strategy's XML file (User Guide > Data >
Where data are stored?). Here I mean the DataRange xml tag with StartDate and EndDate.
3. Advanced: use
System.Reflection to obtain the current strategy window's WealthScript property. 95% of the code required by this task already lives inside Community.Components. Open up the solution, find the StrategyChartForm class, and add this method somewhere next to GetPositionSize(), IsRawProfitMode() etc:
CODE:
Please log in to see this code.
QUOTE:
and I would like to ignore all futures which are pre-2002).
You might want to look up Bars.FirstActualBar in the QuickRef.
Size:
Color:
Thanks for the detailed answer Eugene!
As expected, the first method doesn't return what I was looking for in cases where the DataSeries starts after the Start Date as defined in Data Range in the top left corner of WealthLab. Indeed, the value I get is the start of the DataSeries which is currently being processed instead of the start of the backtesting window.
Same comment for Bars.FirstActualBar which I had also tried before asking you.
The third method however is quite straightforward and returns exactly what I was looking for! Thanks!
Size:
Color:
Good to know it helps. You're welcome.
Size:
Color: